1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

bug 232373: cdt generated make file has options with no spaces between option and argument

This commit is contained in:
Andrew Gvozdev 2010-10-24 04:06:38 +00:00
parent 7e83139fba
commit c1d17327f3
88 changed files with 185 additions and 209 deletions

View file

@ -39,6 +39,7 @@ public class ManagedCommandLineGeneratorTest extends TestCase {
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}",
"${command} ${flags} ${output_flag}${output_prefix}${output} ${WRONG_VAR_NAME}"
};
@ -51,12 +52,13 @@ public class ManagedCommandLineGeneratorTest extends TestCase {
private static String INPUTS_VAL = "[inputs]";
private static String[] INPUTS_ARRAY_VAL = INPUTS_VAL.split( "\\s" );
private static String[] commandLineEtalonesForPatterns = {
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"" + " " + "\"" + INPUTS_VAL + "\"",
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + " " + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"" + " " + "\"" + INPUTS_VAL + "\"",
COMMAND_VAL,
COMMAND_VAL + " " + FLAGS_VAL,
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL,
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + OUTPUT_PREFIX_VAL,
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"",
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + " " + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"",
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"" + " " + "\"" + INPUTS_VAL + "\"",
COMMAND_VAL + " " + FLAGS_VAL + " " + OUTPUT_FLAG_VAL + OUTPUT_PREFIX_VAL + "\"" + OUTPUT_VAL + "\"" + " " + "${WRONG_VAR_NAME}" };
@ -65,13 +67,7 @@ public class ManagedCommandLineGeneratorTest extends TestCase {
}
public static Test suite() {
TestSuite suite = new TestSuite( ManagedCommandLineGeneratorTest.class.getName() );
suite.addTest( new ManagedCommandLineGeneratorTest( "testGetCommandLineGenerator" ) );
suite.addTest( new ManagedCommandLineGeneratorTest( "testGenerateCommandLineInfoPatterns" ) );
suite.addTest( new ManagedCommandLineGeneratorTest( "testGenerateCommandLineInfoParameters" ) );
suite.addTest( new ManagedCommandLineGeneratorTest( "testCustomGenerator" ) );
suite.addTest( new ManagedCommandLineGeneratorTest( "testDollarValue" ) );
return suite;
return new TestSuite(ManagedCommandLineGeneratorTest.class);
}
public final void testGetCommandLineGenerator() {
@ -92,16 +88,25 @@ public class ManagedCommandLineGeneratorTest extends TestCase {
}
}
public final void testGenerateCommandLineInfoDoublePattern() {
IManagedCommandLineGenerator gen = ManagedCommandLineGenerator.getCommandLineGenerator();
IManagedCommandLineInfo info = gen.generateCommandLineInfo( null, COMMAND_VAL, FLAGS_ARRAY_VAL, OUTPUT_FLAG_VAL, OUTPUT_PREFIX_VAL, OUTPUT_VAL, INPUTS_ARRAY_VAL,
"${OUTPUT_FLAG} ${OUTPUT_FLAG}" );
assertNotNull( info );
assertEquals(OUTPUT_FLAG_VAL+" "+OUTPUT_FLAG_VAL, info.getCommandLine());
}
public final void testGenerateCommandLineInfoParameters() {
IManagedCommandLineGenerator gen = ManagedCommandLineGenerator.getCommandLineGenerator();
IManagedCommandLineInfo info = gen.generateCommandLineInfo( null, "", FLAGS_ARRAY_VAL, OUTPUT_FLAG_VAL, OUTPUT_PREFIX_VAL, OUTPUT_VAL, INPUTS_ARRAY_VAL, null );
assertNotNull( info );
assertEquals(FLAGS_VAL+" "+OUTPUT_FLAG_VAL+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
assertEquals(FLAGS_VAL+" "+OUTPUT_FLAG_VAL+" "+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
info = gen.generateCommandLineInfo( null, COMMAND_VAL, new String[0], OUTPUT_FLAG_VAL, OUTPUT_PREFIX_VAL, OUTPUT_VAL, INPUTS_ARRAY_VAL, null );
assertNotNull( info );
assertEquals(COMMAND_VAL+" "+OUTPUT_FLAG_VAL+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
assertEquals(COMMAND_VAL+" "+OUTPUT_FLAG_VAL+" "+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
info = gen.generateCommandLineInfo( null, COMMAND_VAL, FLAGS_ARRAY_VAL, "", OUTPUT_PREFIX_VAL, OUTPUT_VAL, INPUTS_ARRAY_VAL, null );
assertNotNull( info );
@ -109,15 +114,15 @@ public class ManagedCommandLineGeneratorTest extends TestCase {
info = gen.generateCommandLineInfo( null, COMMAND_VAL, FLAGS_ARRAY_VAL, OUTPUT_FLAG_VAL, "", OUTPUT_VAL, INPUTS_ARRAY_VAL, null );
assertNotNull( info );
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL + "\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL+" "+"\""+OUTPUT_VAL + "\""+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
info = gen.generateCommandLineInfo( null, COMMAND_VAL, FLAGS_ARRAY_VAL, OUTPUT_FLAG_VAL, OUTPUT_PREFIX_VAL, "", INPUTS_ARRAY_VAL, null );
assertNotNull( info );
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL+OUTPUT_PREFIX_VAL+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL+" "+OUTPUT_PREFIX_VAL+" " + "\""+INPUTS_VAL + "\"", info.getCommandLine());
info = gen.generateCommandLineInfo( null, COMMAND_VAL, FLAGS_ARRAY_VAL, OUTPUT_FLAG_VAL, OUTPUT_PREFIX_VAL, OUTPUT_VAL, new String[0], null );
assertNotNull( info );
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\"", info.getCommandLine());
assertEquals(COMMAND_VAL+" "+FLAGS_VAL+" "+OUTPUT_FLAG_VAL+" "+OUTPUT_PREFIX_VAL + "\""+OUTPUT_VAL + "\"", info.getCommandLine());
}
public final void testCustomGenerator() {

View file

@ -57,6 +57,10 @@ public class ManagedCommandLineGenerator implements
return cmdLineGen;
}
private String makeVariable(String variableName) {
return "${"+variableName+"}"; //$NON-NLS-1$ //$NON-NLS-2$
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator#getCommandLineInfo(org.eclipse.cdt.managedbuilder.core.ITool, java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String[], java.lang.String)
*/
@ -65,77 +69,44 @@ public class ManagedCommandLineGenerator implements
String outputPrefix, String outputName,
String[] inputResources, String commandLinePattern)
{
StringBuffer sb = new StringBuffer();
if( commandLinePattern == null || commandLinePattern.length() <= 0 )
commandLinePattern = Tool.DEFAULT_PATTERN;
/*
sb.append( commandName + WHITESPACE + stringArrayToString( flags ) + WHITESPACE + outputFlag + WHITESPACE + outputPrefix +
outputName + WHITESPACE + stringArrayToString( inputResources ) );
else {
*/
int start = 0;
int stop = 0;
while( (start = commandLinePattern.indexOf( VAR_FIRST_CHAR, start )) >= 0 ) {
if( commandLinePattern.charAt( start + 1 ) != VAR_SECOND_CHAR ) {
sb.append(VAR_FIRST_CHAR);
start++;
continue;
}
if( start > stop ) {
sb.append( commandLinePattern.substring(stop, start) );
}
stop = commandLinePattern.indexOf( VAR_FINAL_CHAR, start + 1 );
if( stop > 0 && stop <= commandLinePattern.length() ) try {
String varName = commandLinePattern.substring( start+2, stop ).trim();
if( varName.compareToIgnoreCase( CMD_LINE_PRM_NAME ) == 0 ) sb.append( commandName.trim() );
else if( varName.compareToIgnoreCase( FLAGS_PRM_NAME ) == 0 ) sb.append( stringArrayToString( flags ) );
else if( varName.compareToIgnoreCase( OUTPUT_FLAG_PRM_NAME ) == 0 ) sb.append( outputFlag.trim() );
else if( varName.compareToIgnoreCase( OUTPUT_PREFIX_PRM_NAME ) == 0 ) sb.append( outputPrefix.trim() );
else if( varName.compareToIgnoreCase( OUTPUT_PRM_NAME ) == 0 )
{
StringBuffer tempBuffer = new StringBuffer(EMPTY);
if(!outputName.equals(EMPTY))
{
// if the output name isn't a variable then quote it
if(outputName.indexOf("$(") != 0) //$NON-NLS-1$
tempBuffer.append( DOUBLE_QUOTE + outputName + DOUBLE_QUOTE);
else
tempBuffer.append(outputName);
}
if(outputName.length()>0 && outputName.indexOf("$(") != 0) //$NON-NLS-1$
outputName = DOUBLE_QUOTE + outputName + DOUBLE_QUOTE;
sb.append(tempBuffer.toString().trim());
}
else if( varName.compareToIgnoreCase( INPUTS_PRM_NAME ) == 0 &&
(inputResources != null)){
StringBuffer tempBuffer = new StringBuffer(EMPTY);
for(int k = 0; k < inputResources.length; k++)
{
if(!inputResources[k].equals(EMPTY))
{
String inputsStr=""; //$NON-NLS-1$
for (String inp : inputResources) {
if(inp!=null && inp.length()>0) {
// if the input resource isn't a variable then quote it
if(inputResources[k].indexOf("$(") != 0) //$NON-NLS-1$
tempBuffer.append(DOUBLE_QUOTE + inputResources[k] + DOUBLE_QUOTE + WHITESPACE);
else
tempBuffer.append(inputResources[k] + WHITESPACE);
if(inp.indexOf("$(") != 0) { //$NON-NLS-1$
inp = DOUBLE_QUOTE + inp + DOUBLE_QUOTE;
}
inputsStr = inputsStr + inp + WHITESPACE;
}
}
inputsStr = inputsStr.trim();
sb.append(tempBuffer.toString().trim());
String flagsStr = stringArrayToString(flags);
}
else sb.append( VAR_FIRST_CHAR + VAR_SECOND_CHAR + varName + VAR_FINAL_CHAR );
} catch( Exception ex ) {
// do nothing for a while
}
start = ++stop;
// }
}
if (stop<commandLinePattern.length()){
sb.append(commandLinePattern.substring(stop));
}
String command = commandLinePattern;
return new ManagedCommandLineInfo( sb.toString().trim(), commandLinePattern, commandName, stringArrayToString( flags ),
command = command.replace(makeVariable(CMD_LINE_PRM_NAME), commandName);
command = command.replace(makeVariable(FLAGS_PRM_NAME), flagsStr);
command = command.replace(makeVariable(OUTPUT_FLAG_PRM_NAME), outputFlag);
command = command.replace(makeVariable(OUTPUT_PREFIX_PRM_NAME), outputPrefix);
command = command.replace(makeVariable(OUTPUT_PRM_NAME), outputName);
command = command.replace(makeVariable(INPUTS_PRM_NAME), inputsStr);
command = command.replace(makeVariable(CMD_LINE_PRM_NAME.toLowerCase()), commandName);
command = command.replace(makeVariable(FLAGS_PRM_NAME.toLowerCase()), flagsStr);
command = command.replace(makeVariable(OUTPUT_FLAG_PRM_NAME.toLowerCase()), outputFlag);
command = command.replace(makeVariable(OUTPUT_PREFIX_PRM_NAME.toLowerCase()), outputPrefix);
command = command.replace(makeVariable(OUTPUT_PRM_NAME.toLowerCase()), outputName);
command = command.replace(makeVariable(INPUTS_PRM_NAME.toLowerCase()), inputsStr);
return new ManagedCommandLineInfo(command.trim(), commandLinePattern, commandName, stringArrayToString(flags),
outputFlag, outputPrefix, outputName, stringArrayToString(inputResources));
}