1
1
package edu .wpi .first .toolchain ;
2
2
3
+ import java .util .ArrayList ;
3
4
import java .util .HashMap ;
4
5
import java .util .List ;
5
6
import java .util .Map ;
28
29
import org .gradle .nativeplatform .toolchain .NativeToolChain ;
29
30
import org .gradle .nativeplatform .toolchain .NativeToolChainRegistry ;
30
31
import org .gradle .nativeplatform .toolchain .internal .NativeToolChainRegistryInternal ;
32
+ import org .gradle .nativeplatform .toolchain .internal .clang .ClangToolChain ;
33
+ import org .gradle .nativeplatform .toolchain .internal .gcc .GccToolChain ;
31
34
import org .gradle .platform .base .BinaryContainer ;
32
35
import org .gradle .platform .base .BinarySpec ;
33
36
import org .gradle .platform .base .BinaryTasks ;
@@ -42,17 +45,31 @@ public class ToolchainRules extends RuleSource {
42
45
private static final ETLogger logger = ETLoggerFactory .INSTANCE .create ("ToolchainRules" );
43
46
44
47
@ Finalize
45
- void addClangArm (NativeToolChainRegistryInternal toolChainRegistry ) {
48
+ void addClangArm (NativeToolChainRegistryInternal toolChainRegistry , ExtensionContainer extContainer ) {
49
+ // To work around sometimes GCC and Clang getting picked up on Windows, remove
50
+ // them completely
51
+ List <Object > toRemove = new ArrayList <>();
46
52
toolChainRegistry .all (n -> {
53
+ if (OperatingSystem .current ().equals (OperatingSystem .WINDOWS )) {
54
+ if (n instanceof Gcc && n .getName ().equals (GccToolChain .DEFAULT_NAME )) {
55
+ toRemove .add (n );
56
+ }
57
+ if (n instanceof Clang && n .getName ().equals (ClangToolChain .DEFAULT_NAME )) {
58
+ toRemove .add (n );
59
+ }
60
+ }
61
+
47
62
if (n instanceof Gcc && OperatingSystem .current ().equals (OperatingSystem .LINUX )) {
48
- Gcc gcc = (Gcc )n ;
49
- if ((NativePlatforms .desktop .equals (NativePlatforms .linuxarm32 ) || NativePlatforms .desktop .equals (NativePlatforms .linuxarm64 )) && gcc .getName ().equals ("gcc" )) {
63
+ Gcc gcc = (Gcc ) n ;
64
+ if ((NativePlatforms .desktop .equals (NativePlatforms .linuxarm32 )
65
+ || NativePlatforms .desktop .equals (NativePlatforms .linuxarm64 ))
66
+ && gcc .getName ().equals (GccToolChain .DEFAULT_NAME )) {
50
67
gcc .setTargets ();
51
68
gcc .target (NativePlatforms .desktop );
52
69
}
53
70
}
54
71
if (n instanceof Clang && OperatingSystem .current ().equals (OperatingSystem .MAC_OS )) {
55
- Clang gcc = (Clang )n ;
72
+ Clang gcc = (Clang ) n ;
56
73
gcc .setTargets ();
57
74
gcc .target ("osxuniversal" , gccToolChain -> {
58
75
Action <List <String >> m64args = new Action <List <String >>() {
@@ -73,6 +90,13 @@ public void execute(List<String> args) {
73
90
});
74
91
}
75
92
});
93
+
94
+ final ToolchainExtension ext = extContainer .getByType (ToolchainExtension .class );
95
+ if (ext .isRemoveInvalidWindowsToolchains ()) {
96
+ for (var t : toRemove ) {
97
+ toolChainRegistry .remove (t );
98
+ }
99
+ }
76
100
}
77
101
78
102
@ Defaults
@@ -113,7 +137,6 @@ void addDefaultToolchains(NativeToolChainRegistryInternal toolChainRegistry,
113
137
});
114
138
});
115
139
116
-
117
140
}
118
141
119
142
@ Mutate
@@ -181,7 +204,8 @@ void addDefaultPlatforms(final ExtensionContainer extContainer, final PlatformCo
181
204
}
182
205
183
206
@ Validate
184
- void checkEnabledToolchains (final BinaryContainer binaries , final NativeToolChainRegistry toolChains , final ExtensionContainer extContainer ) {
207
+ void checkEnabledToolchains (final BinaryContainer binaries , final NativeToolChainRegistry toolChains ,
208
+ final ExtensionContainer extContainer ) {
185
209
final ToolchainExtension ext = extContainer .getByType (ToolchainExtension .class );
186
210
// Map of platform to toolchains
187
211
Map <String , GccExtension > gccToolChains = new HashMap <>();
@@ -205,8 +229,9 @@ void checkEnabledToolchains(final BinaryContainer binaries, final NativeToolChai
205
229
}
206
230
}
207
231
208
- public static OrderedStripTask configureOrderedStrip (AbstractLinkTask link , GccExtension gcc , NativeBinarySpec binary ) {
209
- ExtensionAware linkExt = (ExtensionAware )link ;
232
+ public static OrderedStripTask configureOrderedStrip (AbstractLinkTask link , GccExtension gcc ,
233
+ NativeBinarySpec binary ) {
234
+ ExtensionAware linkExt = (ExtensionAware ) link ;
210
235
OrderedStripTask strip = linkExt .getExtensions ().findByType (OrderedStripTask .class );
211
236
if (strip == null ) {
212
237
Project project = link .getProject ();
@@ -216,14 +241,16 @@ public static OrderedStripTask configureOrderedStrip(AbstractLinkTask link, GccE
216
241
return null ;
217
242
}
218
243
219
- strip = linkExt .getExtensions ().create ("orderedStrip" , OrderedStripTask .class , tcExt , binary , link , gcc , project );
244
+ strip = linkExt .getExtensions ().create ("orderedStrip" , OrderedStripTask .class , tcExt , binary , link , gcc ,
245
+ project );
220
246
link .doLast (strip );
221
247
}
222
248
return strip ;
223
249
}
224
250
225
251
@ BinaryTasks
226
- void createNativeStripTasks (final ModelMap <Task > tasks , NativeBinarySpec binary , final ExtensionContainer extContainer ) {
252
+ void createNativeStripTasks (final ModelMap <Task > tasks , NativeBinarySpec binary ,
253
+ final ExtensionContainer extContainer ) {
227
254
final ToolchainExtension ext = extContainer .getByType (ToolchainExtension .class );
228
255
NativeToolChain tc = binary .getToolChain ();
229
256
GccExtension gccExt = ext .getGccExtensionMap ().getOrDefault (tc , null );
0 commit comments