-
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.
bzlmod: add BzlmodRepoRuleFunction and friends
- BzlmodRepoRuleHelper: calculates the RepoSpec for a given repository. The actual calculation will be implemented in following changes. - BzlmodRepoRuleFunction: Take a given repository name, look up its RepoSpec via BzlmodRepoRuleHelper, and then create a repository rule out of it. The result will be used in RepositoryDelegatorFunction. Related: #13316 RELNOTES: None. PiperOrigin-RevId: 382745079
- Loading branch information
1 parent
8325885
commit 348b532
Showing
22 changed files
with
793 additions
and
12 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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleCreator.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 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.EventHandler; | ||
import com.google.devtools.build.lib.packages.Package; | ||
import com.google.devtools.build.lib.packages.Rule; | ||
import com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException; | ||
import java.util.Map; | ||
import net.starlark.java.eval.StarlarkSemantics; | ||
|
||
/** | ||
* An interface for {@link RepositoryRuleFunction} to create a repository rule instance with given | ||
* parameters. | ||
*/ | ||
public interface BzlmodRepoRuleCreator { | ||
Rule createRule( | ||
Package.Builder packageBuilder, | ||
StarlarkSemantics semantics, | ||
Map<String, Object> kwargs, | ||
EventHandler handler) | ||
throws InterruptedException, InvalidRuleException; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleHelper.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,23 @@ | ||
// 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.skyframe.SkyFunction.Environment; | ||
import java.util.Optional; | ||
|
||
/** A helper to get {@link RepoSpec} for Bzlmod generated repositories. */ | ||
public interface BzlmodRepoRuleHelper { | ||
Optional<RepoSpec> getRepoSpec(Environment env, String repositoryName); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleHelperImpl.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,28 @@ | ||
// 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.skyframe.SkyFunction.Environment; | ||
import java.util.Optional; | ||
|
||
/** A helper class to get {@link RepoSpec} for Bzlmod generated repositories. */ | ||
public final class BzlmodRepoRuleHelperImpl implements BzlmodRepoRuleHelper { | ||
|
||
@Override | ||
public Optional<RepoSpec> getRepoSpec(Environment env, String repositoryName) { | ||
// TODO(pcloudy): Implement calculating RepoSpec. | ||
return Optional.empty(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleValue.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,78 @@ | ||
// 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.common.collect.Interner; | ||
import com.google.devtools.build.lib.concurrent.BlazeInterners; | ||
import com.google.devtools.build.lib.packages.Rule; | ||
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; | ||
import com.google.devtools.build.skyframe.AbstractSkyKey; | ||
import com.google.devtools.build.skyframe.SkyFunctionName; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
|
||
/** The result of {@link BzlmodRepoRuleFunction}, holding a repository rule instance. */ | ||
public class BzlmodRepoRuleValue implements SkyValue { | ||
public static final SkyFunctionName BZLMOD_REPO_RULE = | ||
SkyFunctionName.createHermetic("BZLMOD_REPO_RULE"); | ||
|
||
private final Rule rule; | ||
|
||
public BzlmodRepoRuleValue(Rule rule) { | ||
this.rule = rule; | ||
} | ||
|
||
public Rule getRule() { | ||
return rule; | ||
} | ||
|
||
public static Key key(String repositoryName) { | ||
return Key.create(repositoryName); | ||
} | ||
|
||
/** Represents an unsuccessful repository lookup. */ | ||
public static final class RepoRuleNotFoundValue extends BzlmodRepoRuleValue { | ||
private RepoRuleNotFoundValue() { | ||
super(/* rule= */ null); | ||
} | ||
|
||
@Override | ||
public Rule getRule() { | ||
throw new IllegalStateException(); | ||
} | ||
} | ||
|
||
public static final RepoRuleNotFoundValue REPO_RULE_NOT_FOUND_VALUE = new RepoRuleNotFoundValue(); | ||
|
||
/** Argument for the SkyKey to request a BzlmodRepoRuleValue. */ | ||
@AutoCodec | ||
public static class Key extends AbstractSkyKey<String> { | ||
private static final Interner<Key> interner = BlazeInterners.newWeakInterner(); | ||
|
||
private Key(String arg) { | ||
super(arg); | ||
} | ||
|
||
@AutoCodec.VisibleForSerialization | ||
@AutoCodec.Instantiator | ||
static Key create(String arg) { | ||
return interner.intern(new Key(arg)); | ||
} | ||
|
||
@Override | ||
public SkyFunctionName functionName() { | ||
return BZLMOD_REPO_RULE; | ||
} | ||
} | ||
} |
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
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.