From ae433913e5db58a851a722f321b648a169518714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Nagy?= Date: Tue, 16 Jul 2024 05:08:09 -0700 Subject: [PATCH] Inject correct mode flagfile Reviewed By: JakobDegen Differential Revision: D59679509 fbshipit-source-id: 191b7204a1e1207288b95a38591f20295524f9db --- tests/check_dependencies_test.bzl | 5 ++++- tests/e2e_util/buck_workspace.py | 12 +++++++----- .../e2e_util/test_bxl_check_dependencies_template.py | 12 +++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/check_dependencies_test.bzl b/tests/check_dependencies_test.bzl index 3d5eabf28db7..01bb7da6f14d 100644 --- a/tests/check_dependencies_test.bzl +++ b/tests/check_dependencies_test.bzl @@ -17,6 +17,7 @@ def check_dependencies_test( allowlist_patterns = None, blocklist_patterns = None, expect_failure_msg = None, + env = None, **kwargs): """ Creates a test target from a buck2 bxl script. BXL script must use "test" as entry @@ -29,12 +30,14 @@ def check_dependencies_test( allowlist_patterns: a regex of patterns that should be allowed in transitive deps of the target blocklist_patterns: a regex of patterns that should be blocked in transitive deps of the target expect_failure_msg: the test is expected to fail with this message regex + env: additional environment variables to pass to the checking script """ bxl_main = "fbcode//buck2/tests/check_dependencies_test.bxl:test" allowlist_patterns = ",".join(allowlist_patterns) if allowlist_patterns else "" blocklist_patterns = ",".join(blocklist_patterns) if blocklist_patterns else "" if not (expect_failure_msg == None or len(expect_failure_msg) > 0): fail("Expected failure message can only be None or non-empty string") + buck2_e2e_test( contacts = contacts, name = name, @@ -45,7 +48,7 @@ def check_dependencies_test( "BXL_MAIN": bxl_main, "EXPECT_FAILURE_MSG": expect_failure_msg or "", "TARGET": target, - }, + } | (env or {}), # fbcode_macros uses tags instead of labels tags = ["check_dependencies_test"], test_with_compiled_buck2 = False, diff --git a/tests/e2e_util/buck_workspace.py b/tests/e2e_util/buck_workspace.py index 8e9ccd6d60a7..a5d8ebc1cb93 100644 --- a/tests/e2e_util/buck_workspace.py +++ b/tests/e2e_util/buck_workspace.py @@ -401,22 +401,24 @@ def is_deployed_buck2() -> bool: return os.environ.get("TEST_EXECUTABLE") == "buck2" -def get_mode_from_platform(mode="dev", prefix=True) -> str: - if mode not in ("dev", "opt"): +def get_mode_from_platform( + mode="dev", prefix=True, skip_validation_i_know_what_im_doing=False +) -> str: + if not skip_validation_i_know_what_im_doing and (mode not in ("dev", "opt")): raise Exception(f"Invalid mode: {mode}") def modefile_basename(): if sys.platform == "darwin": - if mode == "dev": + if mode.startswith("dev"): return "mac" else: return "opt-mac" elif sys.platform == "win32": - if mode == "dev": + if mode.startswith("dev"): return "win" else: return "opt-win" - if mode == "dev": + if mode.startswith("dev"): return "dev" else: return "opt" diff --git a/tests/e2e_util/test_bxl_check_dependencies_template.py b/tests/e2e_util/test_bxl_check_dependencies_template.py index c9437ce7e146..b07ac37a8639 100644 --- a/tests/e2e_util/test_bxl_check_dependencies_template.py +++ b/tests/e2e_util/test_bxl_check_dependencies_template.py @@ -8,7 +8,7 @@ import os from buck2.tests.e2e_util.asserts import expect_failure -from buck2.tests.e2e_util.buck_workspace import buck_test +from buck2.tests.e2e_util.buck_workspace import buck_test, get_mode_from_platform # This is just a template test case for `check_dependencies_test` to use buck2's e2e test framework. @@ -28,8 +28,18 @@ async def test_check_dependencies_bxl(buck) -> None: allowlist = process_list_arg(is_allowlist=True) blocklist = process_list_arg(is_allowlist=False) expect_failure_msg = os.environ["EXPECT_FAILURE_MSG"] + + fbcode_build_mode = os.environ.get("CHECK_DEPENDENCIES_TEST_FBCODE_BUILD_MODE") + if fbcode_build_mode: + mode_argfile = get_mode_from_platform( + fbcode_build_mode, skip_validation_i_know_what_im_doing=True + ) + else: + mode_argfile = get_mode_from_platform() + bxl_call = buck.bxl( os.environ["BXL_MAIN"], + mode_argfile, "--", "--target", os.environ["TARGET"],