-
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.
`create`, `getName`, and `getVersion` are just wrappers (around `new`, `name`, and `version`, respectively) now that ModuleKey is a record. PiperOrigin-RevId: 676559957 Change-Id: I381ee94cfb7cbb377e62e75a05bf950ea794b625
- Loading branch information
1 parent
ce64b1a
commit f301171
Showing
20 changed files
with
69 additions
and
92 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,16 @@ | |
import com.google.common.collect.ImmutableMap; | ||
import com.google.devtools.build.lib.cmdline.RepositoryName; | ||
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; | ||
import com.google.errorprone.annotations.InlineMe; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** A module name, version pair that identifies a module in the external dependency graph. */ | ||
/** | ||
* A module name, version pair that identifies a node in the external dependency graph. | ||
* | ||
* @param name The name of the module. Must be empty for the root module. | ||
* @param version The version of the module. Must be empty iff the module has a {@link | ||
* NonRegistryOverride}. | ||
*/ | ||
@AutoCodec | ||
public record ModuleKey(String name, Version version) { | ||
|
||
|
@@ -54,39 +59,18 @@ public record ModuleKey(String name, Version version) { | |
public static final ModuleKey ROOT = new ModuleKey("", Version.EMPTY); | ||
|
||
public static final Comparator<ModuleKey> LEXICOGRAPHIC_COMPARATOR = | ||
Comparator.comparing(ModuleKey::getName).thenComparing(ModuleKey::getVersion); | ||
|
||
/** | ||
* @deprecated Call the constructor directly. | ||
*/ | ||
@InlineMe( | ||
replacement = "new ModuleKey(name, version)", | ||
imports = "com.google.devtools.build.lib.bazel.bzlmod.ModuleKey") | ||
@Deprecated | ||
public static ModuleKey create(String name, Version version) { | ||
return new ModuleKey(name, version); | ||
} | ||
|
||
/** The name of the module. Must be empty for the root module. */ | ||
public String getName() { | ||
return name(); | ||
} | ||
|
||
/** The version of the module. Must be empty iff the module has a {@link NonRegistryOverride}. */ | ||
public Version getVersion() { | ||
return version(); | ||
} | ||
Comparator.comparing(ModuleKey::name).thenComparing(ModuleKey::version); | ||
|
||
@Override | ||
public final String toString() { | ||
public String toString() { | ||
if (this.equals(ROOT)) { | ||
return "<root>"; | ||
} | ||
return getName() + "@" + (getVersion().isEmpty() ? "_" : getVersion().toString()); | ||
return name + "@" + (version.isEmpty() ? "_" : version.toString()); | ||
} | ||
|
||
/** Returns a string such as "root module" or "module [email protected]" for display purposes. */ | ||
public final String toDisplayString() { | ||
public String toDisplayString() { | ||
if (this.equals(ROOT)) { | ||
return "root module"; | ||
} | ||
|
@@ -113,8 +97,8 @@ public RepositoryName getCanonicalRepoNameWithoutVersion() { | |
} | ||
|
||
private RepositoryName getCanonicalRepoName(boolean includeVersion) { | ||
if (WELL_KNOWN_MODULES.containsKey(getName())) { | ||
return WELL_KNOWN_MODULES.get(getName()); | ||
if (WELL_KNOWN_MODULES.containsKey(name)) { | ||
return WELL_KNOWN_MODULES.get(name); | ||
} | ||
if (ROOT.equals(this)) { | ||
return RepositoryName.MAIN; | ||
|
@@ -123,8 +107,8 @@ private RepositoryName getCanonicalRepoName(boolean includeVersion) { | |
if (includeVersion) { | ||
// getVersion().isEmpty() is true only for modules with non-registry overrides, which enforce | ||
// that there is a single version of the module in the dep graph. | ||
Preconditions.checkState(!getVersion().isEmpty()); | ||
suffix = getVersion().toString(); | ||
Preconditions.checkState(!version.isEmpty()); | ||
suffix = version.toString(); | ||
} else { | ||
// This results in canonical repository names such as `rules_foo+` for the module `rules_foo`. | ||
// This particular format is chosen since: | ||
|
@@ -142,7 +126,7 @@ private RepositoryName getCanonicalRepoName(boolean includeVersion) { | |
// rarely used. | ||
suffix = ""; | ||
} | ||
return RepositoryName.createUnvalidated(String.format("%s+%s", getName(), suffix)); | ||
return RepositoryName.createUnvalidated(String.format("%s+%s", name, suffix)); | ||
} | ||
|
||
public static ModuleKey fromString(String s) throws Version.ParseException { | ||
|
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.