File tree Expand file tree Collapse file tree 4 files changed +19
-4
lines changed
docs/api/rules_python/python/config_settings Expand file tree Collapse file tree 4 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ except for the case of `force_enabled` and `forced_disabled`.
3636
3737Values:
3838
39- * ` auto ` : Automatically decide the effective value based on environment,
39+ * ` auto ` : (default) Automatically decide the effective value based on environment,
4040 target platform, etc.
4141* ` enabled ` : Compile Python source files at build time. Note that
4242 {bzl: obj }` --precompile_add_to_runfiles ` affects how the compiled files are included into
@@ -65,12 +65,18 @@ attribute.
6565
6666Values:
6767
68+ * ` auto ` : (default) Automatically decide the effective value based on environment,
69+ target platform, etc.
6870* ` keep_source ` : Include the original Python source.
6971* ` omit_source ` : Don't include the orignal py source.
7072* ` omit_if_generated_source ` : Keep the original source if it's a regular source
7173 file, but omit it if it's a generated file.
74+
7275:::{versionadded} 0.33.0
7376:::
77+ :::{versionadded} 0.36.0
78+ The ` auto ` value
79+ :::
7480::::
7581
7682::::{bzl: flag } precompile_add_to_runfiles
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ string_flag(
5858
5959string_flag (
6060 name = "precompile_source_retention" ,
61- build_setting_default = PrecompileSourceRetentionFlag .KEEP_SOURCE ,
61+ build_setting_default = PrecompileSourceRetentionFlag .AUTO ,
6262 values = sorted (PrecompileSourceRetentionFlag .__members__ .values ()),
6363 # NOTE: Only public because it's an implicit dependency
6464 visibility = ["//visibility:public" ],
Original file line number Diff line number Diff line change 1616load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
1717load ("@rules_cc//cc:defs.bzl" , "CcInfo" )
1818load ("//python/private:enum.bzl" , "enum" )
19- load ("//python/private:flags.bzl" , "PrecompileFlag" )
19+ load ("//python/private:flags.bzl" , "PrecompileFlag" , "PrecompileSourceRetentionFlag" )
2020load ("//python/private:reexports.bzl" , "BuiltinPyInfo" )
2121load (":common.bzl" , "union_attrs" )
2222load (":providers.bzl" , "PyInfo" )
@@ -85,7 +85,7 @@ PrecompileInvalidationModeAttr = enum(
8585def _precompile_source_retention_get_effective_value (ctx ):
8686 attr_value = ctx .attr .precompile_source_retention
8787 if attr_value == PrecompileSourceRetentionAttr .INHERIT :
88- attr_value = ctx . attr . _precompile_source_retention_flag [ BuildSettingInfo ]. value
88+ attr_value = PrecompileSourceRetentionFlag . get_effective_value ( ctx )
8989
9090 if attr_value not in (
9191 PrecompileSourceRetentionAttr .KEEP_SOURCE ,
Original file line number Diff line number Diff line change @@ -74,17 +74,26 @@ PrecompileFlag = enum(
7474 get_effective_value = _precompile_flag_get_effective_value ,
7575)
7676
77+ def _precompile_source_retention_flag_get_effective_value (ctx ):
78+ value = ctx .attr ._precompile_source_retention_flag [BuildSettingInfo ].value
79+ if value == PrecompileSourceRetentionFlag .AUTO :
80+ value = PrecompileSourceRetentionFlag .KEEP_SOURCE
81+ return value
82+
7783# Determines if, when a source file is compiled, if the source file is kept
7884# in the resulting output or not.
7985# buildifier: disable=name-conventions
8086PrecompileSourceRetentionFlag = enum (
87+ # Automatically decide the effective value based on environment, etc.
88+ AUTO = "auto" ,
8189 # Include the original py source in the output.
8290 KEEP_SOURCE = "keep_source" ,
8391 # Don't include the original py source.
8492 OMIT_SOURCE = "omit_source" ,
8593 # Keep the original py source if it's a regular source file, but omit it
8694 # if it's a generated file.
8795 OMIT_IF_GENERATED_SOURCE = "omit_if_generated_source" ,
96+ get_effective_value = _precompile_source_retention_flag_get_effective_value ,
8897)
8998
9099# Determines if a target adds its compiled files to its runfiles. When a target
You can’t perform that action at this time.
0 commit comments