Skip to content

Commit

Permalink
Merge branch 'maven-nar:master' into add-test
Browse files Browse the repository at this point in the history
  • Loading branch information
lacinoire authored Feb 7, 2023
2 parents 9f0e4fa + e747b5e commit 5672623
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 60 deletions.
74 changes: 42 additions & 32 deletions src/main/java/com/github/maven_nar/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,32 @@ public abstract class Compiler {
protected Compiler() {
}

/**
* Parses a "NAME=VALUE" string into a name and (optional) value. Logs to warn if argument is null, implying a blank
* config item (eg <define></define>, or <define>${x}</define> when x is undefined).
*
* @param argument the string to parse (may be null)
* @param configName the name of the argument type, for logging purposes
* @return the parsed DefineArgument, or null if argument is null
*/
private DefineArgument parseDefineArgument(final String argument, String configName) {
if (argument == null) {
this.mojo.getLog().warn("NAR configuration: empty " + configName + " - ignoring");
return null;
}
final String[] pair = argument.split("=", 2);

if (pair[0].equals("")) {
this.mojo.getLog().warn("NAR configuration: definition has no name in " + configName + " - ignoring");
return null;
}

final DefineArgument define = new DefineArgument();
define.setName(pair[0]);
define.setValue(pair.length > 1 ? cleanDefineValue(pair[1]) : null);
return define;
}

/**
* Filter elements such as cr\lf that are problematic when used inside a `define`
*
Expand Down Expand Up @@ -328,13 +354,10 @@ public final CompilerDef getCompiler(final String type, final String output)
}

if (this.optionSet != null) {

final String[] opts = this.optionSet.split("\\s");

for (final String opt : opts) {

final CompilerArgument arg = new CompilerArgument();

arg.setValue(opt);
compilerDef.addConfiguredCompilerArg(arg);
}
Expand All @@ -358,31 +381,24 @@ public final CompilerDef getCompiler(final String type, final String output)
if (this.defines != null) {
final DefineSet ds = new DefineSet();
for (final String string : this.defines) {
final DefineArgument define = new DefineArgument();
final String[] pair = string.split("=", 2);
define.setName(pair[0]);
define.setValue(pair.length > 1 ? cleanDefineValue(pair[1]) : null);
ds.addDefine(define);
final DefineArgument define = parseDefineArgument(string, "define");
if (define != null) {
ds.addDefine(define);
}
}
compilerDef.addConfiguredDefineset(ds);
}

if (this.defineSet != null) {

final String[] defList = this.defineSet.split(",");
final DefineSet defSet = new DefineSet();

for (final String element : defList) {

final String[] pair = element.trim().split("=", 2);
final DefineArgument def = new DefineArgument();

def.setName(pair[0]);
def.setValue(pair.length > 1 ? cleanDefineValue(pair[1]) : null);

defSet.addDefine(def);
final DefineArgument define = parseDefineArgument(element, "defineSet");
if (define != null) {
defSet.addDefine(define);
}
}

compilerDef.addConfiguredDefineset(defSet);
}

Expand All @@ -400,11 +416,10 @@ public final CompilerDef getCompiler(final String type, final String output)
if (this.undefines != null) {
final DefineSet us = new DefineSet();
for (final String string : this.undefines) {
final DefineArgument undefine = new DefineArgument();
final String[] pair = string.split("=", 2);
undefine.setName(pair[0]);
undefine.setValue(pair.length > 1 ? pair[1] : null);
us.addUndefine(undefine);
final DefineArgument undef = parseDefineArgument(string, "undefine");
if (undef != null) {
us.addUndefine(undef);
}
}
compilerDef.addConfiguredDefineset(us);
}
Expand All @@ -415,16 +430,11 @@ public final CompilerDef getCompiler(final String type, final String output)
final DefineSet undefSet = new DefineSet();

for (final String element : undefList) {

final String[] pair = element.trim().split("=", 2);
final DefineArgument undef = new DefineArgument();

undef.setName(pair[0]);
undef.setValue(pair.length > 1 ? pair[1] : null);

undefSet.addUndefine(undef);
final DefineArgument undef = parseDefineArgument(element, "undefineSet");
if (undef != null) {
undefSet.addUndefine(undef);
}
}

compilerDef.addConfiguredDefineset(undefSet);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/maven_nar/IncludePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public void setPath(final String path) {
this.path = path;
this.file = new File(path);
}

@Override
public String toString() {
return getPath() + (includes == null ? "" : "[" + getIncludes() + "]");
}
}
27 changes: 12 additions & 15 deletions src/main/java/com/github/maven_nar/Linker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
*/
package com.github.maven_nar;

import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.base.Strings.nullToEmpty;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -283,27 +285,27 @@ public final LinkerDef getLinker(final AbstractCompileMojo mojo, final CCTask ta
linker.setSkipDepLink(this.skipDepLink);

// incremental, map
String linkerPrefix;
if (this.prefix == null || this.prefix.equals("")) {
final String linkerPrefix;
// don't add prefix to ar-like commands FIXME should be done in cpptasks
if (type.equals(Library.STATIC) && !getName(null, null).equals("msvc")) {
linkerPrefix = null;
}
else if (isNullOrEmpty(this.prefix)) {
String key = mojo.getAOL().getKey() + ".linker.prefix";
linkerPrefix = NarProperties.getInstance(mojo.getMavenProject()).getProperty(key);
}
else {
linkerPrefix = this.prefix;
}

// don't add prefix to ar-like commands FIXME should be done in cpptasks
if (type.equals(Library.STATIC) && !getName(null, null).equals("msvc")) {
linkerPrefix = null;
}
linker.setLinkerPrefix(linkerPrefix);
linker.setIncremental(this.incremental);
linker.setMap(this.map);

// Add definitions (Window only)
if (os.equals(OS.WINDOWS) && getName(null, null).equals("msvc")
&& (type.equals(Library.SHARED) || type.equals(Library.JNI))) {
final Set defs = new HashSet();
final Set<File> defs = new HashSet<>();
try {
if (mojo.getC() != null) {
final List cSrcDirs = mojo.getC().getSourceDirectories();
Expand Down Expand Up @@ -364,7 +366,6 @@ public final LinkerDef getLinker(final AbstractCompileMojo mojo, final CCTask ta
arg2.setValue("/MANIFESTFILE:" + task.getOutfile() + ".manifest");
linker.addConfiguredLinkerArg(arg2);
}

}

// Add options to linker
Expand Down Expand Up @@ -552,11 +553,7 @@ public final String getVersion(final AbstractNarMojo mojo) throws MojoFailureExc
}

String version = null;
String linkerPrefix = "";

if (this.prefix != null && (!this.prefix.isEmpty())) {
linkerPrefix = this.prefix;
}
final String linkerPrefix = nullToEmpty(this.prefix);

final TextStream out = new StringTextStream();
final TextStream err = new StringTextStream();
Expand Down Expand Up @@ -628,7 +625,7 @@ public final String getVersion(final AbstractNarMojo mojo) throws MojoFailureExc
version = m.group(0);
}
} else {
if (!this.prefix.isEmpty()) {
if (!linkerPrefix.isEmpty()) {
NarUtil.runCommand(linkerPrefix+this.name, new String[] {
"--version"
}, null, null, out, err, dbg, this.log);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/github/maven_nar/cpptasks/CUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.util.StringUtils;

/**
* Some utilities used by the CC and Link tasks.
Expand Down Expand Up @@ -421,7 +419,8 @@ public static int runCommand(final CCTask task, final File workingDir, final Str
return exe.execute();
*/

return CommandExecution.runCommand(cmdline,workingDir,task,env.getVariablesVector());
return CommandExecution.runCommand(cmdline, workingDir, task,
env == null ? new Vector<Environment.Variable>() : env.getVariablesVector());
} catch (final java.io.IOException exc) {
throw new BuildException("Could not launch " + cmdline[0] + ": " + exc, task.getLocation());
}
Expand Down Expand Up @@ -502,14 +501,14 @@ public static String[] toArray(final Vector src) {

public static String toUnixPath(final String path) {
if (File.separatorChar != '/' && path.indexOf(File.separatorChar) != -1) {
return StringUtils.replace(path, File.separator, "/");
return path.replace(File.separator, "/");
}
return path;
}

public static String toWindowsPath(final String path) {
if (File.separatorChar != '\\' && path.indexOf(File.separatorChar) != -1) {
return StringUtils.replace(path, File.separator, "\\");
return path.replace(File.separator, "\\");
}
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public String toRemote(final String host, final File localFile) {
if (this.remoteName != null && (this.hosts == null || this.hosts.contains(host))) {
try {
final String canonical = localFile.getCanonicalPath();
if (canonical.startsWith(this.canonicalPath) && isActive()) {
if (localFile.getCanonicalFile().toPath().startsWith(this.canonicalPath) && isActive()) {
return this.remoteName
+ canonical.substring(this.canonicalPath.length()).replace(File.separatorChar, this.remoteSeparator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class GccLinker extends AbstractLdLinker {
"-bundle",
// FREEHEP
"-dynamic", "-arch", "-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s", "-static", "-shared",
"-symbolic", "-Xlinker", "--export-all-symbols", "-static-libgcc", "-p", "-pg", "-pthread"
"-symbolic", "-Xlinker", "--export-all-symbols", "-static-libgcc", "-p", "-pg", "-pthread",
// Regex based
"-specs=.*", "-std=.*", "--specs=.*", "--std=.*"
};
// FREEHEP refactored dllLinker to soLinker
private static final GccLinker soLinker = new GccLinker("gcc", objFiles, discardFiles, "lib", ".so", false,
Expand Down Expand Up @@ -125,7 +127,7 @@ public String decorateLinkerOption(final StringBuffer buf, final String arg) {
default:
boolean known = false;
for (final String linkerOption : linkerOptions) {
if (linkerOption.equals(arg)) {
if (arg.matches(linkerOption)) {
known = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class GppLinker extends AbstractLdLinker {
};
private static String[] linkerOptions = new String[] {
"-bundle", "-dylib", "-dynamic", "-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s", "-static",
"-shared", "-symbolic", "-Xlinker", "-static-libgcc", "-shared-libgcc", "-p", "-pg", "-pthread"
"-shared", "-symbolic", "-Xlinker", "-static-libgcc", "-shared-libgcc", "-p", "-pg", "-pthread",
// Regex based
"-specs=.*", "-std=.*", "--specs=.*", "--std=.*"
};
// FREEHEP refactored dllLinker into soLinker
private static final GppLinker soLinker = new GppLinker(GPP_COMMAND, objFiles, discardFiles, "lib", ".so", false,
Expand Down Expand Up @@ -230,7 +232,7 @@ public String decorateLinkerOption(final StringBuffer buf, final String arg) {
default:
boolean known = false;
for (final String linkerOption : linkerOptions) {
if (linkerOption.equals(arg)) {
if (arg.matches(linkerOption)) {
known = true;
break;
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/resources/com/github/maven_nar/aol.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1321,3 +1321,38 @@ ppc64.AIX.gcc.plugin.extension=a
ppc64.AIX.gcc.jni.extension=a
ppc64.AIX.gcc.executable.extension=
#

# loongarch64 Linux
#
loongarch64.Linux.linker=g++

loongarch64.Linux.gpp.cpp.compiler=g++
loongarch64.Linux.gpp.cpp.defines=Linux GNU_GCC
loongarch64.Linux.gpp.cpp.options=-Wall -Wno-long-long -Wpointer-arith -Wconversion -fPIC
loongarch64.Linux.gpp.cpp.includes=**/*.cc **/*.cpp **/*.cxx
loongarch64.Linux.gpp.cpp.excludes=

loongarch64.Linux.gpp.c.compiler=gcc
loongarch64.Linux.gpp.c.defines=Linux GNU_GCC
loongarch64.Linux.gpp.c.options=-Wall -Wno-long-long -Wpointer-arith -Wconversion -fPIC
loongarch64.Linux.gpp.c.includes=**/*.c
loongarch64.Linux.gpp.c.excludes=

loongarch64.Linux.gpp.fortran.compiler=gfortran
loongarch64.Linux.gpp.fortran.defines=Linux GNU_GCC
loongarch64.Linux.gpp.fortran.options=-Wall
loongarch64.Linux.gpp.fortran.includes=**/*.f **/*.for **/*.f90
loongarch64.Linux.gpp.fortran.excludes=

loongarch64.Linux.gpp.java.include=include;include/linux
#loongarch64.Linux.gpp.java.runtimeDirectory=jre/lib/loongarch64/server
loongarch64.Linux.gpp.java.runtimeDirectory=IGNORED

looongarch64.Linux.gpp.lib.prefix=lib
loongarch64.Linux.gpp.shared.prefix=lib
loongarch64.Linux.gpp.static.extension=a
looongarch64.Linux.gpp.shared.extension=so*
loongarch64.Linux.gpp.plugin.extension=so
loongarch64.Linux.gpp.jni.extension=so
loongarch64.Linux.gpp.executable.extension=

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import junit.framework.TestCase;

Expand All @@ -45,9 +46,7 @@ public abstract class TestXMLConsumer extends TestCase {
public static void copyResourceToTmpDir(final String resourceName, final String tmpFile) throws IOException {
String tmpDir = System.getProperty("java.io.tmpdir");

final File tempdir = File.createTempFile(tmpFile, Long.toString(System.nanoTime()), new File(tmpDir));
tempdir.delete();
tempdir.mkdir();
final File tempdir = Files.createTempDirectory(new File(tmpDir).toPath(), tmpFile + Long.toString(System.nanoTime())).toFile();
tempdir.deleteOnExit();
tmpDir = tempdir.getAbsolutePath();
//
Expand Down

0 comments on commit 5672623

Please sign in to comment.