Skip to content

Commit

Permalink
Merge branch 'master' into 2472_EOError-returns-String
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Sep 12, 2023
2 parents ff9fd27 + fa610ca commit ada1037
Show file tree
Hide file tree
Showing 58 changed files with 1,771 additions and 1,296 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ebnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ jobs:
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-
- run: |
mkdir -p $CONVERT_PATH
mkdir -p "$CONVERT_PATH"
wget --quiet http://public.yegor256.com/convert.zip -O /tmp/convert.zip
unzip -o -d $CONVERT_PATH /tmp/convert.zip
- run: mvn clean test '-P!jacoco' -Dtest=XMIRTest -pl :eo-parser --errors --batch-mode --quiet
unzip -o -d "$CONVERT_PATH" /tmp/convert.zip
- run: sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
- run: |
cp eo-parser/src/test/resources/tex/ebnf.tex eo-parser/target/ebnf.tex
cd eo-parser/target
sed -i -e '/EBNF/{r ebnf.txt' -e 'd}' ebnf.tex
pdflatex -shell-escape -interaction=errorstopmode -halt-on-error ebnf.tex
pdfcrop --margins '10 10 10 10' ebnf.pdf crop.pdf
mvn com.yegor256:antlr2ebnf-maven-plugin:0.0.4:generate \
-pl :eo-parser --debug --errors --batch-mode --quiet \
"-Dantlr2ebnf.convertDir=$CONVERT_PATH"
- run: |
set -x
cp eo-parser/target/ebnf/org/eolang/parser/Program.pdf .
pdfcrop --margins '10 10 10 10' Program.pdf crop.pdf
pdf2svg crop.pdf ebnf.svg
convert -density 300 -quality 100 -transparent white -colorspace RGB crop.pdf ebnf.png
ls -al
mkdir gh-pages
cp ebnf.png gh-pages
cp ebnf.svg gh-pages
- uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: eo-parser/target/gh-pages
folder: gh-pages
clean: false
if: github.ref == 'refs/heads/master'
9 changes: 0 additions & 9 deletions .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ jobs:
CONVERT_PATH: /tmp/antlr4-to-bnf-converter
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- uses: teatimeguest/[email protected]
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand All @@ -52,9 +48,4 @@ jobs:
echo [http] >> %USERPROFILE%\.cargo\config.toml
echo multiplexing = false >> %USERPROFILE%\.cargo\config.toml
shell: cmd
- run: |
mkdir -p $CONVERT_PATH
wget --quiet http://public.yegor256.com/convert.zip -O /tmp/convert.zip
unzip -o -d $CONVERT_PATH /tmp/convert.zip
if: matrix.os == 'ubuntu-20.04'
- run: mvn clean install -Pqulice --errors --batch-mode
102 changes: 80 additions & 22 deletions eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@
import org.cactoos.iterable.Filtered;
import org.cactoos.iterable.Mapped;
import org.cactoos.number.SumOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.maven.rust.BuildFailureException;

