forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Computing `RepoSpec`s for all selected Bazel modules is on the critical path for the computation of the main repository mapping and thus benefits from parallelized downloads. On my machine, this change has the following effect on `bazel build //src:bazel-dev --enable_bzlmod --nobuild`: ``` before compute main repo mapping: 8s 127ms after compute main repo mapping: 4s 226ms ``` Closes bazelbuild#19294. PiperOrigin-RevId: 559819452 Change-Id: Ieef957fcfe402c909d2863ba4a4ca3540781a56d
- Loading branch information
1 parent
32fa5c2
commit 8a68310
Showing
16 changed files
with
215 additions
and
55 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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecFunction.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,73 @@ | ||
// Copyright 2021 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.devtools.build.lib.profiler.Profiler; | ||
import com.google.devtools.build.lib.profiler.ProfilerTask; | ||
import com.google.devtools.build.lib.profiler.SilentCloseable; | ||
import com.google.devtools.build.lib.server.FailureDetails; | ||
import com.google.devtools.build.skyframe.SkyFunction; | ||
import com.google.devtools.build.skyframe.SkyFunctionException; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* A simple SkyFunction that computes a {@link RepoSpec} for the given {@link InterimModule} by | ||
* fetching required information from its {@link Registry}. | ||
*/ | ||
public class RepoSpecFunction implements SkyFunction { | ||
private final RegistryFactory registryFactory; | ||
|
||
public RepoSpecFunction(RegistryFactory registryFactory) { | ||
this.registryFactory = registryFactory; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public SkyValue compute(SkyKey skyKey, Environment env) | ||
throws InterruptedException, RepoSpecException { | ||
RepoSpecKey key = (RepoSpecKey) skyKey.argument(); | ||
try (SilentCloseable c = | ||
Profiler.instance() | ||
.profile(ProfilerTask.BZLMOD, () -> "compute repo spec: " + key.getModuleKey())) { | ||
return registryFactory | ||
.getRegistryWithUrl(key.getRegistryUrl()) | ||
.getRepoSpec( | ||
key.getModuleKey(), key.getModuleKey().getCanonicalRepoName(), env.getListener()); | ||
} catch (IOException e) { | ||
throw new RepoSpecException( | ||
ExternalDepsException.withCauseAndMessage( | ||
FailureDetails.ExternalDeps.Code.ERROR_ACCESSING_REGISTRY, | ||
e, | ||
"Unable to get module repo spec for %s from registry", | ||
key.getModuleKey())); | ||
} catch (URISyntaxException e) { | ||
// This should never happen since we obtain the registry URL from an already constructed | ||
// registry. | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
static final class RepoSpecException extends SkyFunctionException { | ||
|
||
RepoSpecException(ExternalDepsException cause) { | ||
super(cause, Transience.TRANSIENT); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecKey.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,55 @@ | ||
// Copyright 2021 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.common.base.Preconditions; | ||
import com.google.devtools.build.lib.skyframe.SkyFunctions; | ||
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; | ||
import com.google.devtools.build.skyframe.SkyFunctionName; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
|
||
/** The key for {@link RepoSpecFunction}. */ | ||
@AutoCodec | ||
@AutoValue | ||
abstract class RepoSpecKey implements SkyKey { | ||
private static final SkyKeyInterner<RepoSpecKey> interner = SkyKey.newInterner(); | ||
|
||
static RepoSpecKey of(InterimModule module) { | ||
Preconditions.checkNotNull( | ||
module.getRegistry(), "module must not have a non-registry override"); | ||
return create(module.getKey(), module.getRegistry().getUrl()); | ||
} | ||
|
||
abstract ModuleKey getModuleKey(); | ||
|
||
abstract String getRegistryUrl(); | ||
|
||
@AutoCodec.Instantiator | ||
static RepoSpecKey create(ModuleKey moduleKey, String registryUrl) { | ||
return interner.intern(new AutoValue_RepoSpecKey(moduleKey, registryUrl)); | ||
} | ||
|
||
@Override | ||
public SkyFunctionName functionName() { | ||
return SkyFunctions.REPO_SPEC; | ||
} | ||
|
||
@Override | ||
public SkyKeyInterner<RepoSpecKey> getSkyKeyInterner() { | ||
return interner; | ||
} | ||
} |
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.