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

Be more precise about where to read the URL rewriter config from #22770

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
}
try {
UrlRewriter rewriter =
UrlRewriter.getDownloaderUrlRewriter(repoOptions.downloaderConfig, env.getReporter());
UrlRewriter.getDownloaderUrlRewriter(env.getWorkspace(), repoOptions.downloaderConfig, env.getReporter());
downloadManager.setUrlRewriter(rewriter);
} catch (UrlRewriterParseException e) {
// It's important that the build stops ASAP, because this config file may be required for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -85,7 +84,7 @@ public class UrlRewriter {
* @param configPath Path to the config file to use. May be null.
* @param reporter Used for logging when URLs are rewritten.
*/
public static UrlRewriter getDownloaderUrlRewriter(String configPath, Reporter reporter)
public static UrlRewriter getDownloaderUrlRewriter(Path workspaceRoot, String configPath, Reporter reporter)
throws UrlRewriterParseException {
Consumer<String> log = str -> reporter.handle(Event.info(str));

Expand All @@ -94,7 +93,16 @@ public static UrlRewriter getDownloaderUrlRewriter(String configPath, Reporter r
return new UrlRewriter(log, "", new StringReader(""));
}

try (BufferedReader reader = Files.newBufferedReader(Paths.get(configPath))) {
// There have been reports (eg. https://github.com/bazelbuild/bazel/issues/22104) that
// there are occasional errors when `configFile` can't be found, and when this happens
// investigation suggests that the current working directory isn't the workspace root.
Path actualConfigPath = workspaceRoot.getRelative(configPath);

if (!actualConfigPath.exists()) {
throw new UrlRewriterParseException(String.format("Unable to find downloader config file %s", configPath));
}

try (BufferedReader reader = Files.newBufferedReader(actualConfigPath.getPathFile().toPath())) {
return new UrlRewriter(log, configPath, reader);
} catch (IOException e) {
throw new UrlRewriterParseException(e.getMessage());
Expand Down
Loading