Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A fix to "NAR: Compile failed: Output filename conflict" #178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/java/com/github/maven_nar/cpptasks/TargetMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Vector;

import org.apache.tools.ant.BuildException;
import org.apache.commons.io.FilenameUtils;

import com.github.maven_nar.cpptasks.compiler.LinkerConfiguration;
import com.github.maven_nar.cpptasks.compiler.ProcessorConfiguration;
Expand Down Expand Up @@ -99,10 +100,14 @@ public void visit(final File parentDir, final String filename) throws BuildExcep
//
// see if the same output file has already been registered
//
final TargetInfo previousTarget = this.targets.get(outputFileName);
StringBuffer sb = new StringBuffer( FilenameUtils.removeExtension(outputFileName) );
sb.append( fullPath.getAbsolutePath().hashCode() + "." + FilenameUtils.getExtension(outputFileName) );
String newOutputFileName = sb.toString();

final TargetInfo previousTarget = this.targets.get(newOutputFileName);
if (previousTarget == null) {
this.targets.put(outputFileName, new TargetInfo(selectedCompiler, this.sourceFiles, null, new File(
this.outputDir, outputFileName), selectedCompiler.getRebuild()));
this.targets.put(newOutputFileName, new TargetInfo(selectedCompiler, this.sourceFiles, null, new File(
this.outputDir, newOutputFileName), selectedCompiler.getRebuild()));
} else {
if (!previousTarget.getSources()[0].equals(this.sourceFiles[0])) {
final StringBuffer builder = new StringBuffer("Output filename conflict: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,8 @@ protected boolean resolveInclude(final String includeName, final File[] includeP
}
return false;
}

public final String getOutputSuffix() {
return this.outputSuffix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Environment;
import org.apache.commons.io.FilenameUtils;

import com.github.maven_nar.NarUtil;
import com.github.maven_nar.cpptasks.CCTask;
Expand Down Expand Up @@ -188,7 +189,8 @@ public void compile(final CCTask task, final File outputDir, final String[] sour
if (firstFileNextExec == sourceIndex) {
throw new BuildException("Extremely long file name, can't fit on command line");
}
int argCount = args.length + 1 + endArgs.length + (firstFileNextExec - sourceIndex) * argumentCountPerInputFile;
// int argCount = args.length + 1 + endArgs.length + (firstFileNextExec - sourceIndex) * argumentCountPerInputFile;
int argCount = args.length + 1 + endArgs.length + 3;
if (this.libtool) {
argCount++;
}
Expand All @@ -208,15 +210,28 @@ public void compile(final CCTask task, final File outputDir, final String[] sour
for (final String arg : args) {
commandline[index++] = arg;
}
for (int j = sourceIndex; j < firstFileNextExec; j++) {
for (int k = 0; k < argumentCountPerInputFile; k++) {
commandline[index++] = getInputFileArgument(outputDir, sourceFiles[j], k);
}
}
for (final String endArg : endArgs) {
commandline[index++] = endArg;
}
final int retval = runCommand(task, outputDir, commandline);
int anchor = index;
int retval = 0;
for (int j = sourceIndex; j < firstFileNextExec; j++) {
index = anchor;
commandline[index++] = "-o";

StringBuffer sb = new StringBuffer( FilenameUtils.getBaseName(sourceFiles[j]) );
sb.append( sourceFiles[j].hashCode() + getOutputSuffix());
final String newOutputFileName = sb.toString();

commandline[index++] = newOutputFileName;

// for (int k = 0; k < argumentCountPerInputFile; k++) {
commandline[index++] = getInputFileArgument(outputDir, sourceFiles[j], 0);
// }
final int ret = runCommand(task, outputDir, commandline);
if (ret != 0) retval = ret;
}
// final int retval = runCommand(task, outputDir, commandline);
if (monitor != null) {
final String[] fileNames = new String[firstFileNextExec - sourceIndex];

Expand Down