From b03364a4b1057486b07fe5b7e840ef662bae5274 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 9 Dec 2020 12:01:01 +0200 Subject: [PATCH] build script: add argument combining rules for command line options --- build.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index c515ca2d..2fb44b30 100755 --- a/build.py +++ b/build.py @@ -36,12 +36,22 @@ import zipapp class CommandLineOptions(dict): - def to_list(self, prefix='') -> list: + # Rules to combine argument's name and value + MAKE_RULES = 0 + CMAKE_RULES = 1 + + def to_list(self, rules=MAKE_RULES) -> list: result = [] for arg_name, arg_value in self.items(): - option = prefix + arg_name - option += arg_value and ('=' + arg_value) or '' + if rules == CommandLineOptions.MAKE_RULES: + option = arg_name + ('=' + arg_value) if arg_value else '' + elif rules == CommandLineOptions.CMAKE_RULES: + arg_value = arg_value if arg_value else '' + option = f'-D{arg_name}={arg_value}' + else: + assert False, 'Unknown argument rules' + result.append(option) return result @@ -280,7 +290,7 @@ class CMakeTarget(Target): if builder.sdk_path: args.append('-DCMAKE_OSX_SYSROOT=' + builder.sdk_path) - args += self.options.to_list('-D') + args += self.options.to_list(CommandLineOptions.CMAKE_RULES) args.append(builder.source_path + self.src_root) subprocess.check_call(args, cwd=builder.build_path, env=self.environment)