Skip to content

Commit efa335d

Browse files
committed
build: -T macro before whitespace
- on windows, add double quotes for the entire string
1 parent 75204a0 commit efa335d

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

ilg.gnuarmeclipse.managedbuild.cross/src/ilg/gnuarmeclipse/managedbuild/cross/LikerScriptCommandGenerator.java

+21-17
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
package ilg.gnuarmeclipse.managedbuild.cross;
1313

14+
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
1415
import org.eclipse.cdt.managedbuilder.core.BuildException;
1516
import org.eclipse.cdt.managedbuilder.core.IOption;
1617
import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator;
1718
import org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator;
19+
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
1820
import org.eclipse.cdt.utils.cdtvariables.IVariableSubstitutor;
1921

2022
public class LikerScriptCommandGenerator implements IOptionCommandGenerator {
@@ -23,17 +25,20 @@ public class LikerScriptCommandGenerator implements IOptionCommandGenerator {
2325
public String generateCommand(IOption option,
2426
IVariableSubstitutor macroSubstitutor) {
2527

26-
String command = null;
28+
StringBuffer command = new StringBuffer();
2729
try {
2830
int valueType = option.getValueType();
2931

3032
if (valueType == IOption.STRING) {
3133
// for compatibility with projects created with previous
3234
// versions, keep accepting single strings
33-
command = "-T "
34-
+ GnuMakefileGenerator
35-
.escapeWhitespaces(GnuMakefileGenerator
36-
.ensureUnquoted(option.getStringValue()));
35+
36+
String value = option.getStringValue();
37+
value = CdtVariableResolver.resolveToString(value,
38+
macroSubstitutor);
39+
40+
command.append("-T ");
41+
command.append(Utils.escapeWhitespaces(value));
3742
} else if (valueType == IOption.STRING_LIST) {
3843
for (String value : option.getStringListValue()) {
3944

@@ -42,25 +47,24 @@ public String generateCommand(IOption option,
4247
}
4348

4449
if (value.length() > 0) {
45-
if (command == null)
46-
command = "";
4750

48-
command += "-T "
49-
+ GnuMakefileGenerator
50-
.escapeWhitespaces(GnuMakefileGenerator
51-
.ensureUnquoted(value)) + " ";
51+
value = CdtVariableResolver.resolveToString(value,
52+
macroSubstitutor);
53+
command.append("-T ");
54+
command.append(Utils.escapeWhitespaces(value));
55+
command.append(" ");
5256
}
5357
}
54-
}
58+
}
5559
} catch (BuildException e) {
5660
// TODO Auto-generated catch block
5761
e.printStackTrace();
62+
} catch (CdtVariableException e) {
63+
// TODO Auto-generated catch block
64+
e.printStackTrace();
5865
}
59-
60-
if (command != null)
61-
command = command.trim();
62-
63-
return command;
66+
67+
return command.toString().trim();
6468
}
6569

6670
}

ilg.gnuarmeclipse.managedbuild.cross/src/ilg/gnuarmeclipse/managedbuild/cross/Utils.java

+33
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ public class Utils {
2929
+ ".staticLib";
3030

3131
private static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$
32+
public static final String PROPERTY_OS_VALUE_WINDOWS = "windows";//$NON-NLS-1$
33+
public static final String PROPERTY_OS_VALUE_LINUX = "linux";//$NON-NLS-1$
34+
public static final String PROPERTY_OS_VALUE_MACOSX = "macosx";//$NON-NLS-1$
3235

3336
public static boolean isPlatform(String sPlatform) {
3437
return (System.getProperty(PROPERTY_OS_NAME).toLowerCase()
3538
.startsWith(sPlatform));
3639
}
3740

41+
static public boolean isWindows() {
42+
return System.getProperty(PROPERTY_OS_NAME).toLowerCase()
43+
.startsWith(PROPERTY_OS_VALUE_WINDOWS);
44+
}
45+
3846
/**
3947
* Extracts a resource info from a build object. If no resource info can be
4048
* found, it returns null.
@@ -100,4 +108,29 @@ public static IOption forceOptionRewrite(IConfiguration config,
100108
return config.setOption(toolchain, newOption, value);
101109
}
102110

111+
static public String escapeWhitespaces(String path) {
112+
path = path.trim();
113+
// Escape the spaces in the path/filename if it has any
114+
String[] segments = path.split("\\s"); //$NON-NLS-1$
115+
if (segments.length > 1) {
116+
if (isWindows()) {
117+
if (path.startsWith("\"") || path.startsWith("'"))
118+
return path;
119+
120+
return "\"" + path + "\"";
121+
} else {
122+
StringBuffer escapedPath = new StringBuffer();
123+
for (int index = 0; index < segments.length; ++index) {
124+
escapedPath.append(segments[index]);
125+
if (index + 1 < segments.length) {
126+
escapedPath.append("\\ "); //$NON-NLS-1$
127+
}
128+
}
129+
return escapedPath.toString().trim();
130+
}
131+
} else {
132+
return path;
133+
}
134+
}
135+
103136
}

0 commit comments

Comments
 (0)