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.
Extract yanked versions into a SkyFunction
Ensures that yanked version information is only downloaded once per module name, which reduces the number of files fetched during module resolution. On my machine, this reduces `bazel mod deps` runtime on Bazel itself by ~15%. This also prepares for storing yanked version information in the lockfile. Work towards bazelbuild#20369 Closes bazelbuild#21909. PiperOrigin-RevId: 625617556 Change-Id: Ie4184def3b868470f93d584bbbbd7f704e1e9a82
- Loading branch information
Showing
16 changed files
with
200 additions
and
62 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
68 changes: 68 additions & 0 deletions
68
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsFunction.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,68 @@ | ||
// 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.events.Event; | ||
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.skyframe.SkyFunction; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.Optional; | ||
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 YankedVersionsFunction implements SkyFunction { | ||
private final RegistryFactory registryFactory; | ||
|
||
public YankedVersionsFunction(RegistryFactory registryFactory) { | ||
this.registryFactory = registryFactory; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { | ||
var key = (YankedVersionsValue.Key) skyKey.argument(); | ||
try (SilentCloseable c = | ||
Profiler.instance() | ||
.profile( | ||
ProfilerTask.BZLMOD, () -> "getting yanked versions: " + key.getModuleName())) { | ||
return YankedVersionsValue.create( | ||
registryFactory | ||
.getRegistryWithUrl(key.getRegistryUrl()) | ||
.getYankedVersions(key.getModuleName(), env.getListener())); | ||
} catch (IOException e) { | ||
env.getListener() | ||
.handle( | ||
Event.warn( | ||
String.format( | ||
"Could not read metadata file for module %s: %s", key, e.getMessage()))); | ||
// This is failing open: If we can't read the metadata file, we allow yanked modules to be | ||
// fetched. | ||
return YankedVersionsValue.create(Optional.empty()); | ||
} catch (URISyntaxException e) { | ||
// This should never happen since we obtain the registry URL from an already constructed | ||
// registry. | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsValue.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,61 @@ | ||
// 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.collect.ImmutableMap; | ||
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; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import java.util.Optional; | ||
|
||
/** A class holding information about the versions of a particular module that have been yanked. */ | ||
@AutoValue | ||
public abstract class YankedVersionsValue implements SkyValue { | ||
|
||
public abstract Optional<ImmutableMap<Version, String>> yankedVersions(); | ||
|
||
public static YankedVersionsValue create(Optional<ImmutableMap<Version, String>> yankedVersions) { | ||
return new AutoValue_YankedVersionsValue(yankedVersions); | ||
} | ||
|
||
/** The key for {@link YankedVersionsFunction}. */ | ||
@AutoCodec | ||
@AutoValue | ||
abstract static class Key implements SkyKey { | ||
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner(); | ||
|
||
abstract String getModuleName(); | ||
|
||
abstract String getRegistryUrl(); | ||
|
||
@AutoCodec.Instantiator | ||
static Key create(String moduleName, String registryUrl) { | ||
return interner.intern(new AutoValue_YankedVersionsValue_Key(moduleName, registryUrl)); | ||
} | ||
|
||
@Override | ||
public SkyFunctionName functionName() { | ||
return SkyFunctions.YANKED_VERSIONS; | ||
} | ||
|
||
@Override | ||
public SkyKeyInterner<Key> 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
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.