/**
* Compile binaries.
*
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @since 0.1
* @todo #2197:45min Update cached rust insert if it was changed.
* 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.
*/
@Mojo(
name = "binarize",
Expand Down Expand Up @@ -100,7 +98,7 @@ public void exec() throws IOException {
return 1;
},
new Filtered<>(
project -> BinarizeMojo.valid(project),
BinarizeMojo::valid,
targetDir.toPath().resolve("Lib").toFile().listFiles()
)
)
Expand All @@ -112,7 +110,7 @@ public void exec() throws IOException {
/**
* Is the project valid?
* @param project File to check.
* @return True if valid. Otherwise false.
* @return True if valid. Otherwise, false.
*/
private static boolean valid(final File project) {
return project.isDirectory()
Expand All @@ -134,24 +132,84 @@ private void build(final File project) throws IOException {
Logger.info(this, "Copying %s to %s", cached, target);
FileUtils.copyDirectory(cached, target);
}
Logger.info(this, "Building rust project..");
try {
new Jaxec("cargo", "build").withHome(project).execUnsafe();
} catch (final IOException ex) {
throw new BuildFailureException(
String.format(
"Failed to build cargo project with dest = %s",
project
),
ex
if (BinarizeMojo.sameProject(
project.toPath(),
this.cache
.resolve("Lib")
.resolve(project.getName())
)) {
Logger.info(
this,
"content of %s was not changed since the last launch",
project.getName()
);
} else {
Logger.info(this, "Building %s rust project..", project.getName());
try {
new Jaxec("cargo", "build").withHome(project).execUnsafe();
} catch (final IOException ex) {
throw new BuildFailureException(
String.format(
"Failed to build cargo project with dest = %s",
project
),
ex
);
}
Logger.info(
this,
"Cargo building succeeded, update cached %s with %s",
cached,
target
);
FileUtils.copyDirectory(target.getParentFile(), cached.getParentFile());
}
Logger.info(
this,
"Cargo building succeeded, update cached %s with %s",
cached,
target
}

/**
* Check if the project was not changed.
* @param src Directory in current target.
* @param cached Directory in cache.
* @return True if the project is the same.
*/
private static boolean sameProject(final Path src, final Path cached) {
return BinarizeMojo.sameFile(
src.resolve("src/foo.rs"), cached.resolve("src/foo.rs")
) && BinarizeMojo.sameFile(
src.resolve("src/lib.rs"), cached.resolve("src/lib.rs")
) && BinarizeMojo.sameFile(
src.resolve("Cargo.toml"), cached.resolve("Cargo.toml")
);
}

/**
* Check if the source file is the same as in cache.
* @param src Source file.
* @param cached Cache file.
* @return True if the same.
*/
private static boolean sameFile(final Path src, final Path cached) {
return cached.toFile().exists() && BinarizeMojo.uncomment(
new UncheckedText(
new TextOf(src)
).asString()
).equals(
new UncheckedText(
new TextOf(cached)
).asString()
);
}

/**
* Removed the first line from the string.
* We need it because generated files are disclaimed.
* @param content Content.
* @return String without the first line.
* @checkstyle StringLiteralsConcatenationCheck (8 lines)
*/
private static String uncomment(final String content) {
return content.substring(
1 + content.indexOf(System.getProperty("line.separator"))
);
FileUtils.copyDirectory(target, cached);
}
}
43 changes: 3 additions & 40 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ abstract class SafeMojo extends AbstractMojo {
)
protected File foreign;

/**
* File with external "tojos".
* @checkstyle VisibilityModifierCheck (10 lines)
*/
@Parameter(
property = "eo.external",
required = true,
defaultValue = "${project.build.directory}/eo-external.csv"
)
protected File external;

/**
* Format of "foreign" file ("json" or "csv").
* @checkstyle MemberNameCheck (7 lines)
Expand Down Expand Up @@ -202,34 +191,17 @@ abstract class SafeMojo extends AbstractMojo {

/**
* Used for object versioning implementation.
* If set to TRUE, external tojos are used instead of foreign ones and all
* inherited Mojos behave a bit differently.
* If set to TRUE - objects are parsed, stored in tojos and processed as versioned.
* @todo #1602:30min Remove the flag when objection versioned is
* implemented. The variable is used for implementation of object
* versioning. It allows to use external tojos instead of foreign in Mojos.
* for the test purposes. When object versioning is implemented there
* versioning. When object versioning is implemented there
* will be no need for that variable
* @checkstyle VisibilityModifierCheck (10 lines)
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(property = "eo.withVersions", defaultValue = "false")
protected boolean withVersions;

/**
* External tojos.
* @todo #1602:30min Use external tojos to implement object versioning.
* Implementation of object versioning will bring a lot significant
* changes. That's why it's better to use independent separated tojos for
* that purpose. At the end when object versioning works - just replace
* them and remove unnecessary one.
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle VisibilityModifierCheck (5 lines)
*/
protected final ForeignTojos externalTojos = new ForeignTojos(
() -> Catalogs.INSTANCE.make(this.external.toPath(), this.foreignFormat),
() -> this.scope
);

/**
* Commit hashes.
* @checkstyle VisibilityModifierCheck (5 lines)
Expand Down Expand Up @@ -323,9 +295,6 @@ public final void execute() throws MojoFailureException, MojoExecutionException
if (this.foreign != null) {
SafeMojo.closeTojos(this.tojos);
}
if (this.external != null) {
SafeMojo.closeTojos(this.externalTojos);
}
if (this.placed != null) {
SafeMojo.closeTojos(this.placedTojos);
}
Expand All @@ -342,13 +311,7 @@ public final void execute() throws MojoFailureException, MojoExecutionException
* @checkstyle AnonInnerLengthCheck (100 lines)
*/
protected final ForeignTojos scopedTojos() {
final ForeignTojos tjs;
if (this.external != null && this.withVersions) {
tjs = this.externalTojos;
} else {
tjs = this.tojos;
}
return tjs;
return this.tojos;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,28 @@ void savesToCache(@TempDir final Path temp) throws IOException {
() -> maven.execute(new FakeMaven.Binarize())
);
}

@Test
@Tag("slow")
void boostsSecondCompilation(@TempDir final Path temp) throws IOException {
final FakeMaven maven;
final Path cache = temp.resolve(".cache");
synchronized (BinarizeMojoTest.class) {
maven = new FakeMaven(temp)
.withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo"))
.with("cache", cache);
}
long start = System.currentTimeMillis();
maven.execute(new FakeMaven.Binarize());
long finish = System.currentTimeMillis();
final long first = finish - start;
start = finish;
maven.execute(new FakeMaven.Binarize());
finish = System.currentTimeMillis();
final long second = finish - start;
MatcherAssert.assertThat(
second,
Matchers.lessThan(first)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ final class DiscoverMojoTest {
* Default assertion message.
*/
private static final String SHOULD_CONTAIN =
"External tojos should contain %s object after discovering, but they didn't";
"Tojos should contain %s object after discovering, but they didn't";

/**
* Default assertion message.
*/
private static final String SHOULD_NOT =
"External tojos should not contain %s object after discovering, but they did";
"Tojos should not contain %s object after discovering, but they did";

@ParameterizedTest
@CsvSource({
Expand Down Expand Up @@ -121,7 +121,7 @@ void discoversWithVersions(@TempDir final Path tmp) throws IOException {
.execute(new FakeMaven.Discover());
final ObjectName stdout = new OnVersioned("org.eolang.stdout", "9c93528");
final String nop = "org.eolang.nop";
final ForeignTojos tojos = maven.externalTojos();
final ForeignTojos tojos = maven.foreignTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, DiscoverMojoTest.TEXT),
tojos.contains(DiscoverMojoTest.TEXT),
Expand Down Expand Up @@ -163,7 +163,7 @@ void discoversWithSeveralObjectsWithDifferentVersions(
.execute(new FakeMaven.Discover());
final ObjectName first = new OnVersioned("org.eolang.txt.sprintf", hashes.get("0.28.1"));
final ObjectName second = new OnVersioned("org.eolang.txt.sprintf", hashes.get("0.28.2"));
final ForeignTojos tojos = maven.externalTojos();
final ForeignTojos tojos = maven.foreignTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, first),
tojos.contains(first),
Expand Down Expand Up @@ -193,7 +193,7 @@ void discoversDifferentUnversionedObjectsFromDifferentVersionedObjects(@TempDir
.withProgram(second, new OnVersioned(object, two))
.withProgram(first, new OnDefault(object))
.execute(new FakeMaven.Discover())
.externalTojos();
.foreignTojos();
MatcherAssert.assertThat(
String.format(
"Tojos should contained 3 similar objects %s: 2 with different hashes %s and one without; but they didn't",
Expand All @@ -219,12 +219,12 @@ void doesNotDiscoverWithVersions(@TempDir final Path tmp) throws IOException {
final ObjectName seq = new OnVersioned("org.eolang.seq", "6c6269d");
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, seq),
maven.externalTojos().contains(seq),
maven.foreignTojos().contains(seq),
Matchers.is(false)
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, DiscoverMojoTest.TEXT),
maven.externalTojos().contains(DiscoverMojoTest.TEXT),
maven.foreignTojos().contains(DiscoverMojoTest.TEXT),
Matchers.is(false)
);
}
Expand Down
Loading

3 comments on commit ada1037

@0pdd
Copy link

@0pdd 0pdd commented on ada1037 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2283-0094b893 disappeared from eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java), that's why I closed #2313. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on ada1037 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2283-ddadafec disappeared from eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java), that's why I closed #2315. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on ada1037 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2442-87b4ce00 disappeared from eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java), that's why I closed #2472. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.