Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn SVENSSON2021-02-23 11:47:44 -0500
committerTorbjörn Svensson2021-02-26 14:47:34 -0500
commit0ca137e8540f773f6ab8d0190d5802c70fc7f456 (patch)
tree692affd793f99241b739a974c0a21420f6fc52e6 /build/org.eclipse.cdt.managedbuilder.core/src/org
parentcdd00392c1d1843c1123785a2b3ea823846e6455 (diff)
downloadorg.eclipse.cdt-0ca137e8540f773f6ab8d0190d5802c70fc7f456.tar.gz
org.eclipse.cdt-0ca137e8540f773f6ab8d0190d5802c70fc7f456.tar.xz
org.eclipse.cdt-0ca137e8540f773f6ab8d0190d5802c70fc7f456.zip
Bug 571433: Make ManagedCommandLineGenerator API
Allow extenders to extend the ManagedCommandLineGenerator in order to add options that are placed on the toolchain node instead of the tool. Contributed by STMicroelectronics Change-Id: I548bcbf72f1290cd4bc0ce830c27ce032a62c9c9 Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core/src/org')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedCommandLineInfo.java2
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java5
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java3
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedCommandLineGenerator.java141
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineGenerator.java69
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineInfo.java4
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiFileInfo.java6
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java1
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java3
9 files changed, 169 insertions, 65 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedCommandLineInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedCommandLineInfo.java
index 4cfce2cdbca..8fc0d3cb609 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedCommandLineInfo.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedCommandLineInfo.java
@@ -41,7 +41,9 @@ public interface IManagedCommandLineInfo {
/**
* provide list of resources used by tool for transformation
+ * @deprecated Useless method that does not handle whitespace properly.
*/
+ @Deprecated
public String getInputs();
/**
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java
index 83e88e6a084..0a3b9e2becb 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceConfiguration.java
@@ -228,4 +228,9 @@ public interface IResourceConfiguration extends IResourceInfo {
void setRebuildState(boolean rebuild);
void setTools(ITool[] tools);
+
+ /**
+ * @since 9.2
+ */
+ IToolChain getBaseToolChain();
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
index 59664032625..5708e0d9904 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
@@ -88,7 +88,6 @@ import org.eclipse.cdt.managedbuilder.internal.core.FolderInfo;
import org.eclipse.cdt.managedbuilder.internal.core.IMatchKeyProvider;
import org.eclipse.cdt.managedbuilder.internal.core.InputType;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
-import org.eclipse.cdt.managedbuilder.internal.core.ManagedCommandLineGenerator;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.internal.core.MatchKey;
@@ -787,7 +786,7 @@ public class ManagedBuildManager extends AbstractCExtension {
if (tool != null) {
return tool.getCommandLineGenerator();
}
- return ManagedCommandLineGenerator.getCommandLineGenerator();
+ return new ManagedCommandLineGenerator();
}
/**
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedCommandLineGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedCommandLineGenerator.java
new file mode 100644
index 00000000000..89bdfb7d9be
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedCommandLineGenerator.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2016 Intel Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.core;
+
+import org.eclipse.cdt.managedbuilder.internal.core.Tool;
+
+/**
+ * @since 9.2
+ */
+public class ManagedCommandLineGenerator implements IManagedCommandLineGenerator {
+
+ private static final String DOUBLE_QUOTE = "\""; //$NON-NLS-1$
+ private static final String WHITESPACE = " "; //$NON-NLS-1$
+
+ private static final String CMD_LINE_PRM_NAME = "COMMAND"; //$NON-NLS-1$
+ private static final String FLAGS_PRM_NAME = "FLAGS"; //$NON-NLS-1$
+ private static final String OUTPUT_FLAG_PRM_NAME = "OUTPUT_FLAG"; //$NON-NLS-1$
+ private static final String OUTPUT_PREFIX_PRM_NAME = "OUTPUT_PREFIX"; //$NON-NLS-1$
+ private static final String OUTPUT_PRM_NAME = "OUTPUT"; //$NON-NLS-1$
+ private static final String INPUTS_PRM_NAME = "INPUTS"; //$NON-NLS-1$
+
+ private String makeVariable(String variableName) {
+ return "${" + variableName + "}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ public IManagedCommandLineInfo generateCommandLineInfo(ITool tool, String commandName, String[] flags,
+ String outputFlag, String outputPrefix, String outputName, String[] inputResources,
+ String commandLinePattern) {
+ if (commandLinePattern == null || commandLinePattern.length() <= 0) {
+ commandLinePattern = Tool.DEFAULT_PATTERN;
+ }
+
+ // if the output name isn't a variable then quote it
+ if (outputName.length() > 0 && outputName.indexOf("$(") != 0) { //$NON-NLS-1$
+ outputName = DOUBLE_QUOTE + outputName + DOUBLE_QUOTE;
+ }
+
+ String inputsStr = ""; //$NON-NLS-1$
+ if (inputResources != null) {
+ for (String inp : inputResources) {
+ if (inp != null && !inp.isEmpty()) {
+ // if the input resource isn't a variable then quote it
+ if (inp.indexOf("$(") != 0) { //$NON-NLS-1$
+ inp = DOUBLE_QUOTE + inp + DOUBLE_QUOTE;
+ }
+ inputsStr = inputsStr + inp + WHITESPACE;
+ }
+ }
+ inputsStr = inputsStr.trim();
+ }
+
+ String flagsStr = stringArrayToString(flags);
+
+ String command = commandLinePattern;
+
+ 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 toManagedCommandLineInfo(command.trim(), commandLinePattern, commandName, flags, outputFlag,
+ outputPrefix, outputName, inputResources);
+ }
+
+ protected IManagedCommandLineInfo toManagedCommandLineInfo(String commandLine, String commandLinePattern,
+ String commandName, String[] flags, String outputFlag, String outputPrefix, String outputName,
+ String[] inputResources) {
+ String flagsStr = stringArrayToString(flags);
+ String inputResourcesStr = stringArrayToString(inputResources);
+
+ return new IManagedCommandLineInfo() {
+ @Override
+ public String getCommandLine() {
+ return commandLine;
+ }
+
+ @Override
+ public String getCommandLinePattern() {
+ return commandLinePattern;
+ }
+
+ @Override
+ public String getCommandName() {
+ return commandName;
+ }
+
+ @Override
+ public String getFlags() {
+ return flagsStr;
+ }
+
+ @Override
+ public String getOutputFlag() {
+ return outputFlag;
+ }
+
+ @Override
+ public String getOutputPrefix() {
+ return outputPrefix;
+ }
+
+ @Override
+ public String getOutput() {
+ return outputName;
+ }
+
+ @Override
+ public String getInputs() {
+ return inputResourcesStr;
+ }
+ };
+ }
+
+ private String stringArrayToString(String[] array) {
+ if (array == null) {
+ return ""; //$NON-NLS-1$
+ }
+ return String.join(WHITESPACE, array);
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineGenerator.java
index 6e52fc3b789..d447167cf20 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineGenerator.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineGenerator.java
@@ -17,6 +17,10 @@ import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator;
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
+/**
+ * @deprecated Use {@link org.eclipse.cdt.managedbuilder.core.ManagedCommandLineGenerator}
+ */
+@Deprecated
public class ManagedCommandLineGenerator implements IManagedCommandLineGenerator {
public final String AT = "@"; //$NON-NLS-1$
@@ -51,7 +55,6 @@ public class ManagedCommandLineGenerator implements IManagedCommandLineGenerator
private static ManagedCommandLineGenerator cmdLineGen;
protected ManagedCommandLineGenerator() {
- cmdLineGen = null;
}
public static ManagedCommandLineGenerator getCommandLineGenerator() {
@@ -60,70 +63,12 @@ public class ManagedCommandLineGenerator implements IManagedCommandLineGenerator
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)
- */
@Override
public IManagedCommandLineInfo generateCommandLineInfo(ITool tool, String commandName, String[] flags,
String outputFlag, String outputPrefix, String outputName, String[] inputResources,
String commandLinePattern) {
- if (commandLinePattern == null || commandLinePattern.length() <= 0)
- commandLinePattern = Tool.DEFAULT_PATTERN;
-
- // if the output name isn't a variable then quote it
- if (outputName.length() > 0 && outputName.indexOf("$(") != 0) //$NON-NLS-1$
- outputName = DOUBLE_QUOTE + outputName + DOUBLE_QUOTE;
-
- String inputsStr = ""; //$NON-NLS-1$
- if (inputResources != null) {
- for (String inp : inputResources) {
- if (inp != null && inp.length() > 0) {
- // if the input resource isn't a variable then quote it
- if (inp.indexOf("$(") != 0) { //$NON-NLS-1$
- inp = DOUBLE_QUOTE + inp + DOUBLE_QUOTE;
- }
- inputsStr = inputsStr + inp + WHITESPACE;
- }
- }
- inputsStr = inputsStr.trim();
- }
-
- String flagsStr = stringArrayToString(flags);
-
- String command = commandLinePattern;
-
- 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));
+ // Forward the call to the API implementation
+ return new org.eclipse.cdt.managedbuilder.core.ManagedCommandLineGenerator().generateCommandLineInfo(tool,
+ commandName, flags, outputFlag, outputPrefix, outputName, inputResources, commandLinePattern);
}
-
- private String stringArrayToString(String[] array) {
- if (array == null || array.length <= 0)
- return ""; //$NON-NLS-1$
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < array.length; i++) {
- if (i > 0) // we add whitespace after each but not first so .trim() is a no-op
- sb.append(WHITESPACE);
- sb.append(array[i]);
- }
- return sb.toString().trim();
- }
-
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineInfo.java
index c90d4e726ab..02f6d745354 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineInfo.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedCommandLineInfo.java
@@ -15,6 +15,10 @@ package org.eclipse.cdt.managedbuilder.internal.core;
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo;
+/**
+ * @deprecated Use {@link org.eclipse.cdt.managedbuilder.core.ManagedCommandLineGenerator}
+ */
+@Deprecated
public class ManagedCommandLineInfo implements IManagedCommandLineInfo {
private String commandLine;
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiFileInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiFileInfo.java
index de509d8ab8b..c56e36347ac 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiFileInfo.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MultiFileInfo.java
@@ -18,6 +18,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.core.resources.IResource;
/**
@@ -160,4 +161,9 @@ public class MultiFileInfo extends MultiResourceInfo implements IFileInfo {
}
}
+ @Override
+ public IToolChain getBaseToolChain() {
+ return ((IFileInfo) fRis[curr]).getBaseToolChain();
+ }
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
index 74ce5b7a7a7..5ee7e6c027a 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
@@ -918,6 +918,7 @@ public class ResourceConfiguration extends ResourceInfo implements IFileInfo {
return list.toArray(new BuildLanguageData[list.size()]);
}
+ @Override
public IToolChain getBaseToolChain() {
ITool tools[] = getToolsToInvoke();
ITool baseTool = null;
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
index 0fd5e1076c4..6bb19ec601e 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
@@ -65,6 +65,7 @@ import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.core.ManagedCommandLineGenerator;
import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildEntryStorage;
import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildLanguageData;
import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression;
@@ -2190,7 +2191,7 @@ public class Tool extends HoldsOptions
} catch (CoreException e) {
}
}
- return ManagedCommandLineGenerator.getCommandLineGenerator();
+ return new ManagedCommandLineGenerator();
}
/* (non-Javadoc)

Back to the top