From df61b9ba25a4884785cc66f487cf090c80800813 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 1 Apr 2024 21:35:17 +0300 Subject: [PATCH 1/4] Fix compile_commands.json output location when generator_output is None Followup to #238 --- pylib/gyp/generator/compile_commands_json.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pylib/gyp/generator/compile_commands_json.py b/pylib/gyp/generator/compile_commands_json.py index a5594d13..d22f4cf6 100644 --- a/pylib/gyp/generator/compile_commands_json.py +++ b/pylib/gyp/generator/compile_commands_json.py @@ -108,10 +108,13 @@ def GenerateOutput(target_list, target_dicts, data, params): cwd = os.path.dirname(build_file) AddCommandsForTarget(cwd, target, params, per_config_commands) + output_dir = None try: - # generator_output can be `None` on Windows machines - output_dir = params["options"].generator_output or os.getcwd() + # generator_output can be `None` on Windows machines, or even not defined in other cases + output_dir = params["options"].generator_output except (AttributeError, KeyError): + pass + if output_dir is None: output_dir = params["generator_flags"].get("output_dir", "out") for configuration_name, commands in per_config_commands.items(): filename = os.path.join(output_dir, configuration_name, "compile_commands.json") From 7c60cb587f0e1ba7e51b338e63f33888b2196c1d Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 2 Apr 2024 11:36:53 +0300 Subject: [PATCH 2/4] Fix lint --- pylib/gyp/generator/compile_commands_json.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylib/gyp/generator/compile_commands_json.py b/pylib/gyp/generator/compile_commands_json.py index d22f4cf6..8a81c022 100644 --- a/pylib/gyp/generator/compile_commands_json.py +++ b/pylib/gyp/generator/compile_commands_json.py @@ -110,7 +110,8 @@ def GenerateOutput(target_list, target_dicts, data, params): output_dir = None try: - # generator_output can be `None` on Windows machines, or even not defined in other cases + # generator_output can be `None` on Windows machines, or even not + # defined in other cases output_dir = params["options"].generator_output except (AttributeError, KeyError): pass From 89cc9e470905ca9227d36105910ebcb5fbab9c11 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 2 Apr 2024 11:45:03 +0300 Subject: [PATCH 3/4] Update pylib/gyp/generator/compile_commands_json.py Co-authored-by: Christian Clauss --- pylib/gyp/generator/compile_commands_json.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pylib/gyp/generator/compile_commands_json.py b/pylib/gyp/generator/compile_commands_json.py index 8a81c022..f84c981d 100644 --- a/pylib/gyp/generator/compile_commands_json.py +++ b/pylib/gyp/generator/compile_commands_json.py @@ -115,8 +115,7 @@ def GenerateOutput(target_list, target_dicts, data, params): output_dir = params["options"].generator_output except (AttributeError, KeyError): pass - if output_dir is None: - output_dir = params["generator_flags"].get("output_dir", "out") + output_dir = output_dir or params["generator_flags"].get("output_dir", "out") for configuration_name, commands in per_config_commands.items(): filename = os.path.join(output_dir, configuration_name, "compile_commands.json") gyp.common.EnsureDirExists(filename) From aab0b24d1cda90c8ec930195b2bc765cfb55207d Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 2 Apr 2024 11:50:12 +0300 Subject: [PATCH 4/4] Update pylib/gyp/generator/compile_commands_json.py Co-authored-by: Christian Clauss --- pylib/gyp/generator/compile_commands_json.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pylib/gyp/generator/compile_commands_json.py b/pylib/gyp/generator/compile_commands_json.py index f84c981d..5d7f14da 100644 --- a/pylib/gyp/generator/compile_commands_json.py +++ b/pylib/gyp/generator/compile_commands_json.py @@ -112,8 +112,8 @@ def GenerateOutput(target_list, target_dicts, data, params): try: # generator_output can be `None` on Windows machines, or even not # defined in other cases - output_dir = params["options"].generator_output - except (AttributeError, KeyError): + output_dir = params.get("options").generator_output + except AttributeError: pass output_dir = output_dir or params["generator_flags"].get("output_dir", "out") for configuration_name, commands in per_config_commands.items():