From 2cb273c2dc53e2cdacd1470425a85fceb8944cfc Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 17 Aug 2023 14:39:06 +0200 Subject: ["CC/auto", "config_file"] rename implicit target ... and mention it at the appropriate part of the documentation. While there, also provide a default TARGETS file. --- rules/CC/auto/RULES | 7 +++- rules/CC/auto/TARGETS | 1 + rules/CC/auto/config_runner.py | 76 ------------------------------------------ rules/CC/auto/runner | 76 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 77 deletions(-) create mode 100644 rules/CC/auto/TARGETS delete mode 100755 rules/CC/auto/config_runner.py create mode 100755 rules/CC/auto/runner diff --git a/rules/CC/auto/RULES b/rules/CC/auto/RULES index 0e156c98..860db01c 100644 --- a/rules/CC/auto/RULES +++ b/rules/CC/auto/RULES @@ -1015,6 +1015,11 @@ , "target configuration. In the usual case, a target using this rule is" , "configured by depending on it from a target that uses the built-in" , "\"configure\" rule." + , "" + , "The actual generation of the header file from the template" + , "is done by the implicit dependency on the \"runner\" target which" + , "can be changed globally by setting this target in the" + , "target layer of this repository." ] , "field_doc": { "output": @@ -1045,7 +1050,7 @@ , "last": "last_list_entry" , "stage_singleton_field": ["", "stage_singleton_field"] } - , "implicit": {"runner": ["config_runner.py"]} + , "implicit": {"runner": ["runner"]} , "expression": { "type": "let*" , "bindings": diff --git a/rules/CC/auto/TARGETS b/rules/CC/auto/TARGETS new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/rules/CC/auto/TARGETS @@ -0,0 +1 @@ +{} diff --git a/rules/CC/auto/config_runner.py b/rules/CC/auto/config_runner.py deleted file mode 100755 index f938c272..00000000 --- a/rules/CC/auto/config_runner.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/python3 - -# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import json -import re -from sys import argv -from re import sub, match - -input_file = argv[1] -param_file = argv[2] -magic_string = argv[3] -at_only = argv[4] == "true" - - -with open(param_file) as f: - param = json.loads(f.read()) - -# In many cases, CMake simply defines some variables (without any associated -# value). We handle this situation by assigning to the boolean True the empty -# string. Note that no False value should be found, because the right way to set -# a variable to False in the TARGETS file is to *do not mention* that variable -# at all. -for k, v in param.items(): - if isinstance(v, bool): - param[k] = "" - -with open(input_file) as i: - with open("out", "w") as o: - for line in i.readlines(): - if x := re.search( - r"#(.*)(" + magic_string + r" )([ \t]*)([a-zA-Z0-9_]+)", line - ): - # get the VAR - key = x.groups()[-1] - if key in param: - line = sub( - f"{x.group()[1:]}", - f"{x.groups()[0]}define {x.groups()[2]}{key} {param[key]}", - line, - ) - else: - line = f"/* #undef {x.groups()[-1]} */\n" - if x := re.search( - r"#(.*)(" + magic_string + "01 )([ \t]*)([a-zA-Z0-9_]+)", line - ): - # get the VAR - key = x.groups()[-1] - line = sub( - f"{x.group()[1:]}", - f"{x.groups()[0]}define {x.groups()[2]}{key} " - + str(1 if key in param else 0), - line, - ) - if match("#[ \t]*define", line): - if x := re.search(r"@([a-zA-Z0-9-_]+)@", line): - key = x.groups()[0] - line = sub(x.group(), param.get(key, ""), line) - if not at_only: - if x := re.search(r"\${([a-zA-Z0-9-_]+)}", line): - key = x.groups()[0] - line = sub(r"\${" + key + r"}", param.get(key, ""), line) - - print(line, end="", file=o) diff --git a/rules/CC/auto/runner b/rules/CC/auto/runner new file mode 100755 index 00000000..f938c272 --- /dev/null +++ b/rules/CC/auto/runner @@ -0,0 +1,76 @@ +#!/usr/bin/python3 + +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import re +from sys import argv +from re import sub, match + +input_file = argv[1] +param_file = argv[2] +magic_string = argv[3] +at_only = argv[4] == "true" + + +with open(param_file) as f: + param = json.loads(f.read()) + +# In many cases, CMake simply defines some variables (without any associated +# value). We handle this situation by assigning to the boolean True the empty +# string. Note that no False value should be found, because the right way to set +# a variable to False in the TARGETS file is to *do not mention* that variable +# at all. +for k, v in param.items(): + if isinstance(v, bool): + param[k] = "" + +with open(input_file) as i: + with open("out", "w") as o: + for line in i.readlines(): + if x := re.search( + r"#(.*)(" + magic_string + r" )([ \t]*)([a-zA-Z0-9_]+)", line + ): + # get the VAR + key = x.groups()[-1] + if key in param: + line = sub( + f"{x.group()[1:]}", + f"{x.groups()[0]}define {x.groups()[2]}{key} {param[key]}", + line, + ) + else: + line = f"/* #undef {x.groups()[-1]} */\n" + if x := re.search( + r"#(.*)(" + magic_string + "01 )([ \t]*)([a-zA-Z0-9_]+)", line + ): + # get the VAR + key = x.groups()[-1] + line = sub( + f"{x.group()[1:]}", + f"{x.groups()[0]}define {x.groups()[2]}{key} " + + str(1 if key in param else 0), + line, + ) + if match("#[ \t]*define", line): + if x := re.search(r"@([a-zA-Z0-9-_]+)@", line): + key = x.groups()[0] + line = sub(x.group(), param.get(key, ""), line) + if not at_only: + if x := re.search(r"\${([a-zA-Z0-9-_]+)}", line): + key = x.groups()[0] + line = sub(r"\${" + key + r"}", param.get(key, ""), line) + + print(line, end="", file=o) -- cgit v1.2.3