-
Notifications
You must be signed in to change notification settings - Fork 0
Support %bazel_workspace% interpolation in --repo_env. Attempt to sup… #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,7 +137,6 @@ public class CommandEnvironment { | |||||||||||||||||||||||||||||||||||||||||
| private final DelegatingDownloader delegatingDownloader; | ||||||||||||||||||||||||||||||||||||||||||
| private final RemoteAnalysisCachingEventListener remoteAnalysisCachingEventListener; | ||||||||||||||||||||||||||||||||||||||||||
| private final ImmutableList.Builder<IdleTask> idleTasks = ImmutableList.builder(); | ||||||||||||||||||||||||||||||||||||||||||
| private final ResourceManager resourceManager; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private boolean mergedAnalysisAndExecution; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -234,8 +233,7 @@ public void exit(AbruptExitException exception) { | |||||||||||||||||||||||||||||||||||||||||
| CommandExtensionReporter commandExtensionReporter, | ||||||||||||||||||||||||||||||||||||||||||
| int attemptNumber, | ||||||||||||||||||||||||||||||||||||||||||
| @Nullable String buildRequestIdOverride, | ||||||||||||||||||||||||||||||||||||||||||
| ConfigFlagDefinitions configFlagDefinitions, | ||||||||||||||||||||||||||||||||||||||||||
| ResourceManager resourceManager) { | ||||||||||||||||||||||||||||||||||||||||||
| ConfigFlagDefinitions configFlagDefinitions) { | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructor Parameter RemovalThe resourceManager parameter was removed from the constructor but its usage was changed to a singleton access pattern. This creates inconsistent dependency management where some components are injected while others use global state. Standards
|
||||||||||||||||||||||||||||||||||||||||||
| checkArgument(attemptNumber >= 1); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| this.runtime = runtime; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -256,7 +254,6 @@ public void exit(AbruptExitException exception) { | |||||||||||||||||||||||||||||||||||||||||
| this.timestampGranularityMonitor = new TimestampGranularityMonitor(runtime.getClock()); | ||||||||||||||||||||||||||||||||||||||||||
| this.attemptNumber = attemptNumber; | ||||||||||||||||||||||||||||||||||||||||||
| this.configFlagDefinitions = configFlagDefinitions; | ||||||||||||||||||||||||||||||||||||||||||
| this.resourceManager = resourceManager; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Record the command's starting time again, for use by | ||||||||||||||||||||||||||||||||||||||||||
| // TimestampGranularityMonitor.waitForTimestampGranularity(). | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -358,6 +355,9 @@ public void exit(AbruptExitException exception) { | |||||||||||||||||||||||||||||||||||||||||
| value = clientEnv.get(name); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (value != null) { | ||||||||||||||||||||||||||||||||||||||||||
| if (workspace.getWorkspace() != null) { | ||||||||||||||||||||||||||||||||||||||||||
| value = value.replace("%bazel_workspace%", workspace.getWorkspace().getPathString()); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+358
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Path Injection RiskDirect string replacement of %bazel_workspace% with workspace path without validation creates path injection vulnerability. Malicious repository rules could exploit this to manipulate paths and potentially access files outside intended boundaries. This could lead to unauthorized file access or path traversal attacks. Commitable Suggestion
Suggested change
Standards
Comment on lines
+358
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Workspace CheckThe workspace null check protects against NPE, but there's no handling for the case when workspace is null. Without fallback behavior, repository rules using %bazel_workspace% will receive uninterpolated values, causing potential runtime failures. Commitable Suggestion
Suggested change
Standards
Comment on lines
+358
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String Replacement LogicString replacement is performed unconditionally without checking if the placeholder exists in the value. This could lead to unnecessary string operations for every environment variable, impacting performance with large environment sets. Standards
|
||||||||||||||||||||||||||||||||||||||||||
| repoEnv.put(name, value); | ||||||||||||||||||||||||||||||||||||||||||
| repoEnvFromOptions.put(name, value); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -715,7 +715,7 @@ public WorkspaceInfoFromDiff getWorkspaceInfoFromDiff() { | |||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public ResourceManager getLocalResourceManager() { | ||||||||||||||||||||||||||||||||||||||||||
| return resourceManager; | ||||||||||||||||||||||||||||||||||||||||||
| return ResourceManager.instance(); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
717
to
+718
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ResourceManager Reference ChangeMethod implementation changed from returning stored resourceManager field to ResourceManager.instance(). This changes from instance-specific to global singleton access pattern, potentially affecting resource isolation and reliability in multi-environment scenarios. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resource Manager ReferenceThe constructor parameter resourceManager was removed but the getLocalResourceManager method now returns a global singleton instead of the instance-specific reference. This changes the logical behavior from using a command-specific resource manager to a global one, potentially affecting resource management isolation. Standards
|
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -880,6 +880,49 @@ EOF | |||||||||
| || fail "Expected unrelated action to not be rerun" | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function test_repo_env_workspace_interpolation() { | ||||||||||
| setup_starlark_repository | ||||||||||
|
|
||||||||||
| cat > test.bzl <<'EOF' | ||||||||||
| def _impl(ctx): | ||||||||||
| result = ctx.execute(["my_tool"]) | ||||||||||
| if result.return_code != 0: | ||||||||||
| fail("my_tool failed ({}, PATH = {}): {}".format(result.return_code, ctx.os.environ["PATH"], result.stderr)) | ||||||||||
|
Comment on lines
+888
to
+890
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider including the actual PATH variable in the error message for better debugging:
Suggested change
|
||||||||||
| ctx.file("out.txt", result.stdout) | ||||||||||
| ctx.file("BUILD", 'exports_files(["out.txt"])') | ||||||||||
|
|
||||||||||
| repo = repository_rule( | ||||||||||
| implementation = _impl, | ||||||||||
| ) | ||||||||||
| EOF | ||||||||||
| cat > BUILD <<'EOF' | ||||||||||
| genrule( | ||||||||||
| name = "repoenv", | ||||||||||
| outs = ["repoenv.txt"], | ||||||||||
| srcs = ["@foo//:out.txt"], | ||||||||||
| cmd = "cp $< $@", | ||||||||||
| ) | ||||||||||
| EOF | ||||||||||
| if "$is_windows"; then | ||||||||||
| local repo_env_path="%bazel_workspace%/repo_tools;$PATH" | ||||||||||
| else | ||||||||||
| local repo_env_path="%bazel_workspace%/repo_tools:$PATH" | ||||||||||
| fi | ||||||||||
| cat > .bazelrc <<EOF | ||||||||||
| common --repo_env=PATH="$repo_env_path" | ||||||||||
| EOF | ||||||||||
|
|
||||||||||
| mkdir -p repo_tools | ||||||||||
| cat > repo_tools/my_tool.bat <<'EOF' | ||||||||||
| echo Hello from my_tool | ||||||||||
| EOF | ||||||||||
| cp repo_tools/my_tool.bat repo_tools/my_tool | ||||||||||
| chmod +x repo_tools/my_tool | ||||||||||
|
|
||||||||||
| bazel build //:repoenv &> $TEST_log || fail "Failed to build" | ||||||||||
| assert_contains "Hello from my_tool" `bazel info bazel-bin 2>/dev/null`/repoenv.txt | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function test_repo_env_inverse() { | ||||||||||
| # This test makes sure that a repository rule that has no dependencies on | ||||||||||
| # environment variables does _not_ get refetched when --repo_env changes. | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary Field Removal
The resourceManager field was removed but its usage pattern was changed to a singleton access. This creates an inconsistent pattern where some dependencies are injected while others use global state, reducing maintainability.
Standards