Skip to content

Commit

Permalink
Use an @file to list the sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolamarao committed Feb 22, 2024
1 parent 4980f63 commit 34d2594
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>();
args.add("rcs");
args.addAll(options);
args.add(output.toString());
getSource().forEach(source -> args.add(source.toString()));
final var command = new ArrayList<String>();
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public MetalLink ()
* Link action.
*/
@TaskAction
public void link ()
public void link () throws Exception
{
final var metal = getMetal().get();

Expand All @@ -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<String>();
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<String>();
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)
Expand Down

0 comments on commit 34d2594

Please sign in to comment.