Skip to content

Commit 878d3f7

Browse files
committed
exp: move the precompilation toolchain disabling shortcircuit down the callstack
Stil not working: ``` $ bazel cquery 'deps(@dev_pip//charset_normalizer)' --transitions=lite --extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain | grep "toolchain dependency" Computing main repo mapping: Loading: Loading: 0 packages loaded WARNING: Build option --extra_toolchains has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed). Analyzing: target @@_main~pip_internal~dev_pip//charset_normalizer:charset_normalizer (0 packages loaded, 0 targets configured) INFO: Analyzed target @@_main~pip_internal~dev_pip//charset_normalizer:charset_normalizer (1 packages loaded, 1530 targets configured). INFO: Found 1 target... [toolchain dependency]#@@_main~python~python_3_11_x86_64-unknown-linux-gnu//:py_exec_tools_toolchain#NoTransition -> [toolchain dependency]#@bazel_tools//tools/python:_autodetecting_py_runtime_pair#NoTransition -> INFO: Elapsed time: 0.342s, Critical Path: 0.00s INFO: 0 processes. INFO: Build completed successfully, 0 total actions ```
1 parent 35cbc55 commit 878d3f7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

python/private/common/common_bazel.bzl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,7 @@ def maybe_precompile(ctx, srcs):
6565
* `py_to_pyc_map`: dict of src File input to pyc File output. If a source
6666
file wasn't precompiled, it won't be in the dict.
6767
"""
68-
69-
# The exec tools toolchain and precompiler are optional. Rather than
70-
# fail, just skip precompiling, as its mostly just an optimization.
71-
exec_tools_toolchain = ctx.toolchains[EXEC_TOOLS_TOOLCHAIN_TYPE]
72-
if exec_tools_toolchain == None or exec_tools_toolchain.exec_tools.precompiler == None:
73-
precompile = PrecompileAttr.DISABLED
74-
else:
75-
precompile = PrecompileAttr.get_effective_value(ctx)
68+
precompile = PrecompileAttr.get_effective_value(ctx)
7669

7770
source_retention = PrecompileSourceRetentionAttr.get_effective_value(ctx)
7871

@@ -98,6 +91,12 @@ def maybe_precompile(ctx, srcs):
9891
(source_retention == PrecompileSourceRetentionAttr.OMIT_IF_GENERATED_SOURCE and not is_generated_source)
9992
)
10093
if should_precompile:
94+
# The exec tools toolchain and precompiler are optional. Rather than
95+
# fail, just skip precompiling, as its mostly just an optimization.
96+
exec_tools_toolchain = ctx.toolchains[EXEC_TOOLS_TOOLCHAIN_TYPE]
97+
if exec_tools_toolchain == None or exec_tools_toolchain.exec_tools.precompiler == None:
98+
precompile = PrecompileAttr.DISABLED
99+
break
101100
pyc = _precompile(ctx, src, use_pycache = keep_source)
102101
result.pyc_files.append(pyc)
103102
result.py_to_pyc_map[src] = pyc

0 commit comments

Comments
 (0)