This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Buck will cowardly refuse to download files at build time by default, and we've not publicized the configuration setting that allows a user to override this. Instead, we introduce "buck fetch", which downloads all remote resources by executing the `BuildRule`. In a follow up, I'll explore the option to cache downloadeds in order to survive someone calling "buck clean". However, since we tell users that "buck clean" is a bug, I consider this low priority. Test Plan: buck test --all
- Loading branch information
Showing
18 changed files
with
485 additions
and
23 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
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,133 @@ | ||
/* | ||
* Copyright 2015-present Facebook, Inc. | ||
* | ||
* 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.facebook.buck.cli; | ||
|
||
import com.facebook.buck.command.Build; | ||
import com.facebook.buck.file.Downloader; | ||
import com.facebook.buck.file.HttpDownloader; | ||
import com.facebook.buck.file.RemoteFileDescription; | ||
import com.facebook.buck.json.BuildFileParseException; | ||
import com.facebook.buck.model.BuildTarget; | ||
import com.facebook.buck.model.BuildTargetException; | ||
import com.facebook.buck.rules.ActionGraph; | ||
import com.facebook.buck.rules.BuildEvent; | ||
import com.facebook.buck.rules.Description; | ||
import com.facebook.buck.rules.TargetGraph; | ||
import com.facebook.buck.rules.TargetGraphToActionGraph; | ||
import com.facebook.buck.step.TargetDevice; | ||
import com.google.common.base.Optional; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
import java.io.IOException; | ||
import java.net.Proxy; | ||
|
||
public class FetchCommand extends AbstractCommandRunner<BuildCommandOptions> { | ||
|
||
public FetchCommand(CommandRunnerParams params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
BuildCommandOptions createOptions(BuckConfig buckConfig) { | ||
return new BuildCommandOptions(buckConfig); | ||
} | ||
|
||
@Override | ||
int runCommandWithOptionsInternal(BuildCommandOptions options) | ||
throws IOException, InterruptedException { | ||
|
||
ImmutableSet<BuildTarget> buildTargets = | ||
getBuildTargets(options.getArgumentsFormattedAsBuildTargets()); | ||
|
||
if (buildTargets.isEmpty()) { | ||
console.printBuildFailure("Must specify at least one build target to fetch."); | ||
return 1; | ||
} | ||
|
||
// Post the build started event, setting it to the Parser recorded start time if appropriate. | ||
if (getParser().getParseStartTime().isPresent()) { | ||
getBuckEventBus().post( | ||
BuildEvent.started(buildTargets), | ||
getParser().getParseStartTime().get()); | ||
} else { | ||
getBuckEventBus().post(BuildEvent.started(buildTargets)); | ||
} | ||
|
||
FetchTargetNodeToBuildRuleTransformer ruleGenerator = createFetchTransformer(options); | ||
TargetGraphToActionGraph transformer = new TargetGraphToActionGraph( | ||
getBuckEventBus(), | ||
ruleGenerator); | ||
|
||
ActionGraph actionGraph; | ||
try { | ||
TargetGraph targetGraph = getParser().buildTargetGraphForBuildTargets( | ||
buildTargets, | ||
options.getDefaultIncludes(), | ||
getBuckEventBus(), | ||
console, | ||
environment, | ||
options.getEnableProfiling()); | ||
|
||
actionGraph = transformer.apply(targetGraph); | ||
buildTargets = ruleGenerator.getDownloadableTargets(); | ||
} catch (BuildTargetException | BuildFileParseException e) { | ||
console.printBuildFailureWithoutStacktrace(e); | ||
return 1; | ||
} | ||
|
||
int exitCode; | ||
try (Build build = options.createBuild( | ||
options.getBuckConfig(), | ||
actionGraph, | ||
getProjectFilesystem(), | ||
getAndroidDirectoryResolver(), | ||
getBuildEngine(), | ||
getArtifactCache(), | ||
console, | ||
getBuckEventBus(), | ||
Optional.<TargetDevice>absent(), | ||
getCommandRunnerParams().getPlatform(), | ||
getCommandRunnerParams().getEnvironment(), | ||
getCommandRunnerParams().getObjectMapper(), | ||
getCommandRunnerParams().getClock())) { | ||
exitCode = build.executeAndPrintFailuresToConsole( | ||
buildTargets, | ||
options.isKeepGoing(), | ||
console, | ||
options.getPathToBuildReport()); | ||
} | ||
|
||
getBuckEventBus().post(BuildEvent.finished(buildTargets, exitCode)); | ||
|
||
return exitCode; | ||
} | ||
|
||
private FetchTargetNodeToBuildRuleTransformer createFetchTransformer( | ||
BuildCommandOptions options) { | ||
Optional<String> defaultMavenRepo = options.getBuckConfig().getValue("download", "maven_repo"); | ||
Downloader downloader = new HttpDownloader(Optional.<Proxy>absent(), defaultMavenRepo); | ||
Description<?> description = new RemoteFileDescription(downloader); | ||
return new FetchTargetNodeToBuildRuleTransformer( | ||
ImmutableSet.<Description<?>>of(description) | ||
); | ||
} | ||
|
||
@Override | ||
String getUsageIntro() { | ||
return "fetch remote resources"; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/com/facebook/buck/cli/FetchTargetNodeToBuildRuleTransformer.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,66 @@ | ||
/* | ||
* Copyright 2015-present Facebook, Inc. | ||
* | ||
* 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.facebook.buck.cli; | ||
|
||
import com.facebook.buck.model.BuildTarget; | ||
import com.facebook.buck.parser.NoSuchBuildTargetException; | ||
import com.facebook.buck.rules.BuildRule; | ||
import com.facebook.buck.rules.BuildRuleResolver; | ||
import com.facebook.buck.rules.Description; | ||
import com.facebook.buck.rules.TargetGraph; | ||
import com.facebook.buck.rules.TargetNode; | ||
import com.facebook.buck.rules.TargetNodeToBuildRuleTransformer; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
class FetchTargetNodeToBuildRuleTransformer implements TargetNodeToBuildRuleTransformer { | ||
|
||
private final ImmutableSet<Description<?>> descriptions; | ||
// TODO(user): Allow the TargetToActionGraph to be stateless. | ||
private final ImmutableSet.Builder<BuildTarget> downloadableTargets; | ||
private final BuildTargetNodeToBuildRuleTransformer delegate; | ||
|
||
public FetchTargetNodeToBuildRuleTransformer( | ||
ImmutableSet<Description<?>> descriptions) { | ||
this.descriptions = descriptions; | ||
|
||
this.downloadableTargets = ImmutableSet.builder(); | ||
this.delegate = new BuildTargetNodeToBuildRuleTransformer(); | ||
} | ||
|
||
@Override | ||
public <T> BuildRule transform( | ||
TargetGraph targetGraph, | ||
BuildRuleResolver ruleResolver, | ||
TargetNode<T> targetNode) throws NoSuchBuildTargetException { | ||
TargetNode<?> node = substituteTargetNodeIfNecessary(targetNode); | ||
return delegate.transform(targetGraph, ruleResolver, node); | ||
} | ||
|
||
public ImmutableSet<BuildTarget> getDownloadableTargets() { | ||
return downloadableTargets.build(); | ||
} | ||
|
||
private TargetNode<?> substituteTargetNodeIfNecessary(TargetNode<?> node) { | ||
for (Description<?> description : descriptions) { | ||
if (node.getDescription().getBuildRuleType().equals(description.getBuildRuleType())) { | ||
downloadableTargets.add(node.getBuildTarget()); | ||
return node.amend(description); | ||
} | ||
} | ||
return node; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2015-present Facebook, Inc. | ||
* | ||
* 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.facebook.buck.file; | ||
|
||
import com.facebook.buck.event.BuckEventBus; | ||
import com.facebook.buck.util.HumanReadableException; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Path; | ||
|
||
public class ExplodingDownloader implements Downloader { | ||
@Override | ||
public void fetch(BuckEventBus eventBus, URI uri, Path output) throws IOException { | ||
throw new HumanReadableException( | ||
"Downloading files at runtime is disabled, please run 'buck fetch' before your build"); | ||
} | ||
} |
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.