Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--noexperimental_check_external_repository_files doesn't work with Bzlmod repo #23241

Closed
meteorcloudy opened this issue Aug 8, 2024 · 1 comment
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@meteorcloudy
Copy link
Member

Description of the bug:

test_check_external_files() {
setup_remote
bazel build @remote//:g >& "$TEST_log" || fail "Expected build to succeed"
echo "broken file" > bazel-main/external/remote/BUILD
# The --noexperimental_check_external_repository_files flag doesn't notice the file is broken
bazel build --noexperimental_check_external_repository_files @remote//:g >& "$TEST_log" || fail "Expected build to succeed"
bazel build @remote//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such target '@@remote//:g'"
}

If we migrate this test case to Bzlmod:

setup_remote() {
  WRKDIR=$(mktemp -d "${TEST_TMPDIR}/testXXXXXX")
  cd "${WRKDIR}"

  mkdir remote
  (
    cd remote
    echo 'genrule(name="g", outs=["go"], cmd="echo GO > $@")' > BUILD
  )
  tar cvf remote.tar remote
  rm -rf remote

  mkdir main
  cd main
  cat >> MODULE.bazel <<EOF
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
  name="remote",
  strip_prefix="remote",
  urls=["$(get_extrepourl $WRKDIR)/remote.tar"],
)
EOF
}

test_check_external_files() {
  setup_remote
  bazel build @remote//:g >& "$TEST_log" || fail "Expected build to succeed"

  echo "broken file" > bazel-main/external/+_repo_rules+remote/BUILD
  # The --noexperimental_check_external_repository_files flag doesn't notice the file is broken
  bazel build --noexperimental_check_external_repository_files @remote//:g >& "$TEST_log" || fail "Expected build to succeed"

  bazel build @remote//:g >& "$TEST_log" && fail "Expected build to fail" || true
  expect_log "no such target '@@+_repo_rules+remote//:g'"
}

The test fails with:

ERROR: /usr/local/google/home/pcloudy/.cache/bazel/_bazel_pcloudy/4c5ccabacef1ddac6600d71a1b8bfa58/sandbox/linux-sandbox/2849/execroot/_main/_tmp/6ae13531c753d159158e8eb86f5df1eb/root/120a11317afcb80d507344874cf9f97b/external/+_repo_rules+remote/BUILD:1:8: syntax error at 'file': expected newline

which means --noexperimental_check_external_repository_files doesn't work as expected.

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Change the test as above and run

bazel test //src/test/shell/bazel:check_external_files_test --test_filter test_check_external_files

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@meteorcloudy meteorcloudy added type: bug team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Aug 8, 2024
@meteorcloudy meteorcloudy added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Aug 13, 2024
@Wyverald
Copy link
Member

Huh. I tried the exact thing you wrote, and the test passed for me. Will send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants