Skip to content

Commit

Permalink
[antlir] move internal_external and is_facebook into separate file
Browse files Browse the repository at this point in the history
Summary:
Move these two things into a separate bzl file that we know will never `load()`
anything else, preventing any circular dependencies from popping up.

Test Plan: waitforsandcastle

Reviewed By: epilatow

Differential Revision: D66884674

fbshipit-source-id: b8c7908b272b09001d25b878cbf05fb28f1dd828
  • Loading branch information
vmagro authored and facebook-github-bot committed Dec 16, 2024
1 parent e134288 commit 25522ca
Show file tree
Hide file tree
Showing 34 changed files with 63 additions and 40 deletions.
3 changes: 2 additions & 1 deletion antlir/antlir2/antlir2_packager/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/bzl:build_defs.bzl", "internal_external", "rust_binary")
load("//antlir/bzl:build_defs.bzl", "rust_binary")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/antlir2_packager/btrfs_packager/BUCK
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//antlir/bzl:build_defs.bzl", "internal_external", "rust_binary")
load("//antlir/bzl:build_defs.bzl", "rust_binary")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/antlir2_working_volume/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @oss-disable
load("@prelude//utils:buckconfig.bzl", "read_bool")
load("//antlir/bzl:build_defs.bzl", "is_facebook", "rust_library")
load("//antlir/bzl:build_defs.bzl", "rust_library")
load("//antlir/bzl:internal_external.bzl", "is_facebook")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/appliance_vm/BUCK
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule", "internal_external")
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/bzl/configured_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ load("//antlir/antlir2/bzl/image:cfg.bzl", "cfg_attrs")
# @oss-disable
load("//antlir/antlir2/cfg/systemd:defs.bzl", "systemd_cfg")
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs")
load("//antlir/bzl:build_defs.bzl", "get_visibility", "is_facebook")
load("//antlir/bzl:build_defs.bzl", "get_visibility")
load("//antlir/bzl:internal_external.bzl", "is_facebook")
load("//antlir/bzl:oss_shim.bzl", fb_transition = "ret_none") # @oss-enable

