Skip to content

Commit

Permalink
Inject correct mode flagfile
Browse files Browse the repository at this point in the history
Reviewed By: JakobDegen

Differential Revision: D59679509

fbshipit-source-id: 191b7204a1e1207288b95a38591f20295524f9db
  • Loading branch information
abesto authored and facebook-github-bot committed Jul 16, 2024
1 parent ddae6f9 commit ae43391
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tests/check_dependencies_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions tests/e2e_util/buck_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion tests/e2e_util/test_bxl_check_dependencies_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"],
Expand Down

0 comments on commit ae43391

Please sign in to comment.