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

Ensure repository names don't start with ~ #16564

Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Oct 26, 2022

By ensuring that repository names do not start with ~, runfiles paths are certain not to begin with tildes, which means that they don't need to be shell escaped.

Prevents #16560 (comment)

@fmeum fmeum force-pushed the one-does-not-simply-start-with-a-tilde branch 3 times, most recently from f943c03 to a66e356 Compare October 26, 2022 16:08
@fmeum fmeum changed the title WIP: Ensure repository names don't start with ~ Ensure repository names don't start with ~ Oct 26, 2022
@fmeum fmeum marked this pull request as ready for review October 26, 2022 16:40
@ShreeM01 ShreeM01 added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Oct 26, 2022
} else {
nonEmptyRepoPart = repoName;
}
String bestName = nonEmptyRepoPart + "~" + id.getExtensionName();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Maybe we also check if id.getExtensionName() is empty? It probably should be done early: https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java;l=407

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not strictly necessary since a path ending but not starting with a tilde should not require escaping.

Wouldn't an empty extensionName already lead to an error since it needs to name a Starlark export in the file and these cannot have empty names?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that make sense.

// not start with a tilde.
String repoName = id.getBzlFileLabel().getRepository().getName();
String nonEmptyRepoPart;
if (repoName.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe id.getBzlFileLabel().getRepository().isMain() is a bit more clear? Since other Bazel modules should have a non-empty repo name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

@fmeum fmeum force-pushed the one-does-not-simply-start-with-a-tilde branch from a66e356 to 445de0b Compare October 27, 2022 08:08
} else {
nonEmptyRepoPart = repoName;
}
String bestName = nonEmptyRepoPart + "~" + id.getExtensionName();
Copy link
Member

Choose a reason for hiding this comment

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

Ah, that make sense.

@Wyverald Wyverald added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Oct 27, 2022
@fmeum
Copy link
Collaborator Author

fmeum commented Oct 27, 2022

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Oct 27, 2022
@Wyverald
Copy link
Member

@bazel-io fork 6.0.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Oct 27, 2022
@fmeum fmeum deleted the one-does-not-simply-start-with-a-tilde branch October 27, 2022 13:05
@sgowroji sgowroji removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Oct 27, 2022
fmeum added a commit to fmeum/bazel that referenced this pull request Oct 27, 2022
By ensuring that repository names do not start with `~`, runfiles paths are certain not to begin with tildes, which means that they don't need to be shell escaped.

Prevents bazelbuild#16560 (comment)

Closes bazelbuild#16564.

PiperOrigin-RevId: 484232215
Change-Id: Ie70940aa709f6c7a886564189a3579780731dca6
ShreeM01 pushed a commit that referenced this pull request Oct 27, 2022
By ensuring that repository names do not start with `~`, runfiles paths are certain not to begin with tildes, which means that they don't need to be shell escaped.

Prevents #16560 (comment)

Closes #16564.

PiperOrigin-RevId: 484232215
Change-Id: Ie70940aa709f6c7a886564189a3579780731dca6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants