diff --git a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/MetalApplicationTest.java b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/MetalApplicationTest.java index 47b3137..fd2098f 100644 --- a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/MetalApplicationTest.java +++ b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/MetalApplicationTest.java @@ -726,6 +726,6 @@ void largeSourceSet () throws IOException .withProjectDir(projectDir.toFile()) .build(); - assertThat( archive.task(":archive").getOutcome() ).isEqualTo(SUCCESS); + assertThat( archive.task(":link").getOutcome() ).isEqualTo(SUCCESS); } } diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalArchive.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalArchive.java index 91a98d2..f36c7c1 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalArchive.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalArchive.java @@ -81,30 +81,27 @@ public MetalArchive () * Archive action. */ @TaskAction - public void archive () + public void archive () throws Exception { final var archiver = getMetal().get().locateTool(getArchiver().get()); final var options = getOptions().get(); final var output = getOutput().getAsFile().get(); - try - { - Files.createDirectories(output.toPath().getParent()); - } - catch (IOException e) - { - throw new RuntimeException(e); + final var atFile = this.getTemporaryDir().toPath().resolve("sources"); + try (var writer = Files.newBufferedWriter(atFile)) { + getSource().forEach(file -> { + try { writer.write(file.toString().replace("\\","\\\\") + "\n"); } + catch (IOException e) { throw new RuntimeException(e); } + }); } - final var args = new ArrayList(); - args.add("rcs"); - args.addAll(options); - args.add(output.toString()); - getSource().forEach(source -> args.add(source.toString())); + final var command = new ArrayList(); + command.add(archiver.toString()); + command.add("rcs"); + command.addAll(options); + command.add(output.toString()); + command.add("@"+atFile); - getExec().exec(it -> { - it.executable(archiver); - it.args(args); - }); + getExec().exec(it -> it.commandLine(command)); } } diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalLink.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalLink.java index 17af407..1a68e23 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalLink.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/MetalLink.java @@ -107,7 +107,7 @@ public MetalLink () * Link action. */ @TaskAction - public void link () + public void link () throws Exception { final var metal = getMetal().get(); @@ -117,28 +117,28 @@ public void link () final var output = getOutput().getAsFile().get(); final var target = getTarget().map(this::targetMapper).get(); - try - { - Files.createDirectories(output.toPath().getParent()); - } - catch (IOException e) - { - throw new RuntimeException(e); + final var atFile = this.getTemporaryDir().toPath().resolve("sources"); + try (var writer = Files.newBufferedWriter(atFile)) { + getSource().forEach(file -> { + try { writer.write(file.toString().replace("\\","\\\\") + "\n"); } + catch (IOException e) { throw new RuntimeException(e); } + }); + getLinkDependencies().forEach(file -> { + try { writer.write(file.toString().replace("\\","\\\\") + "\n"); } + catch (IOException e) { throw new RuntimeException(e); } + }); } - final var args = new ArrayList(); - args.add("--target=%s".formatted(target)); - if (! target.contentEquals(host)) args.add("-fuse-ld=lld"); - args.addAll(options); - getLibraryPath().get().forEach(path -> args.add("--library-directory=%s".formatted(path))); - args.add("--output=%s".formatted(output)); - getSource().forEach(source -> args.add(source.toString())); - getLinkDependencies().forEach(linkable -> args.add(linkable.toString())); - - getExec().exec(it -> { - it.executable(linker); - it.args(args); - }); + final var command = new ArrayList(); + command.add(linker.toString()); + command.add("--target=%s".formatted(target)); + if (! target.contentEquals(host)) command.add("-fuse-ld=lld"); + command.addAll(options); + getLibraryPath().get().forEach(path -> command.add("--library-directory=%s".formatted(path))); + command.add("--output=%s".formatted(output)); + command.add("@"+atFile); + + getExec().exec(it -> it.commandLine(command)); } String targetMapper (String target)