-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set tool prefix for spawning GNU tool processes
Allows the GNU tool prefix to be specified by a CDT build variable. Modifies the Cross GCC toolchain description to provide the GNU tool prefix. Part of #361
- Loading branch information
Showing
6 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...gedbuilder.core/src/org/eclipse/cdt/managedbuilder/macros/AbstractGnuToolPrefixMacro.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.eclipse.cdt.managedbuilder.macros; | ||
|
||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException; | ||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableStatus; | ||
import org.eclipse.cdt.managedbuilder.core.BuildException; | ||
import org.eclipse.cdt.managedbuilder.core.IOption; | ||
import org.eclipse.cdt.utils.IGnuToolFactory; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
/** | ||
* A CDT build variable defining the GNU tool prefix for use by | ||
* an {@link org.eclipse.cdt.utils.IGnuToolFactory} implementation. | ||
* | ||
* @since 9.6 | ||
*/ | ||
public abstract class AbstractGnuToolPrefixMacro implements IBuildMacro { | ||
|
||
@Override | ||
public String getName() { | ||
return IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE; | ||
} | ||
|
||
@Override | ||
public int getValueType() { | ||
return IBuildMacro.VALUE_TEXT; | ||
} | ||
|
||
@Override | ||
public int getMacroValueType() { | ||
return getValueType(); | ||
} | ||
|
||
@Override | ||
public abstract String getStringValue() throws BuildMacroException; | ||
|
||
@Override | ||
public String[] getStringListValue() throws BuildMacroException { | ||
throw new BuildMacroException( | ||
new CdtVariableException(ICdtVariableStatus.TYPE_MACRO_NOT_STRINGLIST, getName(), null, getName())); | ||
} | ||
|
||
protected String getStringValue(IOption option) throws BuildMacroException { | ||
try { | ||
return option.getStringValue(); | ||
} catch (BuildException e) { | ||
throw new BuildMacroException(Status.error("Error getting macro value: " + getName(), e)); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...t.build.crossgcc/src/org/eclipse/cdt/internal/build/crossgcc/CrossBuildMacroSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 John Dallaway 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: | ||
* John Dallaway - initial API and implementation (#361) | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.internal.build.crossgcc; | ||
|
||
import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
import org.eclipse.cdt.managedbuilder.core.IOption; | ||
import org.eclipse.cdt.managedbuilder.macros.AbstractGnuToolPrefixMacro; | ||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException; | ||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro; | ||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider; | ||
import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier; | ||
import org.eclipse.cdt.utils.IGnuToolFactory; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
public class CrossBuildMacroSupplier implements IConfigurationBuildMacroSupplier { | ||
|
||
private static class GnuToolPrefixMacro extends AbstractGnuToolPrefixMacro { | ||
|
||
private static final String GNU_TOOL_PREFIX_OPTION = "cdt.managedbuild.option.gnu.cross.prefix"; //$NON-NLS-1$ | ||
private final IConfiguration configuration; | ||
|
||
public GnuToolPrefixMacro(IConfiguration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public String getStringValue() throws BuildMacroException { | ||
final IOption option = configuration.getToolChain().getOptionBySuperClassId(GNU_TOOL_PREFIX_OPTION); | ||
if (null == option) { | ||
throw new BuildMacroException(Status.error("Toolchain option not found: " + GNU_TOOL_PREFIX_OPTION)); //$NON-NLS-1$ | ||
} | ||
return getStringValue(option); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public IBuildMacro getMacro(String macroName, IConfiguration configuration, IBuildMacroProvider provider) { | ||
if (IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE.equals(macroName)) { | ||
return new GnuToolPrefixMacro(configuration); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public IBuildMacro[] getMacros(IConfiguration configuration, IBuildMacroProvider provider) { | ||
final IBuildMacro macro = getMacro(IGnuToolFactory.GNU_TOOL_PREFIX_VARIABLE, configuration, provider); | ||
return (null == macro) ? new IBuildMacro[0] : new IBuildMacro[] { macro }; | ||
} | ||
|
||
} |