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

Add --experimental_repository_disable_download to allow users disable download for external repos #12940

Closed
wants to merge 3 commits into from

Conversation

coeuvre
Copy link
Member

@coeuvre coeuvre commented Feb 1, 2021

This PR adds a flag --experimental_repository_disable_download which when set will prevent Bazel from downloading external repositories. However, local_repository, new_local_repository and external repositories already downloaded in the repository cache would still work.

@coeuvre coeuvre requested a review from philwo February 1, 2021 08:42
@google-cla google-cla bot added the cla: yes label Feb 1, 2021
@coeuvre
Copy link
Member Author

coeuvre commented Feb 1, 2021

cc @lberki

@meteorcloudy
Copy link
Member

meteorcloudy commented Feb 1, 2021

Thanks! Maybe add a simple test for this?

@lberki
Copy link
Contributor

lberki commented Feb 1, 2021

@jin , it looks like this is enough, isn't it?

@jin
Copy link
Member

jin commented Feb 1, 2021

For repo rules, this covers the repository_ctx.download calls, but not arbitrary repository_ctx.execute commands that can make network calls.

@@ -194,6 +199,10 @@ public Path download(
}
}

if (disableDownload) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that this works because we don't provide any built-in repositories anymore that do downloading and we delegate everything to Starlark code instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for repo rule which uses repository_ctx.download.

@@ -194,6 +199,10 @@ public Path download(
}
}

if (disableDownload) {
throw new IOException(String.format("Failed to download repo %s: download is disabled.", repo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test cases to verify at least the following cases (starlark_repository_test looks like a logical location, but maybe there is something better):

  1. When the flag is set, downloads don't work
  2. When the flag is set, repositories in distdir are still accessible
  3. Maybe: when the flag is unset, downloads work (although that case is probably covered by existing tests?)

I'd love if this flag to also affected git_repository and the like, but I guess that's not possible unless we put repository download actions into a sandbox which is probably too big a change for now :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases added.

git_repository uses repository_ctx.execute under the hood so it's impossible for this change to have affect on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think there is a lot we can do about that :(

@lberki
Copy link
Contributor

lberki commented Feb 1, 2021

@jin , can't disagree with that, but that's not any different from regular actions doing network calls, is it?

@jin
Copy link
Member

jin commented Feb 1, 2021

Indeed, and that's the third and final area where Bazel can make user-initiated network calls today AFAICT. Let's get this in to cover this case.

@lberki
Copy link
Contributor

lberki commented Feb 1, 2021

Yeah. This change alone is probably good enough and if not, we can think further. It's definitely necessary, but probably also necessary and sufficient.

EOF

bazel build --experimental_repository_disable_download //:it > "${TEST_log}" 2>&1 \
&& fail "Expected failure" || :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does || : do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the first command failed (exit code is not 0), we need to use : (which is a symbol for true) to set the exit code to 0. Just a trick to ignore the errors. (Copied from other test cases in the same file)

@@ -194,6 +199,10 @@ public Path download(
}
}

if (disableDownload) {
throw new IOException(String.format("Failed to download repo %s: download is disabled.", repo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think there is a lot we can do about that :(

echo 'Hello World' > x/file.txt
tar cvf x.tar x
sha256=$(sha256sum x.tar | head -c 64)
serve_file x.tar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this uses distdir, why do you need this serve_file call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@bazel-io bazel-io closed this in 9804ba5 Feb 3, 2021
philwo pushed a commit that referenced this pull request Mar 15, 2021
… download for external repos

This PR adds a flag `--experimental_repository_disable_download` which when set will prevent Bazel from downloading external repositories.  However, `local_repository`, `new_local_repository` and external repositories already downloaded in the repository cache  would still work.

Closes #12940.

PiperOrigin-RevId: 355332927
philwo pushed a commit that referenced this pull request Mar 15, 2021
… download for external repos

This PR adds a flag `--experimental_repository_disable_download` which when set will prevent Bazel from downloading external repositories.  However, `local_repository`, `new_local_repository` and external repositories already downloaded in the repository cache  would still work.

Closes #12940.

PiperOrigin-RevId: 355332927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants