Skip to content

Commit

Permalink
#2208: Parallel compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Jul 10, 2023
1 parent e9ef31a commit 4146ce0
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.cactoos.experimental.Threads;
import org.cactoos.iterable.Mapped;
import org.cactoos.number.SumOf;
import org.eolang.maven.rust.BuildFailureException;

/**
Expand All @@ -45,9 +48,6 @@
* Now it copies cargo project to cache directory in the end of every
* compilation. It is better to copy the project only if it was changed
* with the last compilation.
* @todo #2195:90min Make cargo compilation in parallel. Now cargo
* projects are being built consistently which is too long.
* It is much better to build them in parallel to reduce time.
*/
@Mojo(
name = "binarize",
Expand Down Expand Up @@ -77,11 +77,26 @@ public final class BinarizeMojo extends SafeMojo {
@Override
public void exec() throws IOException {
new Moja<>(BinarizeParseMojo.class).copy(this).execute();
for (final File project: targetDir.toPath().resolve("Lib").toFile().listFiles()) {
if (project.isDirectory() && project.toPath().resolve("Cargo.toml").toFile().exists()) {
this.build(project);
}
}
int total = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
new Mapped<>(
project -> () -> {
if (project.isDirectory() && project.toPath().resolve("Cargo.toml").toFile().exists()) {
this.build(project);
return 1;
} else {
return 0;
}
},
targetDir.toPath().resolve("Lib").toFile().listFiles()
)
)
).intValue();
Logger.info(
this,
String.format("Built in total %d cargo projects", total)
);
}

/**
Expand Down Expand Up @@ -117,16 +132,6 @@ private void build(final File project) throws IOException {
)
) {
proc.stdout();
proc.waitFor();
} catch (final InterruptedException exception) {
Thread.currentThread().interrupt();
throw new BuildFailureException(
String.format(
"Interrupted while building %s",
project
),
exception
);
} catch (final IllegalArgumentException exc) {
throw new BuildFailureException(
String.format(
Expand Down

0 comments on commit 4146ce0

Please sign in to comment.