diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..43204b8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +charset=utf-8 +indent_style = tab +indent_size = 4 +insert_final_newline = true \ No newline at end of file diff --git a/.github/.templateMarker b/.github/.templateMarker new file mode 100644 index 0000000..5e3a3e0 --- /dev/null +++ b/.github/.templateMarker @@ -0,0 +1 @@ +KOLANICH/python_project_boilerplate.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..89ff339 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + allow: + - dependency-type: "all" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..7fe33b3 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,15 @@ +name: CI +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: typical python workflow + uses: KOLANICH-GHActions/typical-python-workflow@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6700c03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__ +*.pyc +*.pyo +./*.egg-info +./build +./dist +./.eggs \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..384fe7b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,63 @@ +#image: pypy:latest +image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest +stages: + - dependencies + - build + - test + - trigger + +variables: + DOCKER_DRIVER: overlay2 + SAST_ANALYZER_IMAGE_TAG: latest + SAST_DISABLE_DIND: "true" + SAST_CONFIDENCE_LEVEL: 5 + CODECLIMATE_VERSION: latest + +include: + - template: SAST.gitlab-ci.yml + - template: Code-Quality.gitlab-ci.yml + +build: + tags: + - shared + stage: build + variables: + GIT_DEPTH: "1" + PYTHONUSERBASE: ${CI_PROJECT_DIR}/python_user_packages + + before_script: + - export PYTHON_MODULES_DIR=${PYTHONUSERBASE}/lib/python3.8 + - export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin + - export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered + + script: + - mkdir ./wheels + - python3 ./setup.py bdist_wheel + - mv ./dist/*.whl ./wheels/CMake-0.CI_python-py3-none-any.whl + - pip3 install --upgrade --pre --user ./wheels/CMake-0.CI_python-py3-none-any.whl + - coverage run --source=CMake --branch -m pytest --junitxml=./rspec.xml ./tests/tests.py + - coverage report -m + - coverage xml + + coverage: /^TOTAL\\s+.+?(\\d{1,3}%)$/ + + cache: + paths: + - $PYTHONUSERBASE + + artifacts: + paths: + - wheels + reports: + junit: ./rspec.xml + cobertura: ./coverage.xml + + +update_prebuilder_dependencies_image: + only: + - master + stage: trigger + allow_failure: true + trigger: + project: KOLANICH-subgroups/docker-images/prebuilder_dependencies + strategy: depend diff --git a/CMake.py b/CMake.py new file mode 100644 index 0000000..cce6156 --- /dev/null +++ b/CMake.py @@ -0,0 +1,351 @@ +import typing +from pathlib import Path +import json +import re +from collections import OrderedDict + +import cmakeast +import os + + +cmakeConstants = { + "ON": True, + "YES": True, + "TRUE": True, + "Y": True, + + "OFF": False, + "NO": False, + "FALSE": False, + "N": False, +} + +class Arg: + __slots__ = ("type", "optional", "nameMandatory") + def __init__(self, typ:type, optional:bool=False, nameMandatory:bool=False): + self.type = typ + self.optional = optional + self.nameMandatory = nameMandatory + +def parseFuncArgs(interp, spec: typing.Mapping[str, Arg], args:typing.Iterable): + #print("parseFuncArgs", args) + res = OrderedDict() + specIter = iter(spec) + + j = 0 + for argName, argCand in specIter: + arg = args[j] + #print(argName, j, arg) + wasSet = False + if not argCand.optional: + if argCand.nameMandatory: + assert isinstance(arg, cmakeast.ast.Word) and arg.type == cmakeast.ast.WordType.Variable and arg.contents == argName + j += 1 + res[argName] = interp.evaluateExpression(arg) + else: + if argCand.nameMandatory: + if isinstance(arg, cmakeast.ast.Word) and arg.type == cmakeast.ast.WordType.Variable: + if arg.contents == argName: + if argCand.type is bool: + res[argName] = True + wasSet = True + else: + j += 1 + arg = args[j] + res[argName] = interp.evaluateExpression(arg) + wasSet = True + + if not wasSet: + if argCand.type is bool: + res[argName] = False + else: + res[argName] = None + j += 1 + if j >= len(args): + break + + for argName, argCand in specIter: + res[argName] = False if argCand.type is bool else None + + return res + +includeSpec = [ + ("path", Arg(str, False, False)), + ("OPTIONAL", Arg(bool, True, True)), + ("RESULT_VARIABLE", Arg(str, True, True)), + ("NO_POLICY_SCOPE", Arg(bool, True, True)), +] + +messageSpec = [ + ("mode", Arg(str, False, False)), + ("text", Arg(str, False, False)), +] + +setSpec = [ + ("variable", Arg(str, False, False)), + ("value", Arg(str, False, False)), + + #following vars are for CACHE + #("CACHE", Arg(bool, False, False)), + # {"BOOL", "FILEPATH", "PATH", "STRING", "INTERNAL"} + #("docstring", Arg(str, False, False)), + #("FORCE", Arg(bool, True, False)), + + #("PARENT_SCOPE", Arg(bool, False, False)), +] + +class cmakeBuiltins(): + @classmethod + def set(cls, interp, args): + argsRes = [] + for a in args[1:]: + argsRes.append(interp.evaluateExpression(a)) + + name=interp.evaluateExpression(args[0]) + namespace = interp.ns + if name.startswith("ENV{") and name[-1] == "}": + name = name[4:-1] + namespace = interp.envVars + + if len(argsRes) >= 2: + namespace[name] = argsRes + else: + namespace[name] = argsRes[0] + + @classmethod + def message(cls, interp, args): + argz = parseFuncArgs(interp, messageSpec, args) + #print(argz) + if argz["mode"] in {"FATAL_ERROR", }: + raise Exception("Fatal error in message: " + argz["text"]) + elif argz["mode"] in {"WARNING", "AUTHOR_WARNING", "DEPRECATION", "SEND_ERROR"}: + import warnings + warnings.warn(argz["mode"]+": "+ argz["text"]) + else: + print(argz["text"]) + + @classmethod + def include(cls, interp, args): + argz = parseFuncArgs(interp, includeSpec, args) + modulePath = Path(argz["path"]) + if not modulePath.is_file(): + if "CMAKE_MODULE_PATH" in interp.ns: + modulePath= Path(interp.ns["CMAKE_MODULE_PATH"]) / (argz["path"]+".cmake") + + try: + interp.interpret(modulePath.read_text()) + if argz["RESULT_VARIABLE"]: + interp.ns[argz["RESULT_VARIABLE"]] = str(modulePath) + except: + if argz["RESULT_VARIABLE"]: + interp.ns[argz["RESULT_VARIABLE"]] = argz["RESULT_VARIABLE"]+"-NOTFOUND" + + if not argz["OPTIONAL"]: + raise + + +stringEmbeddedExprRx = re.compile("\\$\\{[^\\}\\{\\$\\n]+\\}") + +class CMakeInterpreter(): + __slots__ = ("ns", "cache", "builtins", "envVars") + def __init__(self, ns=None, cache=None, builtins=None, envVars=None): + if ns is None: + ns = {} + if cache is None: + cache = {} + if envVars is None: + envVars = OrderedDict(os.environ) + + if builtins is None: + builtins = cmakeBuiltins + + self.ns = ns + self.cache = cache + self.builtins = builtins + self.envVars = envVars + + def evaluateConditions(self, conditions): + conditionsInitial = conditions + if isinstance(conditions, cmakeast.ast.Word): + return [self.evaluateCondition(conditions)] + + if isinstance(conditions, (list, tuple)): + if not conditions: + return [] + if(len(conditions) == 1): + res = self.evaluateConditions(conditions[0]) + #print("result conditions", res) + return res + + #print("conditions non unary", conditions) + if conditions[0].type == cmakeast.ast.TokenType.Word: + invertCondition = False + if(conditions[0].contents == "NOT"): + #print("invertCondition = True") + invertCondition = True + conditions = conditions[1:] + else: + #print("invertCondition = False") + pass + + if(conditions[0].contents == "EXISTS"): + res = Path(self.evaluateExpression(conditions[1])).exists() + conditions = [(not res if invertCondition else res), *self.evaluateConditions(conditions[2:])] + #print(conditionsInitial, "->", conditions) + return conditions + elif(conditions[0].contents == "IS_DIRECTORY"): + res = Path(self.evaluateExpression(conditions[1])).is_dir() + conditions = [(not res if invertCondition else res), *self.evaluateConditions(conditions[2:])] + #print(conditionsInitial, "->", conditions) + return conditions + + elif invertCondition: + exprToInverseResult = self.evaluateCondition(conditions[0]) + #print(conditions[0], "->", exprToInverseResult) + conditions = [not exprToInverseResult, *self.evaluateConditions(conditions[1:])] + #print(conditionsInitial, "->", conditions) + return conditions + + if conditions[1].type == cmakeast.ast.TokenType.Word: + if(conditions[1].contents == "AND"): + conditions = [self.evaluateCondition(conditions[0]) and self.evaluateConditions(conditions[2]), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "OR"): + conditions = [self.evaluateCondition(conditions[0]) or self.evaluateConditions(conditions[2:])] + elif(conditions[1].contents == "LESS" or conditions[1].contents == "STRLESS"): + conditions = [self.evaluateExpression(conditions[0]) < self.evaluateExpression(conditions[2]), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "GREATER" or conditions[1].contents == "STRGREATER"): + conditions = [self.evaluateExpression(conditions[0]) > self.evaluateExpression(conditions[2]), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "LESS_EQUAL" or conditions[1].contents == "STRLESS_EQUAL"): + conditions = [self.evaluateExpression(conditions[0]) <= self.evaluateExpression(conditions[2]), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "GREATER_EQUAL" or conditions[1].contents == "STRGREATER_EQUAL"): + conditions = [self.evaluateExpression(conditions[0]) >= self.evaluateExpression(conditions[2]), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "EQUAL" or conditions[1].contents == "STREQUAL"): + conditions = [self.evaluateExpression(conditions[0]) == self.evaluateExpression(conditions[2]), *self.evaluateConditions(conditions[3:])] + + elif(conditions[1].contents == "VERSION_LESS"): + conditions = [self.evaluateExpression(conditions[0]).split(".") < self.evaluateExpression(conditions[2]).split("."), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "VERSION_GREATER"): + conditions = [self.evaluateExpression(conditions[0]).split(".") > self.evaluateExpression(conditions[2]).split("."), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "VERSION_LESS_EQUAL" or conditions[1].contents == "STRLESS_EQUAL"): + conditions = [self.evaluateExpression(conditions[0]).split(".") <= self.evaluateExpression(conditions[2]).split("."), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "VERSION_EQUAL" or conditions[1].contents == "STRLESS_EQUAL"): + conditions = [self.evaluateExpression(conditions[0]).split(".") == self.evaluateExpression(conditions[2]).split("."), *self.evaluateConditions(conditions[3:])] + elif(conditions[1].contents == "MATCHES"): + rx = self.evaluateExpression(conditions[2:]) + rx = re.compile(re) + conditions = [bool(rx.match(self.evaluateExpression(conditions[0]))), *self.evaluateConditions(conditions[3:])] + else: + pass + #print("result conditions", conditions) + return conditions + + def evaluateCondition(self, condition): + #print("condition", condition) + if condition.type == cmakeast.ast.TokenType.Word or condition.type == cmakeast.ast.WordType.Variable: + try: + exprRes = self.evaluateExpression(condition) + #print("exprRes", exprRes) + except Exception as ex: + print(ex) + return None + + if isinstance(exprRes, str): + if exprRes in self.ns: + return self.ns[exprRes] + else: + return False + else: + return exprRes + + raise NotImplementedError() + + def derefVariable(self, expr:str): + assert expr[0:2] == "${" + assert expr[-1] == "}" + exprName = expr[2:-1] + #print("exprName", exprName, exprName in self.ns) + if exprName in self.ns: + return self.ns[exprName] + else: + return "" + + def evalStringEmbeddedExpr(self, m): + #print(evalEmbExpr, m.group(0)) + res = self.derefVariable(m.group(0)) + #print("res", res) + return res + + + def evaluateExpression(self, expr): + #print("unary expression", expr) + #assert conditions.type == cmakeast.ast.TokenType.Word or conditions.type == cmakeast.ast.TokenType.Variable + if expr.type == cmakeast.ast.TokenType.Word or expr.type == cmakeast.ast.WordType.CompoundLiteral: + if expr.contents in cmakeConstants: + #print("result expr", cmakeConstants[expr.contents]) + return cmakeConstants[expr.contents] + try: + num = int(expr.contents) + #print("number", num) + return num + except: + pass + return expr.contents + elif expr.type == cmakeast.ast.WordType.String: + res = json.loads(expr.contents) + count = 1 + while count: + res, count = stringEmbeddedExprRx.subn(self.evalStringEmbeddedExpr, res) + return res + elif expr.type == cmakeast.ast.WordType.VariableDereference: + return self.derefVariable(expr.contents) + + #print("result expr", False) + raise ValueError("Neither a Word nor a deref: "+repr(expr)) + + def _interpret(self, statements): + for s in statements: + if isinstance(s, cmakeast.ast.FunctionCall): + fName = s.name.lower() + #print("hasattr(self.builtins ("+repr(self.builtins)+"), "+repr(s.name)+")", hasattr(self.builtins, fName)) + if hasattr(self.builtins, fName): + func = getattr(self.builtins, fName) + func(self, s.arguments) + else: + raise ValueError("Function "+repr(s.name)+" not found") + continue + elif isinstance(s, cmakeast.ast.IfBlock): + cond = s.if_statement.header.arguments + trueBranch=s.if_statement.body if s.if_statement else None + elseif_statements=s.elseif_statements + falseBranch=s.else_statement.body if s.else_statement else None + + evaluatedCond = self.evaluateConditions(cond) + #print("evaluatedCond", evaluatedCond) + assert len(evaluatedCond) == 1 + evaluatedCond = evaluatedCond[0] + if evaluatedCond and trueBranch: + self._interpret(trueBranch) + #TODO: elseif_statements + elif falseBranch: + self._interpret(falseBranch) + continue + #print("s", s) + + def interpret(self, source:typing.Union[str, Path]): + if isinstance(source, Path): + return self.interpret(source.read_text()) + + a = cmakeast.ast.parse(source) + self._interpret(a.statements) + + return self.ns + +def __main__(): + import sys + cm = CMakeInterpreter() + cm.interpret(Path(sys.argv[1])) + from pprint import pprint + pprint(cm.ns) + +if __name__ == "__main__": + __main__() diff --git a/Code_Of_Conduct.md b/Code_Of_Conduct.md new file mode 100644 index 0000000..2b781c7 --- /dev/null +++ b/Code_Of_Conduct.md @@ -0,0 +1 @@ +No codes of conduct! diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..20f0fa8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include UNLICENSE +include *.md +include tests +include .editorconfig diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..167ff9d --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,14 @@ +CMake.py [![Unlicensed work](https://raw.githubusercontent.com/unlicense/unlicense.org/master/static/favicon.png)](https://unlicense.org/) +=============== +[![GitLab Build Status](https://gitlab.com/KOLANICH/CMake.py/badges/master/pipeline.svg)](https://gitlab.com/KOLANICH/CMake.py/pipelines/master/latest) +![GitLab Coverage](https://gitlab.com/KOLANICH/CMake.py/badges/master/coverage.svg) +[![Coveralls Coverage](https://img.shields.io/coveralls/KOLANICH/CMake.py.svg)](https://coveralls.io/r/KOLANICH/CMake.py) +[![Libraries.io Status](https://img.shields.io/librariesio/github/KOLANICH/CMake.py.svg)](https://libraries.io/github/KOLANICH/CMake.py) +[![Code style: antiflash](https://img.shields.io/badge/code%20style-antiflash-FFF.svg)](https://github.com/KOLANICH-tools/antiflash.py) + +This is just a dumb implementation of CMake interpreter. Probably incorrect, but works fine enough for my purposes. The purpose of it is to parse CMake scripts used to configure CPack to extract from them info about how packaging should be done. + +Requirements +------------ +* [`Python >=3.4`](https://www.python.org/downloads/). [`Python 2` is dead, stop raping its corpse.](https://python3statement.org/) Use `2to3` with manual postprocessing to migrate incompatible code to `3`. It shouldn't take so much time. For unit-testing you need Python 3.6+ or PyPy3 because their `dict` is ordered and deterministic. Python 3 is also semi-dead, 3.7 is the last minor release in 3. +* [`cmake-ast`](https://github.com/polysquare/cmake-ast) ![Licence](https://img.shields.io/github/license/polysquare/cmake-ast.svg) [![PyPi Status](https://img.shields.io/pypi/v/cmake-ast.svg)](https://pypi.python.org/pypi/cmake-ast) [![TravisCI Build Status](https://travis-ci.org/polysquare/cmake-ast.svg?branch=master)](https://travis-ci.org/polysquare/cmake-ast) [![Libraries.io Status](https://img.shields.io/librariesio/github/polysquare/cmake-ast.svg)](https://libraries.io/github/polysquare/cmake-ast) diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 0000000..efb9808 --- /dev/null +++ b/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6524f2f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,31 @@ +[build-system] +requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3"] +build-backend = "setuptools.build_meta" + +[project] +name = "CMake" +authors = [{name = "KOLANICH"}] +description = "A dumb and incomplete implementation of CMake interpreter in python" +readme = "ReadMe.md" +keywords = ["cmake", "build"] +license = {text = "Unlicense"} +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Development Status :: 4 - Beta", + "Environment :: Other Environment", + "Intended Audience :: Developers", + "License :: Public Domain", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", +] +urls = {Homepage = "https://github.com/KOLANICH/CMake.py"} +requires-python = ">=3.4" +dependencies = ["cmakeast @ git+https://github.com/polysquare/cmake-ast.git"] +dynamic = ["version"] + +[tool.setuptools] +zip-safe = true +py-modules = ["CMake"] + +[tool.setuptools_scm] diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..639a616 --- /dev/null +++ b/tests/tests.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +import sys +from pathlib import Path +import unittest + +thisFile = Path(__file__).absolute() +thisDir = thisFile.parent.absolute() +repoMainDir = thisDir.parent.absolute() +sys.path.append(str(repoMainDir)) + +from collections import OrderedDict +dict=OrderedDict + +from CMake import * + +class SimpleTests(unittest.TestCase): + def setUp(self): + pass + + @unittest.skip + def testSetSimple(self): + cm = CMakeInterpreter() + cm.interpret('set(a "b")\n') + self.assertEqual(cm.ns["a"], "b") + + @unittest.skip + def testSetAssignOther(self): + cm = CMakeInterpreter() + cm.interpret('set(a "b")\n') + cm.interpret('set(c "${a}")\n') + self.assertEqual(cm.ns["c"], "b") + + @unittest.skip + def testMessage(self): + class ourBuiltins(cmakeBuiltins): + @classmethod + def message(cls, interp, args): + argz = parseFuncArgs(interp, messageSpec, args) + print(argz) + + cm = CMakeInterpreter(builtins = ourBuiltins) + cm.interpret('message(STATUS a)') + + @unittest.skip + def testInclude(self): + ourIncludes = { + "a": 'set(a "B")\ninclude(b)\n', + "b": 'set(b "C")\n', + } + class ourBuiltins(cmakeBuiltins): + @classmethod + def include(cls, interp, args): + argz = parseFuncArgs(interp, includeSpec, args) + try: + interp.interpret(ourIncludes[argz["path"]]) + if argz["RESULT_VARIABLE"]: + interp.ns[argz["RESULT_VARIABLE"]] = argz["path"] + except: + if argz["RESULT_VARIABLE"]: + interp.ns[argz["RESULT_VARIABLE"]] = argz["RESULT_VARIABLE"]+"-NOTFOUND" + + if not argz["OPTIONAL"]: + raise + + + cm = CMakeInterpreter(builtins = ourBuiltins) + cm.interpret('include(a OPTIONAL)') + self.assertEqual(cm.ns["a"], "B") + self.assertEqual(cm.ns["b"], "C") + return + + cm.interpret('include(a RESULT_VARIABLE )') + cm.interpret('include(a NO_POLICY_SCOPE)') + + cm = CMakeInterpreter(builtins = ourBuiltins) + cm.interpret('include(a OPTIONAL NO_POLICY_SCOPE)') + cm.interpret('include(a RESULT_VARIABLE NO_POLICY_SCOPE)') + + cm = CMakeInterpreter(builtins = ourBuiltins) + cm.interpret('include(a OPTIONAL RESULT_VARIABLE )') + cm.interpret('include(a OPTIONAL NO_POLICY_SCOPE)') + + cm = CMakeInterpreter(builtins = ourBuiltins) + cm.interpret('include(a OPTIONAL RESULT_VARIABLE NO_POLICY_SCOPE)') + + def testIfExists(self): + cm = CMakeInterpreter() + cm.interpret(""" + if(NOT EXISTS """+'"'+str(thisFile)+'"'+""") + set(exists "ON") + else() + set(exists "OFF") + endif() + """) + self.assertEqual(cm.ns["exists"], "OFF") + +if __name__ == '__main__': + unittest.main()