Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update fetch command to fetch everything
- Added fetch option --all - Update fetch command logic to handle the new option PiperOrigin-RevId: 567413867 Change-Id: Idb9cd41b0e8fba8b29e2ff669af4096d22f0eea3
- Loading branch information
Showing
12 changed files
with
391 additions
and
13 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
85 changes: 85 additions & 0 deletions
85
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllFunction.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,85 @@ | ||
// Copyright 2023 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.bzlmod; | ||
|
||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.devtools.build.lib.cmdline.RepositoryName; | ||
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; | ||
import com.google.devtools.build.skyframe.SkyFunction; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import com.google.devtools.build.skyframe.SkyframeLookupResult; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Void function designed to gather and fetch all the repositories without returning any specific | ||
* result (empty value is returned). | ||
*/ | ||
public class BazelFetchAllFunction implements SkyFunction { | ||
|
||
@Override | ||
@Nullable | ||
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { | ||
|
||
// Collect all the repos we want to fetch here | ||
List<RepositoryName> reposToFetch = new ArrayList<>(); | ||
|
||
// 1. Run resolution and collect the dependency graph repos | ||
BazelDepGraphValue depGraphValue = (BazelDepGraphValue) env.getValue(BazelDepGraphValue.KEY); | ||
if (depGraphValue == null) { | ||
return null; | ||
} | ||
reposToFetch.addAll(depGraphValue.getCanonicalRepoNameLookup().keySet()); | ||
|
||
// 2. Run every extension found in the modules | ||
ImmutableSet<ModuleExtensionId> extensionIds = | ||
depGraphValue.getExtensionUsagesTable().rowKeySet(); | ||
ImmutableSet<SkyKey> singleEvalKeys = | ||
extensionIds.stream().map(SingleExtensionEvalValue::key).collect(toImmutableSet()); | ||
SkyframeLookupResult singleEvalValues = env.getValuesAndExceptions(singleEvalKeys); | ||
|
||
// 3. For each extension, collect its generated repos | ||
for (SkyKey singleEvalKey : singleEvalKeys) { | ||
SingleExtensionEvalValue singleEvalValue = | ||
(SingleExtensionEvalValue) singleEvalValues.get(singleEvalKey); | ||
if (singleEvalValue == null) { | ||
return null; | ||
} | ||
reposToFetch.addAll(singleEvalValue.getCanonicalRepoNameToInternalNames().keySet()); | ||
} | ||
|
||
// 4. Fetch all the collected repos excluding root | ||
ImmutableSet<SkyKey> repoDelegatorKeys = | ||
reposToFetch.stream() | ||
.filter(repoName -> !repoName.isMain()) | ||
.map(RepositoryDirectoryValue::key) | ||
.collect(toImmutableSet()); | ||
SkyframeLookupResult repoDirValues = env.getValuesAndExceptions(repoDelegatorKeys); | ||
for (SkyKey repoDelegatorKey : repoDelegatorKeys) { | ||
RepositoryDirectoryValue repoDirValue = | ||
(RepositoryDirectoryValue) repoDirValues.get(repoDelegatorKey); | ||
if (repoDirValue == null) { | ||
return null; | ||
} | ||
} | ||
|
||
return BazelFetchAllValue.create(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllValue.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,35 @@ | ||
// Copyright 2023 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.bzlmod; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.devtools.build.lib.skyframe.SkyFunctions; | ||
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
|
||
/** | ||
* Empty result of running Bazel fetch all dependencies, to indicate that all repos have been | ||
* fetched successfully. | ||
*/ | ||
@AutoValue | ||
public abstract class BazelFetchAllValue implements SkyValue { | ||
@SerializationConstant public static final SkyKey KEY = () -> SkyFunctions.BAZEL_FETCH_ALL; | ||
|
||
public static BazelFetchAllValue create() { | ||
return new AutoValue_BazelFetchAllValue(); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/google/devtools/build/lib/bazel/commands/FetchOptions.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,38 @@ | ||
// Copyright 2023 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.commands; | ||
|
||
import com.google.devtools.common.options.Option; | ||
import com.google.devtools.common.options.OptionDocumentationCategory; | ||
import com.google.devtools.common.options.OptionEffectTag; | ||
import com.google.devtools.common.options.OptionsBase; | ||
|
||
/** Defines the options specific to Bazel's sync command */ | ||
public class FetchOptions extends OptionsBase { | ||
@Option( | ||
name = "all", | ||
defaultValue = "false", | ||
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY, | ||
effectTags = {OptionEffectTag.CHANGES_INPUTS}, | ||
help = | ||
"Fetches all external repositories necessary for building any target or repository. Only" | ||
+ " works when --enable_bzlmod is on.") | ||
public boolean all; | ||
|
||
/*TODO(salmasamy) add more options: | ||
* repo: to fetch a specific repo | ||
* force: to force fetch even if a repo exists | ||
* configure: to fetch only the repos marked as configure | ||
*/ | ||
} |
4 changes: 2 additions & 2 deletions
4
src/main/java/com/google/devtools/build/lib/bazel/commands/fetch.txt
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
Usage: %{product} %{command} [<option> ...] <targets> | ||
Usage: %{product} %{command} [<option> ...] --all or <targets> | ||
|
||
Fetches all external dependencies for the targets given. | ||
Fetches all external dependencies, or fetch dependencies only for given targets | ||
|
||
%{options} |
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.