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

allow compilation of files with same names #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
64 changes: 30 additions & 34 deletions src/main/java/com/github/maven_nar/cpptasks/TargetMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -55,6 +55,7 @@ public TargetMatcher(CCTask task, File outputDir,
}
public void visit(File parentDir, String filename) throws BuildException {
File fullPath = new File(parentDir, filename);
int hash = Math.abs(fullPath.getPath().hashCode());
//
// see if any processor wants to bid
// on this one
Expand Down Expand Up @@ -84,41 +85,36 @@ public void visit(File parentDir, String filename) throws BuildException {
}
}
} else {
//
// get output file name
//
String[] outputFileNames = selectedCompiler
.getOutputFileNames(filename, versionInfo);
sourceFiles[0] = fullPath;
//
// if there is some output for this task
// (that is a source file and not an header file)
//
for (int i = 0; i < outputFileNames.length; i++) {
//
// see if the same output file has already been registered
// get output file name
//
String[] outputFileNames = selectedCompiler
.getOutputFileNames(filename, versionInfo);
sourceFiles[0] = fullPath;

//
// if there is some output for this task
// (that is a source file and not an header file)
//
TargetInfo previousTarget = (TargetInfo) targets
.get(outputFileNames[i]);
if (previousTarget == null) {
targets.put(outputFileNames[i], new TargetInfo(
for (int i = 0; i < outputFileNames.length; i++) {
//
// see if the same output file has already been registered
//
TargetInfo previousTarget = (TargetInfo) targets
.get(outputFileNames[i]);

String ext = outputFileNames[i].substring(outputFileNames[i].lastIndexOf('.'),outputFileNames[i].length());
StringBuffer nf = new StringBuffer(outputFileNames[i].substring(0, outputFileNames[i].lastIndexOf('.')));
nf.append(hash + ext);

outputFileNames[i] = nf.toString();

targets.put(outputFileNames[i], new TargetInfo(
selectedCompiler, sourceFiles, null, new File(
outputDir, outputFileNames[i]),
selectedCompiler.getRebuild()));
} else {
if (!previousTarget.getSources()[0].equals(sourceFiles[0])) {
StringBuffer builder = new StringBuffer(
"Output filename conflict: ");
builder.append(outputFileNames[i]);
builder.append(" would be produced from ");
builder.append(previousTarget.getSources()[0]
.toString());
builder.append(" and ");
builder.append(filename);
throw new BuildException(builder.toString());
}
}
}
outputDir, outputFileNames[i]),
selectedCompiler.getRebuild()));

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -208,4 +208,7 @@ protected boolean resolveInclude(String includeName, File[] includePath,
}
return false;
}
public String getOutputSuffix() {
return outputSuffix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import java.util.ArrayList;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Environment;
Expand All @@ -39,7 +40,7 @@
/**
* An abstract Compiler implementation which uses an external program to
* perform the compile.
*
*
* @author Adam Murdoch
*/
public abstract class CommandLineCompiler extends AbstractCompiler {
Expand Down Expand Up @@ -73,11 +74,11 @@ abstract protected void addImpliedArgs(Vector<String> args, boolean debug,
Boolean rtti, OptimizationEnum optimization);
/**
* Adds command-line arguments for include directories.
*
*
* If relativeArgs is not null will add corresponding relative paths
* include switches to that vector (for use in building a configuration
* identifier that is consistent between machines).
*
*
* @param baseDirPath Base directory path.
* @param includeDirs
* Array of include directory paths
Expand Down Expand Up @@ -134,7 +135,7 @@ protected void buildDefineArguments(CompilerDef[] defs, Vector<String> args) {
}
/**
* Compiles a source file.
*
*
*/
public void compile(CCTask task, File outputDir, String[] sourceFiles,
String[] args, String[] endArgs, boolean relentless,
Expand Down Expand Up @@ -184,25 +185,27 @@ public void compile(CCTask task, File outputDir, String[] sourceFiles,
if (libtool) {
argCount++;
}
String[] commandline = new String[argCount];
ArrayList<String> commandline = new ArrayList<String>();
int index = 0;
if (libtool) {
commandline[index++] = "libtool";
commandline.add("libtool");
}
commandline[index++] = command;
commandline.add(command);
for (int j = 0; j < args.length; j++) {
commandline[index++] = args[j];
commandline.add(args[j]);
}
for (int j = sourceIndex; j < firstFileNextExec; j++) {
for (int k = 0; k < argumentCountPerInputFile; k++) {
commandline[index++] = getInputFileArgument(outputDir,
sourceFiles[j], k);
commandline.add(getInputFileArgument(outputDir, sourceFiles[j], k));
}
}
for (int j = 0; j < endArgs.length; j++) {
commandline[index++] = endArgs[j];
commandline.add(endArgs[j]);
}
int retval = runCommand(task, outputDir, commandline);
commandline.add("-o");
File ff = new File(sourceFiles[sourceIndex]);
commandline.add(ff.getName().replaceFirst("[.][^.]+$", "") + Math.abs(sourceFiles[sourceIndex].hashCode()) + config.getOutputSuffix());
int retval = runCommand(task, outputDir, commandline.toArray(new String[commandline.size()]));
if (monitor != null) {
String[] fileNames = new String[firstFileNextExec - sourceIndex];

Expand Down Expand Up @@ -240,8 +243,8 @@ public void compile(CCTask task, File outputDir, String[] sourceFiles,
}
}
protected CompilerConfiguration createConfiguration(final CCTask task,
final LinkType linkType,
final ProcessorDef[] baseDefs,
final LinkType linkType,
final ProcessorDef[] baseDefs,
final CompilerDef specificDef,
final TargetDef targetPlatform,
final VersionInfo versionInfo) {
Expand Down Expand Up @@ -417,17 +420,17 @@ public String getIdentifier() {
return identifier;
}
abstract protected String getIncludeDirSwitch(String source);

/**
* Added by Darren Sargent 22Oct2008 Returns the include dir switch value.
* Default implementation doesn't treat system includes specially, for
* compilers which don't care.
*
*
* @param source
* the given source value.
* @param isSystem
* "true" if this is a system include path
*
*
* @return the include dir switch value.
*/
protected String getIncludeDirSwitch(String source, boolean isSystem) {
Expand All @@ -451,7 +454,7 @@ protected final boolean getLibtool() {
}
/**
* Obtains the same compiler, but with libtool set
*
*
* Default behavior is to ignore libtool
*/
public final CommandLineCompiler getLibtoolCompiler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -30,7 +30,7 @@
import com.github.maven_nar.cpptasks.VersionInfo;
/**
* A configuration for a C++ compiler
*
*
* @author Curt Arnold
*/
public final class CommandLineCompilerConfiguration
Expand Down Expand Up @@ -158,23 +158,23 @@ public void compile(CCTask task, File outputDir, String[] sourceFiles,
}
}
/**
*
*
* This method may be used to get two distinct compiler configurations, one
* for compiling the specified file and producing a precompiled header
* file, and a second for compiling other files using the precompiled
* header file.
*
*
* The last (preferrably only) include directive in the prototype file will
* be used to mark the boundary between pre-compiled and normally compiled
* headers.
*
*
* @param prototype
* A source file (for example, stdafx.cpp) that is used to build
* the precompiled header file. @returns null if precompiled
* headers are not supported or a two element array containing
* the precompiled header generation configuration and the
* consuming configuration
*
*
*/
public CompilerConfiguration[] createPrecompileConfigurations(
File prototype, String[] nonPrecompiledFiles) {
Expand Down Expand Up @@ -244,4 +244,7 @@ public final void setCommandPath(String commandPath) {
public final String getCommandPath() {
return this.commandPath;
}
public String getOutputSuffix() {
return compiler.getOutputSuffix();
}
}