-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement RemoteDownloader w/
--experimental_remote_downloader
This is the Bazel client implementation of bazelbuild/proposals#160. It allows downloading of external dependencies to be delegated to a remote service. TODOs: - [x] Once bazelbuild/remote-apis#112 is merged, the vendored copy of `bazelbuild/remote-apis` should be updated. I've used a [WIP] placeholder for now. - [x] If the general approach looks reasonable then I'll add tests. Currently I've been testing with an in-house implementation of the downloader server. R: @buchgr @dslomov CC: @EricBurnett @sstriker @ulfjack Closes #10622. PiperOrigin-RevId: 300116716
- Loading branch information
1 parent
80a2d7c
commit 586eabf
Showing
9 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../java/com/google/devtools/build/lib/bazel/repository/downloader/DelegatingDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.bazel.repository.downloader; | ||
|
||
import com.google.common.base.Optional; | ||
import com.google.devtools.build.lib.events.ExtendedEventHandler; | ||
import com.google.devtools.build.lib.vfs.Path; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* A {@link Downloader} that delegates to another Downloader. Primarily useful for mutable | ||
* dependency injection. | ||
*/ | ||
public class DelegatingDownloader implements Downloader { | ||
private final Downloader defaultDelegate; | ||
@Nullable private Downloader delegate; | ||
|
||
public DelegatingDownloader(Downloader defaultDelegate) { | ||
this.defaultDelegate = defaultDelegate; | ||
} | ||
|
||
/** | ||
* Sets the {@link Downloader} to delegate to. If setDelegate(null) is called, the default | ||
* delegate passed to the constructor will be used. | ||
*/ | ||
public void setDelegate(@Nullable Downloader delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void download( | ||
List<URL> urls, | ||
Map<URI, Map<String, String>> authHeaders, | ||
Optional<Checksum> checksum, | ||
String canonicalId, | ||
Path destination, | ||
ExtendedEventHandler eventHandler, | ||
Map<String, String> clientEnv) | ||
throws IOException, InterruptedException { | ||
Downloader downloader = defaultDelegate; | ||
if (delegate != null) { | ||
downloader = delegate; | ||
} | ||
downloader.download( | ||
urls, authHeaders, checksum, canonicalId, destination, eventHandler, clientEnv); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.