Skip to content

Commit

Permalink
Merge branch 'master' into update-maven-plugin-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Dec 6, 2021
2 parents 34e445a + 3801358 commit 196067d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BaseCSharpTest extends BaseRuntimeTestSupport implements RuntimeTes
private final static String testProjectFileName = "Antlr4.Test.csproj";
private final static boolean isDebug = false;
private static String cSharpTestProjectContent;
private static final String cSharpCachingDirectory = Paths.get(cachingDirectory, "CSharp").toString();

@Override
protected String getPropertyPrefix() {
Expand Down Expand Up @@ -208,7 +209,7 @@ public boolean buildProject() {
return true;
}

private boolean initializeRuntime() {
private synchronized boolean initializeRuntime() {
// Compile runtime project once per tests session
if (isRuntimeInitialized)
return true;
Expand All @@ -222,20 +223,19 @@ private boolean initializeRuntime() {
File runtimeProjFile = new File(runtimeProj.getFile());
String runtimeProjPath = runtimeProjFile.getPath();

RuntimeTestUtils.mkdir(cachingDirectory);
RuntimeTestUtils.mkdir(cSharpCachingDirectory);
String[] args = new String[]{
"dotnet",
"build",
runtimeProjPath,
"-c",
"Release",
"-o",
cachingDirectory
cSharpCachingDirectory
};

boolean success;
try
{
try {
String cSharpTestProjectResourceName = BaseCSharpTest.class.getPackage().getName().replace(".", "/") + "/";
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(cSharpTestProjectResourceName + testProjectFileName);
int bufferSize = 1024;
Expand All @@ -245,11 +245,10 @@ private boolean initializeRuntime() {
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
out.append(buffer, 0, numRead);
}
cSharpTestProjectContent = out.toString().replace(cSharpAntlrRuntimeDllName, Paths.get(cachingDirectory, cSharpAntlrRuntimeDllName).toString());
cSharpTestProjectContent = out.toString().replace(cSharpAntlrRuntimeDllName, Paths.get(cSharpCachingDirectory, cSharpAntlrRuntimeDllName).toString());

success = runProcess(args, cachingDirectory);
}
catch (Exception e) {
success = runProcess(args, cSharpCachingDirectory);
} catch (Exception e) {
e.printStackTrace(System.err);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.EnumSet;

import static junit.framework.TestCase.*;
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
Expand Down Expand Up @@ -188,30 +189,32 @@ private String execModule(String fileName) {
stdoutVacuum.join();
stderrVacuum.join();
String output = stdoutVacuum.toString();
if ( output.length()==0 ) {
if (output.length() == 0) {
output = null;
}
if (stderrVacuum.toString().length() > 0) {
setParseErrors(stderrVacuum.toString());
}
return output;
}
catch (Exception e) {
} catch (Exception e) {
System.err.println("can't exec recognizer");
e.printStackTrace(System.err);
}
return null;
}

private boolean initializeRuntime() {
private synchronized boolean initializeRuntime() {
if (isRuntimeInitialized)
return true;

String goRoot = getGoRootValue();
Path newGoRoot = Paths.get(cachingDirectory, "Go");
newGoRootString = newGoRoot.toString();
try {
copyDirectory(Paths.get(goRoot), newGoRoot, StandardCopyOption.REPLACE_EXISTING);
File newGoRootDirectory = newGoRoot.toFile();
if (newGoRootDirectory.exists())
deleteDirectory(newGoRootDirectory);
copyDirectory(Paths.get(goRoot), newGoRoot);
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Unable to copy go system files");
Expand Down Expand Up @@ -240,7 +243,7 @@ private boolean initializeRuntime() {

private void copyDirectory(final Path source, final Path target, final CopyOption... options)
throws IOException {
Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 2147483647, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
Expand All @@ -257,6 +260,15 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
});
}

private void deleteDirectory(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
deleteDirectory(c);
}
if (!f.delete())
throw new FileNotFoundException("Failed to delete file: " + f);
}

private static String getGoRootValue() {
try {
ProcessBuilder pb = new ProcessBuilder("go", "env", "GOROOT");
Expand Down
3 changes: 2 additions & 1 deletion runtime/CSharp/src/Antlr4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<Company>The ANTLR Organization</Company>
<Version>4.9.3</Version>
<NeutralLanguage>en-US</NeutralLanguage>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">netstandard2.0</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net45;netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS1591;CS1574;CS1580</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Antlr4.Runtime.Standard</AssemblyName>
Expand Down
6 changes: 1 addition & 5 deletions runtime/Cpp/runtime/src/ANTLRInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ ANTLRInputStream::ANTLRInputStream() {
InitializeInstanceFields();
}

ANTLRInputStream::ANTLRInputStream(const std::string_view &input): ANTLRInputStream() {
ANTLRInputStream::ANTLRInputStream(std::string_view input): ANTLRInputStream() {
load(input.data(), input.length());
}

ANTLRInputStream::ANTLRInputStream(const std::string &input): ANTLRInputStream() {
load(input.data(), input.size());
}

ANTLRInputStream::ANTLRInputStream(const char *data, size_t length) {
load(data, length);
}
Expand Down
3 changes: 1 addition & 2 deletions runtime/Cpp/runtime/src/ANTLRInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ namespace antlr4 {

ANTLRInputStream();

ANTLRInputStream(const std::string_view &input);
ANTLRInputStream(std::string_view input);

ANTLRInputStream(const std::string &input);
ANTLRInputStream(const char *data, size_t length);
ANTLRInputStream(std::istream &stream);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ RuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedAction
<namedActions.init>
<locals; separator = "\n">

#if __cplusplus > 201703L
auto onExit = finally([=, this] {
#else
auto onExit = finally([=] {
#endif
<finallyAction>
exitRule();
});
Expand Down Expand Up @@ -509,7 +513,11 @@ LeftRecursiveRuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs
<namedActions.init>
<! TODO: untested !> <locals; separator = "\n">

#if __cplusplus > 201703L
auto onExit = finally([=, this] {
#else
auto onExit = finally([=] {
#endif
<if (finallyAction)><finallyAction><endif>
unrollRecursionContexts(parentContext);
});
Expand Down

0 comments on commit 196067d

Please sign in to comment.