def _transition_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> PlatformInfo:
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/image/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ load("//antlir/bzl:oss_shim.bzl", fb_cfg_attrs = "empty_dict", fb_refs = "empty_
load("//antlir/antlir2/cfg/systemd:defs.bzl", "systemd_cfg")
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs")
load("//antlir/antlir2/os:oses.bzl", "OSES")
load("//antlir/bzl:build_defs.bzl", "is_facebook")
load("//antlir/bzl:internal_external.bzl", "is_facebook")

def cfg_attrs():
return {
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/image/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ load(
load("//antlir/antlir2/os:package.bzl", "get_default_os_for_package", "should_all_images_in_package_use_default_os")
# @oss-disable
load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "RepoInfo", "RepoSetInfo")
load("//antlir/bzl:build_defs.bzl", "is_facebook")
load("//antlir/bzl:constants.bzl", "REPO_CFG")
load("//antlir/bzl:internal_external.bzl", "is_facebook")
load("//antlir/bzl:types.bzl", "types")
load("//antlir/bzl/build_defs.bzl", "config", "get_visibility")
load(":cfg.bzl", "attrs_selected_by_cfg", "cfg_attrs", "layer_cfg")
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/image/prebuilt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load("//antlir/antlir2/antlir2_rootless:package.bzl", "get_antlir2_rootless")
load("//antlir/antlir2/bzl:build_phase.bzl", "BuildPhase")
load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform")
load("//antlir/antlir2/bzl:types.bzl", "BuildApplianceInfo", "FlavorInfo", "LayerContents", "LayerInfo")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load(":facts.bzl", "facts")

PrebuiltImageInfo = provider(fields = [
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/package/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load("//antlir/bzl:oss_shim.bzl", fb_cfg_attrs = "empty_dict", fb_refs = "empty_
# @oss-disable
load("//antlir/antlir2/cfg/systemd:defs.bzl", "systemd_cfg")
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs")
load("//antlir/bzl:build_defs.bzl", "is_facebook")
load("//antlir/bzl:internal_external.bzl", "is_facebook")

def cfg_attrs():
return _cfg_attrs() | rootless_cfg.attrs
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/bzl/package/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("//antlir/antlir2/bzl:platform.bzl", "arch_select", "os_select")
load("//antlir/antlir2/bzl:types.bzl", "BuildApplianceInfo", "LayerInfo")
load("//antlir/antlir2/bzl/image:cfg.bzl", "attrs_selected_by_cfg")
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load(":btrfs.bzl", "btrfs")
load(":cfg.bzl", "layer_attrs", "package_cfg")
load(":gpt.bzl", "GptPartitionSource", "gpt")
Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/features/dot_meta/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/bzl/package:defs.bzl", "package")
load("//antlir/antlir2/features/dot_meta:dot_meta.bzl", "dot_meta")
load("//antlir/antlir2/testing:image_diff_test.bzl", "image_diff_test")
load("//antlir/bzl:build_defs.bzl", "buck_sh_test", "internal_external")
load("//antlir/bzl:build_defs.bzl", "buck_sh_test")
load("//antlir/bzl:internal_external.bzl", "internal_external")

# Normally, the `dot_meta` feature is included only when packaging up a final
# layer, but we want to make it easier to test with image_diff_test, so these
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/features/extract/extract.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ load("//antlir/antlir2/features:defs.bzl", "FeaturePluginInfo")
load("//antlir/antlir2/features:dependency_layer_info.bzl", "layer_dep_analyze")
load("//antlir/antlir2/features:feature_info.bzl", "FeatureAnalysis", "ParseTimeFeature")
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")

def extract_from_layer(
layer: str | Select,
Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/features/extract/tests/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/testing:image_test.bzl", "image_sh_test")
load("//antlir/bzl:build_defs.bzl", "internal_external", "rust_binary")
load("//antlir/bzl:build_defs.bzl", "rust_binary")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/features/genrule/tests/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/testing:image_diff_test.bzl", "image_diff_test")
load("//antlir/bzl:build_defs.bzl", "is_facebook", "rust_binary")
load("//antlir/bzl:build_defs.bzl", "rust_binary")
load("//antlir/bzl:internal_external.bzl", "is_facebook")

oncall("antlir")

Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/features/install/install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load(
"ParseTimeFeature",
)
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load("//antlir/bzl:stat.bzl", "stat")

default_permissions = record(
Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/features/rpm/tests/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "repo_set")
load("//antlir/antlir2/testing:image_test.bzl", "image_python_test", "image_sh_test")
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule", "internal_external", "python_binary")
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule", "python_binary")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load(":defs.bzl", "expected_t", "test_rpms")

oncall("antlir")
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/flavor/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("//antlir/antlir2/bzl/flavor:defs.bzl", "flavor")
load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "repo_set")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/libcap/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @oss-disable
load("//antlir/bzl:build_defs.bzl", "alias", "internal_external", "rust_bindgen_library", "rust_library")
load("//antlir/bzl:build_defs.bzl", "alias", "rust_bindgen_library", "rust_library")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/os/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/bzl:build_defs.bzl", "internal_external", "is_facebook")
load("//antlir/bzl:internal_external.bzl", "internal_external", "is_facebook")
load(":defs.bzl", "OsVersionInfo")
load(":oses.bzl", "OSES")

Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/os/oses.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/bzl:build_defs.bzl", "internal_external", "is_facebook")
load("//antlir/bzl:internal_external.bzl", "internal_external", "is_facebook")

arch_t = enum("x86_64", "aarch64")

Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/package_managers/dnf/build_appliance/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("//antlir/antlir2/bzl:json_file.bzl", "json_file")
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "repo_set")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/package_managers/dnf/rules/makecache/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/bzl:build_defs.bzl", "buck_sh_binary", "export_file", "internal_external")
load("//antlir/bzl:build_defs.bzl", "buck_sh_binary", "export_file")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
3 changes: 2 additions & 1 deletion antlir/antlir2/package_managers/dnf/rules/makerepo/BUCK
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//antlir/bzl:build_defs.bzl", "buck_sh_binary", "is_facebook", "rust_binary")
load("//antlir/bzl:build_defs.bzl", "buck_sh_binary", "rust_binary")
load("//antlir/bzl:internal_external.bzl", "is_facebook")

oncall("antlir")

Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/package_managers/dnf/rules/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# LICENSE file in the root directory of this source tree.

load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform")
load("//antlir/bzl:build_defs.bzl", "is_facebook")
load("//antlir/bzl:internal_external.bzl", "is_facebook")
load(":rpm.bzl", "RpmInfo", "nevra_to_string", "package_href")

RepoInfo = provider(fields = [
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/test_images/cfg/os/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("//antlir/antlir2/bzl/package:defs.bzl", "package")
load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "repo")
load("//antlir/antlir2/package_managers/dnf/rules:rpm.bzl", "rpm")
load("//antlir/antlir2/testing:image_test.bzl", "image_rust_test")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load(":defs.bzl", "write_os")

oncall("antlir")
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/test_images/remote_execution/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/genrule_in_image:genrule_in_image.bzl", "genrule_in_image")
load("//antlir/antlir2/testing:image_rpms_test.bzl", "image_test_rpm_names")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down
4 changes: 3 additions & 1 deletion antlir/antlir2/testing/image_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:cfg.bzl", "cfg_attrs", "layer_cfg")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/bzl:build_defs.bzl", "add_test_framework_label", "buck_sh_test", "cpp_unittest", "internal_external", "is_facebook", "python_unittest", "rust_unittest")
load("//antlir/bzl:build_defs.bzl", "add_test_framework_label", "buck_sh_test", "cpp_unittest", "python_unittest", "rust_unittest")
load("//antlir/bzl:oss_shim.bzl", "special_tags") # @oss-enable

load("//antlir/bzl:internal_external.bzl", "internal_external", "is_facebook")

HIDE_TEST_LABELS = [special_tags.disabled, special_tags.test_is_invisible_to_testpilot]

def _default_list(maybe_value: list[str] | None, default: list[str]) -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion antlir/antlir2/testing/tests/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/bzl:build_defs.bzl", "internal_external")
load("//antlir/bzl:internal_external.bzl", "internal_external")

def _product(*iterables):
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
Expand Down
10 changes: 2 additions & 8 deletions antlir/bzl/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load("@prelude//utils:selects.bzl", "selects")
# FB-internal contributors will be less likely to accidentally break
# open-source by starting to use un-shimmed features.
load(":build_defs_impl.bzl", "shim")
load(":internal_external.bzl", "is_facebook")

def _third_party_libraries(names, platform = None):
return [
Expand Down Expand Up @@ -56,7 +57,7 @@ def _rust_common(rule, **kwargs):
if rule != shim.rust_unittest and rule != shim.rust_python_extension and rule != shim.rust_bindgen_library:
kwargs["unittests"] = False

if shim.is_facebook:
if is_facebook:
deps = selects.apply(kwargs.pop("deps", []), lambda deps: [_ensure_dep_is_public(dep) for dep in deps])
kwargs["deps"] = selects.apply(deps, lambda deps: deps + list(kwargs.pop("fb_deps", [])))
if kwargs.get("unittests", False):
Expand Down Expand Up @@ -132,12 +133,6 @@ echo = rule(
attrs = {"content": attrs.string()},
)

def internal_external(*, fb, oss):
if is_facebook:
return fb
else:
return oss

cpp_binary = shim.cpp_binary
cpp_library = shim.cpp_library
cpp_unittest = shim.cpp_unittest
Expand All @@ -155,7 +150,6 @@ export_file = shim.export_file
get_visibility = shim.get_visibility
http_file = shim.http_file
http_archive = shim.http_archive
is_facebook = shim.is_facebook
do_not_use_repo_cfg = shim.do_not_use_repo_cfg
target_utils = shim.target_utils
alias = shim.alias
Expand Down
1 change: 0 additions & 1 deletion antlir/bzl/build_defs_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ shim = struct(
cpp_binary = _cpp_binary,
cpp_library = _cpp_library,
cpp_unittest = _cpp_unittest,
is_facebook = False,
cxx_genrule = _cxx_genrule,
export_file = _export_file,
http_file = _http_file,
Expand Down
13 changes: 13 additions & 0 deletions antlir/bzl/internal_external.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# @oss-disable
is_facebook = False # @oss-enable

def internal_external(*, fb, oss):
if is_facebook:
return fb
else:
return oss
3 changes: 2 additions & 1 deletion antlir/bzl/third_party.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ load("@prelude//:paths.bzl", "paths")
load("//antlir/antlir2/bzl:selects.bzl", "selects")
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load(":build_defs.bzl", "buck_genrule", "internal_external", third_party_shim = "third_party")
load("//antlir/bzl:internal_external.bzl", "internal_external")
load(":build_defs.bzl", "buck_genrule", third_party_shim = "third_party")
load(":third_party.shape.bzl", "dep_t", "script_t")

PREFIX = "/third-party-build"
Expand Down
3 changes: 2 additions & 1 deletion antlir/uidmaps/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@prelude//:paths.bzl", "paths")
load("//antlir/bzl:build_defs.bzl", "alias", "export_file", "internal_external")
load("//antlir/bzl:build_defs.bzl", "alias", "export_file")
load("//antlir/bzl:internal_external.bzl", "internal_external")
# @oss-disable

oncall("antlir")
Expand Down
3 changes: 2 additions & 1 deletion antlir/vm/runtime/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ load("@prelude//:paths.bzl", "paths")
load("//antlir/antlir2/bzl:hoist.bzl", "hoist")
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule", "internal_external")
load("//antlir/bzl:build_defs.bzl", "alias", "buck_genrule")
load("//antlir/bzl:internal_external.bzl", "internal_external")

oncall("antlir")

Expand Down

0 comments on commit 25522ca

Please sign in to comment.