Skip to content

Commit

Permalink
Don't hardcode constraint_overrides.bzl transition attributes
Browse files Browse the repository at this point in the history
Summary: In preparation for the rework in D64911682.

Reviewed By: mojsarn

Differential Revision: D64950866

fbshipit-source-id: ce60b12eb6f639a50e575dad6050996d1990537e
  • Loading branch information
Gabriel Agamennoni authored and facebook-github-bot committed Oct 29, 2024
1 parent f3cd53e commit bcded3e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions android/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load("@prelude//decls/common.bzl", "buck")
load("@prelude//decls/core_rules.bzl", "TargetCpuType")
load("@prelude//decls/toolchains_common.bzl", "toolchains_common")
load("@prelude//genrule.bzl", "genrule_attributes")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_attributes")
load(":android_aar.bzl", "android_aar_impl")
load(":android_apk.bzl", "android_apk_impl")
load(":android_build_config.bzl", "android_build_config_impl")
Expand Down Expand Up @@ -107,7 +108,6 @@ extra_attributes = {
"application_module_blacklist": attrs.option(attrs.list(attrs.transition_dep(cfg = cpu_transition)), default = None),
"application_module_configs": attrs.dict(key = attrs.string(), value = attrs.list(attrs.transition_dep(cfg = cpu_transition)), sorted = False, default = {}),
"build_config_values_file": attrs.option(attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()), default = None),
"constraint_overrides": attrs.list(attrs.string(), default = []),
"deps": attrs.list(attrs.split_transition_dep(cfg = cpu_split_transition), default = []),
"dex_tool": attrs.string(default = "d8"), # Match default in V1
"duplicate_resource_behavior": attrs.enum(DuplicateResourceBehaviour, default = "allow_by_default"), # Match default in V1
Expand All @@ -129,7 +129,7 @@ extra_attributes = {
"_is_force_single_default_cpu": attrs.default_only(attrs.bool(default = FORCE_SINGLE_DEFAULT_CPU)),
"_java_toolchain": toolchains_common.java_for_android(),
VALIDATION_DEPS_ATTR_NAME: attrs.set(attrs.transition_dep(cfg = cpu_transition), sorted = True, default = []),
},
} | constraint_overrides_attributes(),
"android_build_config": {
"_android_toolchain": toolchains_common.android(),
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
Expand Down
5 changes: 2 additions & 3 deletions python/python_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ load(
"depth_first_traversal_by",
)
load("@prelude//decls/toolchains_common.bzl", "toolchains_common")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_transition")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_attributes", "constraint_overrides_transition")

def _link_deps(
link_infos: dict[Label, LinkableNode],
Expand Down Expand Up @@ -221,13 +221,12 @@ python_wheel = rule(
"ovr_config//os:linux-x86_64": "linux_x86_64",
}),
),
constraint_overrides = attrs.list(attrs.string(), default = []),
libraries = attrs.list(attrs.dep(providers = [PythonLibraryInfo]), default = []),
scripts = attrs.dict(key = attrs.string(), value = attrs.source(), default = {}),
libraries_query = attrs.option(attrs.query(), default = None),
prefer_stripped_objects = attrs.default_only(attrs.bool(default = False)),
_wheel = attrs.default_only(attrs.exec_dep(default = "prelude//python/tools:wheel")),
_cxx_toolchain = toolchains_common.cxx(),
_python_toolchain = toolchains_common.python(),
),
) | constraint_overrides_attributes(),
)
13 changes: 4 additions & 9 deletions rules_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ load("@prelude//decls/scala_rules.bzl", "scala_rules")
load("@prelude//decls/shell_rules.bzl", "shell_rules")
load("@prelude//decls/toolchains_common.bzl", "toolchains_common")
load("@prelude//decls/uncategorized_rules.bzl", "uncategorized_rules")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_transition")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_attributes", "constraint_overrides_transition")
load(":alias.bzl", "alias_impl", "configured_alias_impl", "toolchain_alias_impl", "versioned_alias_impl")
load(":command_alias.bzl", "command_alias_impl")
load(":export_file.bzl", "export_file_impl")
Expand Down Expand Up @@ -266,11 +266,6 @@ def _cxx_python_extension_attrs():
})
return res

def _constraint_overrides_attr():
return {
"constraint_overrides": attrs.list(attrs.string(), default = []),
}

# Attrs common between python binary/test
def _python_executable_attrs():
cxx_binary_attrs = {k: v for k, v in cxx_rules.cxx_binary.attrs.items()}
Expand All @@ -284,7 +279,7 @@ def _python_executable_attrs():
if key not in python_executable_attrs
}

updated_attrs.update(_constraint_overrides_attr())
updated_attrs.update(constraint_overrides_attributes())

# allow non-default value for the args below
updated_attrs.update({
Expand Down Expand Up @@ -391,7 +386,7 @@ def _cxx_binary_and_test_attrs():
"_cxx_hacks": attrs.dep(default = "prelude//cxx/tools:cxx_hacks"),
"_cxx_toolchain": toolchains_common.cxx(),
}
ret.update(_constraint_overrides_attr())
ret.update(constraint_overrides_attributes())
return ret

NativeLinkStrategy = ["separate", "native", "merged"]
Expand Down Expand Up @@ -650,7 +645,7 @@ inlined_extra_attributes = {
"_unzip_tool": attrs.default_only(attrs.exec_dep(providers = [RunInfo], default = "prelude//zip_file/tools:unzip")),
},
"rust_test": {},
"sh_test": _constraint_overrides_attr(),
"sh_test": constraint_overrides_attributes(),
"windows_resource": {
"_cxx_toolchain": toolchains_common.cxx(),
},
Expand Down
8 changes: 8 additions & 0 deletions transitions/constraint_overrides.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ constraint_overrides_transition = transition(
"constraint_overrides",
],
)

def constraint_overrides_attributes() -> dict:
return {
"constraint_overrides": attrs.list(attrs.string(), default = []),
"constraint_overrides_strict": attrs.bool(default = False),
"constraint_passthroughs": attrs.list(attrs.string(), default = []),
"platform_override": attrs.option(attrs.string(), default = None),
}

0 comments on commit bcded3e

Please sign in to comment.