Skip to content

Commit 099720b

Browse files
Kasra Ghodsimeta-codesync[bot]
authored andcommitted
Add Directory Rollout Support
Summary: ## Context: See T239185724. We want to enable content-based output path addressing for Python bytecode to deduplicate the output artifacts when the BUCK configuration changes but the output remains the same (e.g., switching between `opt` and `dev` mode.) --- ## This Diff: To mitigate build failure risk, I'm adopting the same rollout approach used for rust_make_par (see D77735814). I initialize this to only enable Python content based path hashing for binaries in the `fbcode//python` directory. Reviewed By: alexmalyshev Differential Revision: D89552557 fbshipit-source-id: 7ea3042255daca5c190670ef945cd5ee0f00fef9
1 parent af88f38 commit 099720b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

prelude/decls/python_rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _python_executable_attrs():
102102
"static_extension_utils": attrs.source(default = "prelude//python/tools:static_extension_utils.cpp"),
103103
"strip_libpar": attrs.enum(StripLibparStrategy, default = "none"),
104104
"strip_stapsdt": attrs.bool(default = False),
105+
"supports_pyc_content_based_paths": attrs.bool(default = False), # TODO(kasrag) Delete this when content-based paths are fulled rolled out
105106
"use_anon_target_for_analysis": attrs.bool(default = False), # TODO(dcssiva) Delete this when we change the default analysis method to use anon targets
106107
"use_oss_python": attrs.bool(default = False),
107108
"use_rust_make_par": attrs.bool(default = False), # TODO(rishiarora) Delete this when we change the default build style

prelude/python/compile.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def compile_manifests_for_mode(
2929
manifests: list[ManifestInfo],
3030
invalidation_mode: PycInvalidationMode = PycInvalidationMode("unchecked_hash")) -> ManifestInfo:
3131
mode = invalidation_mode.value.upper()
32-
has_content_based_path = ctx.attrs._python_toolchain[PythonToolchainInfo].supports_content_based_paths == True
32+
has_content_based_path = (
33+
getattr(ctx.attrs, "supports_pyc_content_based_paths", False) == True and
34+
ctx.attrs._python_toolchain[PythonToolchainInfo].supports_content_based_paths == True
35+
)
3336
output = ctx.actions.declare_output("bytecode_{}".format(mode), dir = True, has_content_based_path = has_content_based_path)
3437
bytecode_manifest = ctx.actions.declare_output("bytecode_{}.manifest".format(mode), has_content_based_path = has_content_based_path)
3538
cmd = [

prelude/python/make_py_package.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,11 @@ def _pex_modules_args(
10381038
# placeholder "output_artifacts" portion of the path with the resolved hash.
10391039
# This isn't needed for inplace builds which symlink to original bytecode artifacts without path resolution.
10401040
inplace = package_style in [PackageStyle("inplace"), PackageStyle("inplace_lite")]
1041-
if not inplace and ctx.attrs._python_toolchain[PythonToolchainInfo].supports_content_based_paths:
1041+
if (
1042+
not inplace and
1043+
getattr(ctx.attrs, "supports_pyc_content_based_paths", False) and
1044+
ctx.attrs._python_toolchain[PythonToolchainInfo].supports_content_based_paths
1045+
):
10421046
bytecode_artifacts = pex_modules.manifests.bytecode_artifacts(pyc_mode)
10431047

10441048
bytecode_artifacts_path = ctx.actions.write(

0 commit comments

Comments
 (0)