-
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.
Extract Bazel registry creation into a SkyFunction
This gets rid of an ad-hoc cache maintained in `RegistryFactoryImpl` and prepares for making registries aware of hashes stored in the lockfile. Work towards #20369 Closes #22040. PiperOrigin-RevId: 626307340 Change-Id: I34b428553f7169c72ed7dddd2fe3ea5e6dca2a97
- Loading branch information
Showing
24 changed files
with
198 additions
and
115 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
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.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,57 @@ | ||
// 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.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.net.URISyntaxException; | ||
import javax.annotation.Nullable; | ||
|
||
/** A simple SkyFunction that creates a {@link Registry} with a given URL. */ | ||
public class RegistryFunction implements SkyFunction { | ||
private final RegistryFactory registryFactory; | ||
|
||
public RegistryFunction(RegistryFactory registryFactory) { | ||
this.registryFactory = registryFactory; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public SkyValue compute(SkyKey skyKey, Environment env) | ||
throws InterruptedException, RegistryException { | ||
RegistryKey key = (RegistryKey) skyKey.argument(); | ||
try { | ||
return registryFactory.createRegistry(key.getUrl()); | ||
} catch (URISyntaxException e) { | ||
throw new RegistryException( | ||
ExternalDepsException.withCauseAndMessage( | ||
FailureDetails.ExternalDeps.Code.INVALID_REGISTRY_URL, | ||
e, | ||
"Invalid registry URL: %s", | ||
key.getUrl())); | ||
} | ||
} | ||
|
||
static final class RegistryException extends SkyFunctionException { | ||
|
||
RegistryException(ExternalDepsException cause) { | ||
super(cause, Transience.TRANSIENT); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryKey.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,46 @@ | ||
// 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.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 RegistryFunction}. */ | ||
@AutoCodec | ||
@AutoValue | ||
abstract class RegistryKey implements SkyKey { | ||
private static final SkyKeyInterner<RegistryKey> interner = SkyKey.newInterner(); | ||
|
||
abstract String getUrl(); | ||
|
||
@AutoCodec.Instantiator | ||
static RegistryKey create(String url) { | ||
return interner.intern(new AutoValue_RegistryKey(url)); | ||
} | ||
|
||
@Override | ||
public SkyFunctionName functionName() { | ||
return SkyFunctions.REGISTRY; | ||
} | ||
|
||
@Override | ||
public SkyKeyInterner<RegistryKey> 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.