Skip to content

Commit f7e54ab

Browse files
committed
Enable --host_features=-compiler_param_file only when Bazel >= 6.1.0
This flag is only available in Bazel >= 6.1.0.
1 parent b998dca commit f7e54ab

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

refresh.template.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,37 @@ def _print_header_finding_warning_once():
9696
_print_header_finding_warning_once.has_logged = False
9797

9898

99+
@functools.lru_cache(maxsize=None)
100+
def _get_bazel_version():
101+
"""Gets the Bazel version as a tuple of (major, minor, patch).
102+
103+
The rolling release and the release candidate are treated as the LTS release.
104+
E.g. both 7.0.0-pre.XXXXXXXX.X and 7.0.0rc1 are treated as 7.0.0.
105+
If the version can't be determined, returns (0, 0, 0).
106+
"""
107+
bazel_version_process = subprocess.run(
108+
['bazel', 'version'],
109+
# MIN_PY=3.7: Replace PIPEs with capture_output.
110+
stdout=subprocess.PIPE,
111+
stderr=subprocess.PIPE,
112+
encoding=locale.getpreferredencoding(),
113+
check=True, # Should always succeed.
114+
)
115+
116+
version = ''
117+
for line in bazel_version_process.stdout.splitlines():
118+
line = line.strip()
119+
if line.startswith('Build label: '):
120+
version = line[len('Build label: '):]
121+
122+
match = re.search(r'^(\d+)\.(\d+)\.(\d+)', version)
123+
if not match:
124+
log_warning(f">>> Failed to get Bazel version.\nPlease file an issue with the following log:\n", bazel_version_process.stdout)
125+
return (0, 0, 0)
126+
127+
return tuple(int(match.group(i)) for i in range(1, 4))
128+
129+
99130
@functools.lru_cache(maxsize=None)
100131
def _get_bazel_cached_action_keys():
101132
"""Gets the set of actionKeys cached in bazel-out."""
@@ -1165,13 +1196,17 @@ def _get_commands(target: str, flags: str):
11651196
# That's all well and good, but param files would prevent us from seeing compile actions before the param files had been generated by compilation.
11661197
# Since clangd has no such length limit, we'll disable param files for our aquery run.
11671198
'--features=-compiler_param_file',
1168-
'--host_features=-compiler_param_file',
11691199
# Disable layering_check during, because it causes large-scale dependence on generated module map files that prevent header extraction before their generation
11701200
# For more context, see https://github.com/hedronvision/bazel-compile-commands-extractor/issues/83
11711201
# If https://github.com/clangd/clangd/issues/123 is resolved and we're not doing header extraction, we could try removing this, checking that there aren't erroneous red squigglies squigglies before the module maps are generated.
11721202
# If Bazel starts supporting modules (https://github.com/bazelbuild/bazel/issues/4005), we'll probably need to make changes that subsume this.
11731203
'--features=-layering_check',
1174-
] + additional_flags
1204+
]
1205+
1206+
if _get_bazel_version() >= (6, 1, 0):
1207+
aquery_args += ['--host_features=-compiler_param_file']
1208+
1209+
aquery_args += additional_flags
11751210

11761211
aquery_process = subprocess.run(
11771212
aquery_args,

0 commit comments

Comments
 (0)