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

Allow ~/home in downloaderConfig of RepositoryOptions #24618

Closed
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 @@ -394,9 +394,8 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
Event.warn(String.format("Error parsing the .netrc file: %s.", e.getMessage())));
}
try {
UrlRewriter rewriter =
UrlRewriter.getDownloaderUrlRewriter(
env.getWorkspace(), repoOptions.downloaderConfig, env.getReporter());
UrlRewriter rewriter = 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 @@ -207,14 +207,15 @@ public class RepositoryOptions extends OptionsBase {
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.REMOTE,
effectTags = {OptionEffectTag.UNKNOWN},
converter = OptionsUtils.PathFragmentConverter.class,
help =
"Specify a file to configure the remote downloader with. This file consists of lines, "
+ "each of which starts with a directive (`allow`, `block` or `rewrite`) followed "
+ "by either a host name (for `allow` and `block`) or two patterns, one to match "
+ "against, and one to use as a substitute URL, with back-references starting from "
+ "`$1`. It is possible for multiple `rewrite` directives for the same URL to be "
+ "give, and in this case multiple URLs will be returned.")
public String downloaderConfig;
public PathFragment downloaderConfig;

/** See {@link #workerForRepoFetching}. */
public enum WorkerForRepoFetching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -86,11 +87,11 @@ public class UrlRewriter {
* @param reporter Used for logging when URLs are rewritten.
*/
public static UrlRewriter getDownloaderUrlRewriter(
Path workspaceRoot, String configPath, Reporter reporter) throws UrlRewriterParseException {
Path workspaceRoot, @Nullable PathFragment configPath, Reporter reporter) throws UrlRewriterParseException {
Consumer<String> log = str -> reporter.handle(Event.info(str));

// "empty" UrlRewriter shouldn't alter auth headers
if (Strings.isNullOrEmpty(configPath)) {
if (configPath == null || configPath.isEmpty()) {
return new UrlRewriter(log, "", new StringReader(""));
}

Expand All @@ -101,13 +102,13 @@ public static UrlRewriter getDownloaderUrlRewriter(

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

try (InputStream inputStream = actualConfigPath.getInputStream();
Reader inputStreamReader = new InputStreamReader(inputStream);
Reader reader = new BufferedReader(inputStreamReader)) {
return new UrlRewriter(log, configPath, reader);
return new UrlRewriter(log, configPath.getPathString(), reader);
} catch (IOException e) {
throw new UrlRewriterParseException(e.getMessage());
}
Expand Down
Loading