@@ -43,13 +43,15 @@ public static BazelDepGraphValue create(
43
43
ImmutableList <AbridgedModule > abridgedModules ,
44
44
ImmutableTable <ModuleExtensionId , ModuleKey , ModuleExtensionUsage > extensionUsagesTable ,
45
45
ImmutableMap <ModuleExtensionId , String > extensionUniqueNames ,
46
+ ImmutableTable <ModuleExtensionId , String , RepositoryName > repoOverrides ,
46
47
char repoNameSeparator ) {
47
48
return new AutoValue_BazelDepGraphValue (
48
49
depGraph ,
49
50
ImmutableBiMap .copyOf (canonicalRepoNameLookup ),
50
51
abridgedModules ,
51
52
extensionUsagesTable ,
52
53
extensionUniqueNames ,
54
+ repoOverrides ,
53
55
repoNameSeparator );
54
56
}
55
57
@@ -75,6 +77,7 @@ public static BazelDepGraphValue createEmptyDepGraph() {
75
77
ImmutableList .of (),
76
78
ImmutableTable .of (),
77
79
ImmutableMap .of (),
80
+ ImmutableTable .of (),
78
81
'+' );
79
82
}
80
83
@@ -107,6 +110,12 @@ public static BazelDepGraphValue createEmptyDepGraph() {
107
110
*/
108
111
public abstract ImmutableMap <ModuleExtensionId , String > getExtensionUniqueNames ();
109
112
113
+ /**
114
+ * For each module extension, a mapping from the name of the repo exported by the extension to the
115
+ * canonical name of the repo that should override it (if any).
116
+ */
117
+ public abstract ImmutableTable <ModuleExtensionId , String , RepositoryName > getRepoOverrides ();
118
+
110
119
/** The character to use to separate the different segments of a canonical repo name. */
111
120
public abstract char getRepoNameSeparator ();
112
121
@@ -115,22 +124,45 @@ public static BazelDepGraphValue createEmptyDepGraph() {
115
124
* module deps and module extensions.
116
125
*/
117
126
public final RepositoryMapping getFullRepoMapping (ModuleKey key ) {
127
+ return getRepositoryMapping (
128
+ key ,
129
+ getDepGraph (),
130
+ getExtensionUsagesTable (),
131
+ getExtensionUniqueNames (),
132
+ getCanonicalRepoNameLookup (),
133
+ getRepoOverrides (),
134
+ getRepoNameSeparator ());
135
+ }
136
+
137
+ static RepositoryMapping getRepositoryMapping (
138
+ ModuleKey key ,
139
+ ImmutableMap <ModuleKey , Module > depGraph ,
140
+ ImmutableTable <ModuleExtensionId , ModuleKey , ModuleExtensionUsage > extensionUsagesTable ,
141
+ ImmutableMap <ModuleExtensionId , String > extensionUniqueNames ,
142
+ ImmutableBiMap <RepositoryName , ModuleKey > canonicalRepoNameLookup ,
143
+ ImmutableTable <ModuleExtensionId , String , RepositoryName > repoOverrides ,
144
+ char repoNameSeparator ) {
118
145
ImmutableMap .Builder <String , RepositoryName > mapping = ImmutableMap .builder ();
119
146
for (Map .Entry <ModuleExtensionId , ModuleExtensionUsage > extIdAndUsage :
120
- getExtensionUsagesTable () .column (key ).entrySet ()) {
147
+ extensionUsagesTable .column (key ).entrySet ()) {
121
148
ModuleExtensionId extensionId = extIdAndUsage .getKey ();
122
149
ModuleExtensionUsage usage = extIdAndUsage .getValue ();
123
- String repoNamePrefix = getExtensionUniqueNames () .get (extensionId ) + getRepoNameSeparator () ;
150
+ String repoNamePrefix = extensionUniqueNames .get (extensionId ) + repoNameSeparator ;
124
151
for (ModuleExtensionUsage .Proxy proxy : usage .getProxies ()) {
125
152
for (Map .Entry <String , String > entry : proxy .getImports ().entrySet ()) {
126
- String canonicalRepoName = repoNamePrefix + entry .getValue ();
127
- mapping .put (entry .getKey (), RepositoryName .createUnvalidated (canonicalRepoName ));
153
+ RepositoryName defaultCanonicalRepoName =
154
+ RepositoryName .createUnvalidated (repoNamePrefix + entry .getValue ());
155
+ mapping .put (
156
+ entry .getKey (),
157
+ repoOverrides
158
+ .row (extensionId )
159
+ .getOrDefault (entry .getValue (), defaultCanonicalRepoName ));
128
160
}
129
161
}
130
162
}
131
- return getDepGraph ()
163
+ return depGraph
132
164
.get (key )
133
- .getRepoMappingWithBazelDepsOnly (getCanonicalRepoNameLookup () .inverse ())
165
+ .getRepoMappingWithBazelDepsOnly (canonicalRepoNameLookup .inverse ())
134
166
.withAdditionalMappings (mapping .buildOrThrow ());
135
167
}
136
168
}
0 commit comments