diff --git a/tests/core/build/BUCK b/tests/core/build/BUCK index bc953bbb3e77..a00344dfff2c 100644 --- a/tests/core/build/BUCK +++ b/tests/core/build/BUCK @@ -22,6 +22,12 @@ buck2_e2e_test( serialize_test_cases = False, ) +buck2_e2e_test( + name = "test_build_configured", + srcs = ["test_build_configured.py"], + data_dir = "test_build_configured_data", +) + buck2_e2e_test( name = "test_plugins", srcs = ["test_plugins.py"], diff --git a/tests/core/build/test_build_configured.py b/tests/core/build/test_build_configured.py new file mode 100644 index 000000000000..8529f5d9b0d8 --- /dev/null +++ b/tests/core/build/test_build_configured.py @@ -0,0 +1,80 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under both the MIT license found in the +# LICENSE-MIT file in the root directory of this source tree and the Apache +# License, Version 2.0 found in the LICENSE-APACHE file in the root directory +# of this source tree. + +# pyre-strict + + +import json +import re +import typing + +from buck2.tests.e2e_util.api.buck import Buck +from buck2.tests.e2e_util.asserts import expect_failure +from buck2.tests.e2e_util.buck_workspace import buck_test + + +# Obtain hashes of `` and `` configurations. +async def _obtain_cfg_hashes(buck: Buck) -> typing.Tuple[str, str]: + result = await buck.cquery( + "root//:simple", + "--target-universe", + "root//:universe", + ) + [astrologer, vagabond] = result.stdout.splitlines() + assert astrologer.startswith("root//:simple (#") + assert vagabond.startswith("root//:simple (#") + astrologer_hash = re.sub(r".*#(.*)\)", r"\1", astrologer) + vagabond_hash = re.sub(r".*#(.*)\)", r"\1", vagabond) + assert re.fullmatch("[0-9a-f]{16}", astrologer_hash), astrologer + assert re.fullmatch("[0-9a-f]{16}", vagabond_hash), vagabond + return (astrologer_hash, vagabond_hash) + + +@buck_test() +async def test_build_configured_full_configuration(buck: Buck) -> None: + (astrologer_hash, _) = await _obtain_cfg_hashes(buck) + + result = await buck.build( + f"root//:simple (#{astrologer_hash})", + "--target-universe", + "root//:universe", + ) + out = result.get_build_report().output_for_target("root//:simple").read_text() + assert f"$$$root//:simple (#{astrologer_hash})$$$" == out + + +@buck_test() +async def test_build_configured_no_hash(buck: Buck) -> None: + (_, vagabond_hash) = await _obtain_cfg_hashes(buck) + result = await buck.build( + "root//:simple ()", + "--target-universe", + "root//:universe", + ) + out = result.get_build_report().output_for_target("root//:simple").read_text() + assert f"$$$root//:simple (#{vagabond_hash})$$$" == out + + +@buck_test() +async def test_build_configured_wrong_hash(buck: Buck) -> None: + result = await buck.build( + "root//:simple (#0123456789abcdef)", + "--target-universe", + "root//:universe", + ) + # TODO(nga): this should either fail or emit a warning. + assert "root//:simple" not in json.loads(result.stdout)["results"] + + +@buck_test() +async def test_build_configured_no_universe(buck: Buck) -> None: + await expect_failure( + buck.build( + "root//:simple ()", + ), + stderr_regex="Targets with explicit configuration can only be built when the", + ) diff --git a/tests/core/build/test_build_configured_data/.buckconfig b/tests/core/build/test_build_configured_data/.buckconfig new file mode 100644 index 000000000000..09556211287d --- /dev/null +++ b/tests/core/build/test_build_configured_data/.buckconfig @@ -0,0 +1,12 @@ +[cells] + root = . + nano_prelude = nano_prelude + +[cell_aliases] + prelude = nano_prelude + +[external_cells] + nano_prelude = bundled + +[buildfile] + name = TARGETS.fixture diff --git a/tests/core/build/test_build_configured_data/.buckroot b/tests/core/build/test_build_configured_data/.buckroot new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/e2e/build/test_build_configured_data/BUCK.v2 b/tests/core/build/test_build_configured_data/TARGETS.fixture similarity index 66% rename from tests/e2e/build/test_build_configured_data/BUCK.v2 rename to tests/core/build/test_build_configured_data/TARGETS.fixture index bbace7b38e06..abbaa22e060e 100644 --- a/tests/e2e/build/test_build_configured_data/BUCK.v2 +++ b/tests/core/build/test_build_configured_data/TARGETS.fixture @@ -3,10 +3,16 @@ load(":defs.bzl", "simple", "universe") # Write the configuration label to the default output. simple( name = "simple", + default_target_platform = ":default_plat", ) # Build nothing, but depend on two `:simple` targets in different configurations. universe( name = "universe", split_dep = ":simple", + default_target_platform = ":default_plat", +) + +platform( + name = "default_plat", ) diff --git a/tests/e2e/build/test_build_configured_data/defs.bzl b/tests/core/build/test_build_configured_data/defs.bzl similarity index 100% rename from tests/e2e/build/test_build_configured_data/defs.bzl rename to tests/core/build/test_build_configured_data/defs.bzl diff --git a/tests/e2e/build/BUCK b/tests/e2e/build/BUCK index c9f36a8928d0..bec869a4977e 100644 --- a/tests/e2e/build/BUCK +++ b/tests/e2e/build/BUCK @@ -25,11 +25,6 @@ buck2_e2e_test( serialize_test_cases = False, ) -buck2_e2e_test( - name = "test_build_configured", - srcs = ["test_build_configured.py"], -) - buck2_e2e_test( name = "test_build_inplace", srcs = ["test_build_inplace.py"], diff --git a/tests/e2e/build/test_build_configured.py b/tests/e2e/build/test_build_configured.py deleted file mode 100644 index ffc599898f60..000000000000 --- a/tests/e2e/build/test_build_configured.py +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under both the MIT license found in the -# LICENSE-MIT file in the root directory of this source tree and the Apache -# License, Version 2.0 found in the LICENSE-APACHE file in the root directory -# of this source tree. - -# pyre-strict - - -import json -import re -import typing - -from buck2.tests.e2e_util.api.buck import Buck -from buck2.tests.e2e_util.asserts import expect_failure -from buck2.tests.e2e_util.buck_workspace import buck_test - - -# Obtain hashes of `` and `` configurations. -async def _obtain_cfg_hashes(buck: Buck) -> typing.Tuple[str, str]: - result = await buck.cquery( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple", - "--target-universe", - "fbcode//buck2/tests/e2e/build/test_build_configured_data:universe", - ) - [astrologer, vagabond] = result.stdout.splitlines() - assert astrologer.startswith( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#" - ) - assert vagabond.startswith( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#" - ) - astrologer_hash = re.sub(r".*#(.*)\)", r"\1", astrologer) - vagabond_hash = re.sub(r".*#(.*)\)", r"\1", vagabond) - assert re.fullmatch("[0-9a-f]{16}", astrologer_hash), astrologer - assert re.fullmatch("[0-9a-f]{16}", vagabond_hash), vagabond - return (astrologer_hash, vagabond_hash) - - -@buck_test(inplace=True) -async def test_build_configured_full_configuration(buck: Buck) -> None: - (astrologer_hash, _) = await _obtain_cfg_hashes(buck) - - result = await buck.build( - f"fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#{astrologer_hash})", - "--target-universe", - "fbcode//buck2/tests/e2e/build/test_build_configured_data:universe", - ) - out = ( - result.get_build_report() - .output_for_target( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple" - ) - .read_text() - ) - assert ( - f"$$$fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#{astrologer_hash})$$$" - == out - ) - - -@buck_test(inplace=True) -async def test_build_configured_no_hash(buck: Buck) -> None: - (_, vagabond_hash) = await _obtain_cfg_hashes(buck) - result = await buck.build( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple ()", - "--target-universe", - "fbcode//buck2/tests/e2e/build/test_build_configured_data:universe", - ) - out = ( - result.get_build_report() - .output_for_target( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple" - ) - .read_text() - ) - assert ( - f"$$$fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#{vagabond_hash})$$$" - == out - ) - - -@buck_test(inplace=True) -async def test_build_configured_wrong_hash(buck: Buck) -> None: - result = await buck.build( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple (#0123456789abcdef)", - "--target-universe", - "fbcode//buck2/tests/e2e/build/test_build_configured_data:universe", - ) - # TODO(nga): this should either fail or emit a warning. - assert ( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple" - not in json.loads(result.stdout)["results"] - ) - - -@buck_test(inplace=True) -async def test_build_configured_no_universe(buck: Buck) -> None: - await expect_failure( - buck.build( - "fbcode//buck2/tests/e2e/build/test_build_configured_data:simple ()", - ), - stderr_regex="Targets with explicit configuration can only be built when the", - )