Skip to content

Commit d7a64d6

Browse files
authored
Update to gradle 8.11, fix deprecation warnings (#227)
* Update to gradle 8.11, fix deprecation warnings * Fix diff
1 parent f5f1051 commit d7a64d6

18 files changed

+150
-69
lines changed

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/NativePlatforms.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.ByteArrayOutputStream;
44

5-
import org.gradle.api.Project;
65
import org.gradle.internal.os.OperatingSystem;
6+
import org.gradle.process.ExecOperations;
77

88
public class NativePlatforms {
99
public static final String desktop = desktopOS() + desktopArch();
@@ -34,7 +34,7 @@ public static String desktopArchDirect() {
3434
return (arch.equals("amd64") || arch.equals("x86_64")) ? x64arch : x86arch;
3535
}
3636

37-
public static String desktopPlatformArch(Project project) {
37+
public static String desktopPlatformArch(ExecOperations operations) {
3838
if (OperatingSystem.current().isWindows()) {
3939
String arch = System.getenv("PROCESSOR_ARCHITECTURE");
4040
String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");
@@ -43,7 +43,7 @@ public static String desktopPlatformArch(Project project) {
4343
String desktop = desktopArchDirect();
4444
if (desktop.equals("x86-64")) {
4545
ByteArrayOutputStream os = new ByteArrayOutputStream();
46-
project.exec(spec -> {
46+
operations.exec(spec -> {
4747
spec.commandLine("sysctl", "-in", "sysctl.proc_translated");
4848
spec.setStandardOutput(os);
4949
spec.setIgnoreExitValue(true);

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/OrderedStripTask.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import javax.inject.Inject;
88

99
import org.gradle.api.Action;
10-
import org.gradle.api.Project;
1110
import org.gradle.api.Task;
1211
import org.gradle.nativeplatform.NativeBinarySpec;
1312
import org.gradle.nativeplatform.tasks.AbstractLinkTask;
13+
import org.gradle.process.ExecOperations;
1414

1515
import edu.wpi.first.deployutils.log.ETLogger;
1616
import edu.wpi.first.deployutils.log.ETLoggerFactory;
@@ -21,7 +21,7 @@ public class OrderedStripTask implements Action<Task> {
2121
public final NativeBinarySpec binary;
2222
public final AbstractLinkTask linkTask;
2323
public final GccExtension gcc;
24-
public final Project project;
24+
public final ExecOperations operations;
2525
private boolean performStripAll = false;
2626
private boolean performDebugStrip = false;
2727

@@ -43,11 +43,11 @@ public void setPerformDebugStrip(boolean stripDebug) {
4343
}
4444

4545
@Inject
46-
public OrderedStripTask(ToolchainExtension tcExt, NativeBinarySpec binary, AbstractLinkTask linkTask, GccExtension gcc, Project project) {
46+
public OrderedStripTask(ToolchainExtension tcExt, NativeBinarySpec binary, AbstractLinkTask linkTask, GccExtension gcc, ExecOperations operations) {
4747
this.tcExt = tcExt;
4848
this.binary = binary;
4949
this.linkTask = linkTask;
50-
this.project = project;
50+
this.operations = operations;
5151
this.gcc = gcc;
5252
}
5353

@@ -79,17 +79,17 @@ public void execute(Task task) {
7979
String objcopy = disc.tool("objcopy").get().toString();
8080
String strip = disc.tool("strip").get().toString();
8181

82-
project.exec((ex) -> {
82+
operations.exec((ex) -> {
8383
ex.commandLine(objcopy, "--only-keep-debug", mainFileStr, debugFile);
8484
});
85-
project.exec((ex) -> {
85+
operations.exec((ex) -> {
8686
ex.commandLine(strip, "-g", mainFileStr);
8787
});
88-
project.exec((ex) -> {
88+
operations.exec((ex) -> {
8989
ex.commandLine(objcopy, "--add-gnu-debuglink=" + debugFile, mainFileStr);
9090
});
9191
if (performStripAll) {
92-
project.exec((ex) -> {
92+
operations.exec((ex) -> {
9393
ex.commandLine(strip, "--strip-all", "--discard-all", mainFileStr);
9494
});
9595
}

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/ToolchainDiscoverer.java

+31-16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.gradle.nativeplatform.toolchain.internal.metadata.CompilerMetaDataProvider;
2525
import org.gradle.nativeplatform.toolchain.internal.metadata.CompilerMetaDataProviderFactory;
2626
import org.gradle.platform.base.internal.toolchain.SearchResult;
27+
import org.gradle.process.ExecOperations;
2728
import org.gradle.process.ExecSpec;
2829
import org.gradle.util.internal.VersionNumber;
2930

@@ -36,19 +37,24 @@ public abstract class ToolchainDiscoverer implements Named {
3637
private final Function<String, String> composer;
3738
private final ToolchainDescriptorBase descriptor;
3839

39-
public static ToolchainDiscoverer createDiscoverer(String name, ToolchainDescriptorBase descriptor, Provider<File> rootDir, Function<String, String> composer, Project project) {
40+
public static ToolchainDiscoverer createDiscoverer(String name, ToolchainDescriptorBase descriptor,
41+
Provider<File> rootDir, Function<String, String> composer, Project project) {
4042
return project.getObjects().newInstance(ToolchainDiscoverer.class, name, descriptor, rootDir, composer);
4143
}
4244

43-
public static ToolchainDiscovererProperty createProperty(String name, ToolchainDescriptorBase descriptor, Provider<File> rootDir, Function<String, String> composer, Project project) {
45+
public static ToolchainDiscovererProperty createProperty(String name, ToolchainDescriptorBase descriptor,
46+
Provider<File> rootDir, Function<String, String> composer, Project project) {
4447
ToolchainDiscovererProperty prop = project.getObjects().newInstance(ToolchainDiscovererProperty.class, name);
45-
Provider<ToolchainDiscoverer> disc = project.provider(() -> project.getObjects().newInstance(ToolchainDiscoverer.class, name, descriptor, rootDir, composer));
48+
Provider<ToolchainDiscoverer> disc = project.provider(
49+
() -> project.getObjects().newInstance(ToolchainDiscoverer.class, name, descriptor, rootDir, composer));
4650
prop.getDiscoverers().add(disc);
4751
return prop;
4852
}
4953

5054
@Inject
51-
public ToolchainDiscoverer(String name, ToolchainDescriptorBase descriptor, Provider<File> rootDir, Function<String, String> composer, CompilerMetaDataProviderFactory metaDataProviderFactory, ProviderFactory providers) {
55+
public ToolchainDiscoverer(String name, ToolchainDescriptorBase descriptor, Provider<File> rootDir,
56+
Function<String, String> composer, CompilerMetaDataProviderFactory metaDataProviderFactory,
57+
ProviderFactory providers) {
5258
this.name = name;
5359
this.rootDir = rootDir;
5460
this.composer = composer;
@@ -75,7 +81,8 @@ public boolean exists() {
7581
}
7682

7783
public boolean versionValid() {
78-
if (!exists()) return false;
84+
if (!exists())
85+
return false;
7986

8087
VersionNumber v = metadata(null).get().getVersion();
8188
String versionLo = descriptor.getVersionLow().get();
@@ -200,22 +207,24 @@ public String getName() {
200207
private Optional<GccMetadata> metadata(File file, DiagnosticsVisitor visitor) {
201208
if (file == null || !file.exists())
202209
return Optional.empty();
203-
SearchResult<GccMetadata> searchresult = metadataProvider.getCompilerMetaData(new ArrayList<File>(), compilerSpec -> {
204-
compilerSpec.executable(file);
205-
});
210+
SearchResult<GccMetadata> searchresult = metadataProvider.getCompilerMetaData(new ArrayList<File>(),
211+
compilerSpec -> {
212+
compilerSpec.executable(file);
213+
});
206214
if (visitor != null)
207215
searchresult.explain(visitor);
208216
return Optional.ofNullable(searchresult.getComponent());
209217
}
210218

211-
public static List<File> systemPath(Project project, ToolchainGraphBuildService tce, Function<String, String> composer) {
219+
public static List<File> systemPath(Project project, ToolchainGraphBuildService tce,
220+
Function<String, String> composer, ExecOperations operations) {
212221
String tool = composer == null ? "g++" : composer.apply("gcc");
213222
String whichResult = tce.getWhichResult(tool);
214223
if (whichResult == null) {
215224
ByteArrayOutputStream os = new ByteArrayOutputStream();
216225
ByteArrayOutputStream errStr = new ByteArrayOutputStream();
217226

218-
project.exec((ExecSpec spec) -> {
227+
operations.exec((ExecSpec spec) -> {
219228
spec.commandLine(OperatingSystem.current().isWindows() ? "where.exe" : "which", tool);
220229
spec.setStandardOutput(os);
221230
spec.setErrorOutput(errStr);
@@ -228,18 +237,22 @@ public static List<File> systemPath(Project project, ToolchainGraphBuildService
228237

229238
return Arrays.stream(whichResult.split("\n"))
230239
.map(String::trim)
231-
.filter(((Predicate<String>)String::isEmpty).negate())
232-
.map((String path) -> { return new File(path).getParentFile().getParentFile(); })
240+
.filter(((Predicate<String>) String::isEmpty).negate())
241+
.map((String path) -> {
242+
return new File(path).getParentFile().getParentFile();
243+
})
233244
.collect(Collectors.toList());
234245
}
235246

236-
public static ToolchainDiscovererProperty forSystemPath(Project project, ToolchainGraphBuildService tce, ToolchainDescriptorBase descriptor, Function<String, String> composer) {
237-
ToolchainDiscovererProperty prop = project.getObjects().newInstance(ToolchainDiscovererProperty.class, "PathList");
247+
public static ToolchainDiscovererProperty forSystemPath(Project project, ToolchainGraphBuildService tce,
248+
ToolchainDescriptorBase descriptor, Function<String, String> composer, ExecOperations operations) {
249+
ToolchainDiscovererProperty prop = project.getObjects().newInstance(ToolchainDiscovererProperty.class,
250+
"PathList");
238251

239252
Provider<List<ToolchainDiscoverer>> p = project.provider(() -> {
240253
List<ToolchainDiscoverer> disc = new ArrayList<>();
241254
int i = 0;
242-
for (File f : systemPath(project, tce, composer)) {
255+
for (File f : systemPath(project, tce, composer, operations)) {
243256
Provider<File> fp = project.provider(() -> f);
244257
disc.add(ToolchainDiscoverer.createDiscoverer("Path" + (i++), descriptor, fp, composer, project));
245258
}
@@ -250,7 +263,9 @@ public static ToolchainDiscovererProperty forSystemPath(Project project, Toolcha
250263
}
251264

252265
private static Optional<File> join(Optional<File> f, String join) {
253-
return optFile((File)(f.map((File file) -> { return new File(file, join); }).orElse(null)));
266+
return optFile((File) (f.map((File file) -> {
267+
return new File(file, join);
268+
}).orElse(null)));
254269
}
255270

256271
private static Optional<File> optFile(File f) {

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/ToolchainExtension.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.gradle.internal.logging.text.DiagnosticsVisitor;
1414
import org.gradle.internal.os.OperatingSystem;
1515
import org.gradle.nativeplatform.toolchain.Gcc;
16+
import org.gradle.process.ExecOperations;
1617

1718
import edu.wpi.first.toolchain.arm32.Arm32ToolchainPlugin;
1819
import edu.wpi.first.toolchain.arm64.Arm64ToolchainPlugin;
@@ -45,7 +46,7 @@ public ToolchainGraphBuildService getToolchainGraphService() {
4546
}
4647

4748
@Inject
48-
public ToolchainExtension(Project project, ToolchainGraphBuildService rootExtension) {
49+
public ToolchainExtension(Project project, ToolchainGraphBuildService rootExtension, ExecOperations operations) {
4950
this.project = project;
5051
this.rootExtension = rootExtension;
5152

@@ -67,13 +68,15 @@ public ToolchainExtension(Project project, ToolchainGraphBuildService rootExtens
6768
descriptor.getVersionLow().convention("0.0");
6869
descriptor.getVersionHigh().convention("1000.0");
6970

70-
descriptor.getToolchainPlatform().set(project.provider(() -> config.getOperatingSystem().get() + config.getArchitecture().get()));
71+
descriptor.getToolchainPlatform().set(
72+
project.provider(() -> config.getOperatingSystem().get() + config.getArchitecture().get()));
7173
toolchainDescriptors.add(descriptor);
7274

73-
descriptor.getDiscoverers().add(ToolchainDiscoverer.forSystemPath(project, rootExtension, descriptor, name -> {
74-
String exeSuffix = OperatingSystem.current().isWindows() ? ".exe" : "";
75-
return config.getCompilerPrefix().get() + name + exeSuffix;
76-
}));
75+
descriptor.getDiscoverers()
76+
.add(ToolchainDiscoverer.forSystemPath(project, rootExtension, descriptor, name -> {
77+
String exeSuffix = OperatingSystem.current().isWindows() ? ".exe" : "";
78+
return config.getCompilerPrefix().get() + name + exeSuffix;
79+
}, operations));
7780

7881
config.getToolchainDescriptor().set(descriptor);
7982
} else {
@@ -85,9 +88,10 @@ public ToolchainExtension(Project project, ToolchainGraphBuildService rootExtens
8588

8689
public void setSinglePrintPerPlatform() {
8790
rootExtension.setSinglePrintPerPlatform();
88-
// ToolchainUtilExtension tcuExt = project.getExtensions().findByType(ToolchainUtilExtension.class);
91+
// ToolchainUtilExtension tcuExt =
92+
// project.getExtensions().findByType(ToolchainUtilExtension.class);
8993
// if (tcuExt != null) {
90-
// tcuExt.setSkipBinaryToolchainMissingWarning(true);
94+
// tcuExt.setSkipBinaryToolchainMissingWarning(true);
9195
// }
9296
}
9397

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/ToolchainRules.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ public static OrderedStripTask configureOrderedStrip(AbstractLinkTask link, GccE
241241
return null;
242242
}
243243

244-
strip = linkExt.getExtensions().create("orderedStrip", OrderedStripTask.class, tcExt, binary, link, gcc,
245-
project);
244+
strip = linkExt.getExtensions().create("orderedStrip", OrderedStripTask.class, tcExt, binary, link, gcc);
246245
link.doLast(strip);
247246
}
248247
return strip;

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/arm32/Arm32ToolchainPlugin.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package edu.wpi.first.toolchain.arm32;
22

3+
import javax.inject.Inject;
4+
35
import org.gradle.api.Plugin;
46
import org.gradle.api.Project;
7+
import org.gradle.process.ExecOperations;
58

69
import edu.wpi.first.toolchain.NativePlatforms;
710
import edu.wpi.first.toolchain.ToolchainDescriptor;
@@ -17,6 +20,13 @@ public class Arm32ToolchainPlugin implements Plugin<Project> {
1720
private Arm32ToolchainExtension arm32Ext;
1821
private OpenSdkToolchainBase opensdk;
1922

23+
private ExecOperations operations;
24+
25+
@Inject
26+
public Arm32ToolchainPlugin(ExecOperations operations) {
27+
this.operations = operations;
28+
}
29+
2030
@Override
2131
public void apply(Project project) {
2232

@@ -25,9 +35,11 @@ public void apply(Project project) {
2535
ToolchainExtension toolchainExt = project.getExtensions().getByType(ToolchainExtension.class);
2636

2737
opensdk = new OpenSdkToolchainBase(baseToolchainName, arm32Ext, project, Arm32ToolchainExtension.INSTALL_SUBDIR,
28-
"raspi-bullseye", project.provider(() -> "armv6-bullseye-linux-gnueabihf"), toolchainExt.getToolchainGraphService());
38+
"raspi-bullseye", project.provider(() -> "armv6-bullseye-linux-gnueabihf"),
39+
toolchainExt.getToolchainGraphService(), operations);
2940

30-
CrossCompilerConfiguration configuration = project.getObjects().newInstance(CrossCompilerConfiguration.class, NativePlatforms.linuxarm32);
41+
CrossCompilerConfiguration configuration = project.getObjects().newInstance(CrossCompilerConfiguration.class,
42+
NativePlatforms.linuxarm32);
3143

3244
configuration.getArchitecture().set("arm");
3345
configuration.getOperatingSystem().set("linux");

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/arm64/Arm64ToolchainPlugin.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package edu.wpi.first.toolchain.arm64;
22

3+
import javax.inject.Inject;
4+
35
import org.gradle.api.Plugin;
46
import org.gradle.api.Project;
7+
import org.gradle.process.ExecOperations;
58

69
import edu.wpi.first.toolchain.NativePlatforms;
710
import edu.wpi.first.toolchain.ToolchainDescriptor;
@@ -16,6 +19,12 @@ public class Arm64ToolchainPlugin implements Plugin<Project> {
1619

1720
private Arm64ToolchainExtension arm64Ext;
1821
private OpenSdkToolchainBase opensdk;
22+
private ExecOperations operations;
23+
24+
@Inject
25+
public Arm64ToolchainPlugin(ExecOperations operations) {
26+
this.operations = operations;
27+
}
1928

2029
@Override
2130
public void apply(Project project) {
@@ -24,9 +33,11 @@ public void apply(Project project) {
2433
ToolchainExtension toolchainExt = project.getExtensions().getByType(ToolchainExtension.class);
2534

2635
opensdk = new OpenSdkToolchainBase(baseToolchainName, arm64Ext, project, Arm64ToolchainExtension.INSTALL_SUBDIR,
27-
"bullseye", project.provider(() -> "aarch64-bullseye-linux-gnu"), toolchainExt.getToolchainGraphService());
36+
"bullseye", project.provider(() -> "aarch64-bullseye-linux-gnu"),
37+
toolchainExt.getToolchainGraphService(), operations);
2838

29-
CrossCompilerConfiguration configuration = project.getObjects().newInstance(CrossCompilerConfiguration.class, NativePlatforms.linuxarm64);
39+
CrossCompilerConfiguration configuration = project.getObjects().newInstance(CrossCompilerConfiguration.class,
40+
NativePlatforms.linuxarm64);
3041

3142
configuration.getArchitecture().set("arm64");
3243
configuration.getOperatingSystem().set("linux");

ToolchainPlugin/src/main/java/edu/wpi/first/toolchain/opensdk/OpenSdkToolchainBase.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.gradle.api.Project;
99
import org.gradle.api.provider.Provider;
1010
import org.gradle.internal.os.OperatingSystem;
11+
import org.gradle.process.ExecOperations;
1112

1213
import edu.wpi.first.toolchain.AbstractToolchainInstaller;
1314
import edu.wpi.first.toolchain.DefaultToolchainInstaller;
@@ -25,16 +26,19 @@ public class OpenSdkToolchainBase {
2526
private final String archiveSubDir;
2627
private final Provider<String> toolchainPrefix;
2728
private final ToolchainGraphBuildService rootExtension;
29+
private final ExecOperations operations;
2830

2931
public OpenSdkToolchainBase(String baseToolchainName, OpenSdkToolchainExtension tcExt, Project project,
30-
String installSubdir, String archiveSubdir, Provider<String> toolchainPrefix, ToolchainGraphBuildService rootExtension) {
32+
String installSubdir, String archiveSubdir, Provider<String> toolchainPrefix,
33+
ToolchainGraphBuildService rootExtension, ExecOperations operations) {
3134
this.baseToolchainName = baseToolchainName;
3235
this.tcExt = tcExt;
3336
this.project = project;
3437
this.installSubdir = installSubdir;
3538
this.archiveSubDir = archiveSubdir;
3639
this.toolchainPrefix = toolchainPrefix;
3740
this.rootExtension = rootExtension;
41+
this.operations = operations;
3842
}
3943

4044
private String toolchainRemoteFile() {
@@ -44,10 +48,10 @@ private String toolchainRemoteFile() {
4448
if (OperatingSystem.current().isWindows()) {
4549
platformId = "x86_64-w64-mingw32";
4650
} else if (OperatingSystem.current().isMacOsX()) {
47-
platformId = (NativePlatforms.desktopPlatformArch(project) == NativePlatforms.x64arch ? "x86_64" : "arm64")
51+
platformId = (NativePlatforms.desktopPlatformArch(operations) == NativePlatforms.x64arch ? "x86_64" : "arm64")
4852
+ "-apple-darwin";
4953
} else {
50-
String desktopPlatformArch = NativePlatforms.desktopPlatformArch(project);
54+
String desktopPlatformArch = NativePlatforms.desktopPlatformArch(operations);
5155
if (desktopPlatformArch.equals(NativePlatforms.arm64arch)) {
5256
platformId = "aarch64-bullseye-linux-gnu";
5357
} else if (desktopPlatformArch.equals(NativePlatforms.arm32arch)) {
@@ -94,8 +98,10 @@ public void populatePathAndDownloadDescriptors(ToolchainDescriptor descriptor) {
9498
});
9599

96100
// Discoverer order matters. They will be searched from top to bottom.
97-
descriptor.getDiscoverers().add(ToolchainDiscoverer.createProperty("GradleUserDir", descriptor, fp, this::composeTool, project));
98-
descriptor.getDiscoverers().add(ToolchainDiscoverer.forSystemPath(project, rootExtension, descriptor, this::composeTool));
101+
descriptor.getDiscoverers()
102+
.add(ToolchainDiscoverer.createProperty("GradleUserDir", descriptor, fp, this::composeTool, project));
103+
descriptor.getDiscoverers()
104+
.add(ToolchainDiscoverer.forSystemPath(project, rootExtension, descriptor, this::composeTool, operations));
99105

100106
try {
101107
descriptor.getInstallers().add(installerFor(OperatingSystem.LINUX, fp, archiveSubDir));

0 commit comments

Comments
 (0)