diff --git a/ui2abc/gn/command/gen_sdk.py b/ui2abc/gn/command/gen_sdk.py index f9bb97ea23a044fa88d0540bf98f23e02d1c05fb..9e88e15981de5c044e5e92de181cae92c118ce00 100755 --- a/ui2abc/gn/command/gen_sdk.py +++ b/ui2abc/gn/command/gen_sdk.py @@ -28,9 +28,6 @@ def get_compiler_type(os, cpu): return 'mingw_x86_64' return 'clang_x64' -def replace_out_root(value, out_root, compiler_type): - """Replace $out_root in the string with the actual value.""" - return value.replace("$out_root", out_root).replace("$compiler_type", compiler_type) def validate_out_root(out_root, compiler_type): head_out_root, tail_out_root = os.path.split(out_root) @@ -38,18 +35,18 @@ def validate_out_root(out_root, compiler_type): return head_out_root return out_root +def apply_substitutions(targets, substitutions): + # Replace $out_root et al + for i in range(len(targets)): + for key, val in substitutions.items(): + targets[i] = targets[i].replace(key, val) + return targets -def copy_files(config, src_base, dist_base, out_root, compiler_type, substitutions): + +def copy_files(config, src_base, dist_base, substitutions): """Copy files or directories based on the configuration.""" for mapping in config['file_mappings']: - # Replace $out_root - source = replace_out_root(mapping['source'], out_root, compiler_type) - destination = replace_out_root(mapping['destination'], out_root, compiler_type) - - if substitutions: - for key, val in substitutions.items(): - source = source.replace(key, val) - destination = destination.replace(key, val) + source, destination = apply_substitutions([mapping[key] for key in ['source', 'destination']], substitutions) # Build full paths source = os.path.join(src_base, source) @@ -95,18 +92,18 @@ def main(): config = load_config(args.config) compiler_type = get_compiler_type(args.current_os, args.current_cpu) - out_root = validate_out_root(args.out_root, compiler_type) - substitutions = config.get('substitutions') + substitutions = {"$out_root": out_root, "$compiler_type": compiler_type} - if substitutions: - substitutions = substitutions.get(args.current_os) - if not substitutions: + cfg_subst = config.get('substitutions') + if cfg_subst: + if args.current_os not in cfg_subst: raise Exception(f'Substitutions not found for current_os "{args.current_os}".') + substitutions.update(cfg_subst.get(args.current_os)) # Copy files or directories - copy_files(config, args.src, args.dist, out_root, compiler_type, substitutions) + copy_files(config, args.src, args.dist, substitutions) # Create package.json to pass SDK validation content = """{