@@ -41,13 +41,15 @@ public static BazelDepGraphValue create(
41
41
ImmutableMap <RepositoryName , ModuleKey > canonicalRepoNameLookup ,
42
42
ImmutableList <AbridgedModule > abridgedModules ,
43
43
ImmutableTable <ModuleExtensionId , ModuleKey , ModuleExtensionUsage > extensionUsagesTable ,
44
- ImmutableMap <ModuleExtensionId , String > extensionUniqueNames ) {
44
+ ImmutableMap <ModuleExtensionId , String > extensionUniqueNames ,
45
+ ImmutableTable <ModuleExtensionId , String , RepositoryName > repoOverrides ) {
45
46
return new AutoValue_BazelDepGraphValue (
46
47
depGraph ,
47
48
ImmutableBiMap .copyOf (canonicalRepoNameLookup ),
48
49
abridgedModules ,
49
50
extensionUsagesTable ,
50
- extensionUniqueNames );
51
+ extensionUniqueNames ,
52
+ repoOverrides );
51
53
}
52
54
53
55
public static BazelDepGraphValue createEmptyDepGraph () {
@@ -71,7 +73,8 @@ public static BazelDepGraphValue createEmptyDepGraph() {
71
73
canonicalRepoNameLookup ,
72
74
ImmutableList .of (),
73
75
ImmutableTable .of (),
74
- ImmutableMap .of ());
76
+ ImmutableMap .of (),
77
+ ImmutableTable .of ());
75
78
}
76
79
77
80
/**
@@ -103,27 +106,54 @@ public static BazelDepGraphValue createEmptyDepGraph() {
103
106
*/
104
107
public abstract ImmutableMap <ModuleExtensionId , String > getExtensionUniqueNames ();
105
108
109
+ /**
110
+ * For each module extension, a mapping from the name of the repo exported by the extension to the
111
+ * canonical name of the repo that should override it (if any).
112
+ */
113
+ public abstract ImmutableTable <ModuleExtensionId , String , RepositoryName > getRepoOverrides ();
114
+
106
115
/**
107
116
* Returns the full {@link RepositoryMapping} for the given module, including repos from Bazel
108
117
* module deps and module extensions.
109
118
*/
110
119
public final RepositoryMapping getFullRepoMapping (ModuleKey key ) {
120
+ return getRepositoryMapping (
121
+ key ,
122
+ getDepGraph (),
123
+ getExtensionUsagesTable (),
124
+ getExtensionUniqueNames (),
125
+ getCanonicalRepoNameLookup (),
126
+ getRepoOverrides ());
127
+ }
128
+
129
+ static RepositoryMapping getRepositoryMapping (
130
+ ModuleKey key ,
131
+ ImmutableMap <ModuleKey , Module > depGraph ,
132
+ ImmutableTable <ModuleExtensionId , ModuleKey , ModuleExtensionUsage > extensionUsagesTable ,
133
+ ImmutableMap <ModuleExtensionId , String > extensionUniqueNames ,
134
+ ImmutableBiMap <RepositoryName , ModuleKey > canonicalRepoNameLookup ,
135
+ ImmutableTable <ModuleExtensionId , String , RepositoryName > repoOverrides ) {
111
136
ImmutableMap .Builder <String , RepositoryName > mapping = ImmutableMap .builder ();
112
137
for (Map .Entry <ModuleExtensionId , ModuleExtensionUsage > extIdAndUsage :
113
- getExtensionUsagesTable () .column (key ).entrySet ()) {
138
+ extensionUsagesTable .column (key ).entrySet ()) {
114
139
ModuleExtensionId extensionId = extIdAndUsage .getKey ();
115
140
ModuleExtensionUsage usage = extIdAndUsage .getValue ();
116
- String repoNamePrefix = getExtensionUniqueNames () .get (extensionId ) + "+" ;
141
+ String repoNamePrefix = extensionUniqueNames .get (extensionId ) + "+" ;
117
142
for (ModuleExtensionUsage .Proxy proxy : usage .getProxies ()) {
118
143
for (Map .Entry <String , String > entry : proxy .getImports ().entrySet ()) {
119
- String canonicalRepoName = repoNamePrefix + entry .getValue ();
120
- mapping .put (entry .getKey (), RepositoryName .createUnvalidated (canonicalRepoName ));
144
+ RepositoryName defaultCanonicalRepoName =
145
+ RepositoryName .createUnvalidated (repoNamePrefix + entry .getValue ());
146
+ mapping .put (
147
+ entry .getKey (),
148
+ repoOverrides
149
+ .row (extensionId )
150
+ .getOrDefault (entry .getValue (), defaultCanonicalRepoName ));
121
151
}
122
152
}
123
153
}
124
- return getDepGraph ()
154
+ return depGraph
125
155
.get (key )
126
- .getRepoMappingWithBazelDepsOnly (getCanonicalRepoNameLookup () .inverse ())
156
+ .getRepoMappingWithBazelDepsOnly (canonicalRepoNameLookup .inverse ())
127
157
.withAdditionalMappings (mapping .buildOrThrow ());
128
158
}
129
159
}
0 commit comments