From ea63900e291943cd99f4b5d654d69a45913b4d44 Mon Sep 17 00:00:00 2001 From: Niranjan Yardi Date: Wed, 13 Nov 2024 17:24:03 -0800 Subject: [PATCH 1/3] Remove overwrite_args parser argument --- cobalt/build/gn.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cobalt/build/gn.py b/cobalt/build/gn.py index b769e6e12dd..91b4f3b119a 100755 --- a/cobalt/build/gn.py +++ b/cobalt/build/gn.py @@ -96,18 +96,24 @@ def write_build_args(build_args_path, original_lines, dict_settings, def main(out_directory: str, platform: str, build_type: str, - overwrite_args: bool, gn_gen_args: List[str]): + gn_gen_args: List[str]): platform_path = f'cobalt/build/configs/{platform}' dst_args_gn_file = os.path.join(out_directory, 'args.gn') src_args_gn_file = os.path.join(platform_path, 'args.gn') Path(out_directory).mkdir(parents=True, exist_ok=True) - if overwrite_args or not os.path.exists(dst_args_gn_file): - build_args = get_build_args(src_args_gn_file) + build_args = get_build_args(src_args_gn_file) + if not os.path.exists(dst_args_gn_file): write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) else: - print(f'{dst_args_gn_file} already exists.' + - ' Running ninja will regenerate build files automatically.') + # Overwrite args.gn, copy the stale args.gn file to stale_args.gn + stale_dst_args_gn_file = dst_args_gn_file.replace('args', 'stale_args') + os.rename(dst_args_gn_file, stale_dst_args_gn_file) + print(f' Warning: {dst_args_gn_file} is rewritten.' + + ' Old file is copied to {stale_dst_args_gn_file}.' + + 'In general, if the file exists, you should run' + + ' `gn args ` to edit it instead.') + write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) gn_command = ['gn', 'gen', out_directory] + gn_gen_args print(' '.join(gn_command)) @@ -145,13 +151,6 @@ def main(out_directory: str, platform: str, build_type: str, default='devel', choices=_BUILD_TYPES.keys(), help='The build_type (configuration) to build with.') - parser.add_argument( - '--overwrite_args', - default=False, - action='store_true', - help='Whether or not to overwrite an existing args.gn file if one exists ' - 'in the out directory. In general, if the file exists, you should run ' - '`gn args ` to edit it instead.') parser.add_argument( '--no-check', # TODO: b/377295011 - Enable gn --check @@ -173,4 +172,4 @@ def main(out_directory: str, platform: str, build_type: str, builds_out_directory = os.path.join( BUILDS_DIRECTORY, f'{script_args.platform}_{script_args.build_type}') main(builds_out_directory, script_args.platform, script_args.build_type, - script_args.overwrite_args, gen_args) + gen_args) From 9e33a698fa0e5176e5ce50d8a3b19c141ab31d6c Mon Sep 17 00:00:00 2001 From: Niranjan Yardi Date: Fri, 15 Nov 2024 11:21:17 -0800 Subject: [PATCH 2/3] Address feedback --- cobalt/build/gn.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cobalt/build/gn.py b/cobalt/build/gn.py index 91b4f3b119a..a95f0f14ee3 100755 --- a/cobalt/build/gn.py +++ b/cobalt/build/gn.py @@ -103,18 +103,15 @@ def main(out_directory: str, platform: str, build_type: str, Path(out_directory).mkdir(parents=True, exist_ok=True) build_args = get_build_args(src_args_gn_file) - if not os.path.exists(dst_args_gn_file): - write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) - else: - # Overwrite args.gn, copy the stale args.gn file to stale_args.gn + if os.path.exists(dst_args_gn_file): + # Copy the stale args.gn into stale_args.gn stale_dst_args_gn_file = dst_args_gn_file.replace('args', 'stale_args') os.rename(dst_args_gn_file, stale_dst_args_gn_file) print(f' Warning: {dst_args_gn_file} is rewritten.' + ' Old file is copied to {stale_dst_args_gn_file}.' + 'In general, if the file exists, you should run' + ' `gn args ` to edit it instead.') - write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) - + write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) gn_command = ['gn', 'gen', out_directory] + gn_gen_args print(' '.join(gn_command)) subprocess.check_call(gn_command) From a364c379d1fff8f15c959d229cc198844a177f6c Mon Sep 17 00:00:00 2001 From: Niranjan Yardi Date: Fri, 15 Nov 2024 12:29:04 -0800 Subject: [PATCH 3/3] Address feedback2 --- cobalt/build/gn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cobalt/build/gn.py b/cobalt/build/gn.py index a95f0f14ee3..a450f8d44c1 100755 --- a/cobalt/build/gn.py +++ b/cobalt/build/gn.py @@ -102,15 +102,15 @@ def main(out_directory: str, platform: str, build_type: str, src_args_gn_file = os.path.join(platform_path, 'args.gn') Path(out_directory).mkdir(parents=True, exist_ok=True) - build_args = get_build_args(src_args_gn_file) if os.path.exists(dst_args_gn_file): # Copy the stale args.gn into stale_args.gn stale_dst_args_gn_file = dst_args_gn_file.replace('args', 'stale_args') os.rename(dst_args_gn_file, stale_dst_args_gn_file) - print(f' Warning: {dst_args_gn_file} is rewritten.' + - ' Old file is copied to {stale_dst_args_gn_file}.' + - 'In general, if the file exists, you should run' + + print(f' Warning: {dst_args_gn_file} is rewritten.' + f' Old file is copied to {stale_dst_args_gn_file}.' + 'In general, if the file exists, you should run' ' `gn args ` to edit it instead.') + build_args = get_build_args(src_args_gn_file) write_build_args(dst_args_gn_file, build_args[0], build_args[1], build_type) gn_command = ['gn', 'gen', out_directory] + gn_gen_args print(' '.join(gn_command))