-
Notifications
You must be signed in to change notification settings - Fork 210
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
Invoke "gcc" to build assembler files #671
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ ASM_SRCS := | |
C_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C_DEPS := | ||
EXECUTABLES := | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ ASM_SRCS := | |
C_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C_DEPS := | ||
EXECUTABLES := | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ ASM_SRCS := | |
C_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C_DEPS := | ||
EXECUTABLES := | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ ASM_SRCS := | |
C_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C_DEPS := | ||
EXECUTABLES := | ||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ C_SRCS := | |
C_UPPER_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C++M_DEPS := | ||
C++_DEPS := | ||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ C_SRCS := | |
C_UPPER_SRCS := | ||
OBJ_SRCS := | ||
O_SRCS := | ||
SX_SRCS := | ||
S_UPPER_SRCS := | ||
C++M_DEPS := | ||
C++_DEPS := | ||
|
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
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
97 changes: 97 additions & 0 deletions
97
...builder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuAsmFlagsCommandGenerator.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,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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 implementation (#666) | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.managedbuilder.gnu.ui; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException; | ||
import org.eclipse.cdt.managedbuilder.core.BuildException; | ||
import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
import org.eclipse.cdt.managedbuilder.core.IOption; | ||
import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator; | ||
import org.eclipse.cdt.managedbuilder.core.ITool; | ||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.FileMacroExplicitSubstitutor; | ||
import org.eclipse.cdt.managedbuilder.internal.macros.BuildfileMacroSubstitutor; | ||
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver; | ||
import org.eclipse.cdt.utils.cdtvariables.IVariableSubstitutor; | ||
import org.eclipse.core.runtime.Platform; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
/** | ||
* Assembler flags command generator. | ||
* This command generator supports managed build projects that were | ||
* created using older versions of the GNU toolchain build description | ||
* where assembly files were built by invoking the GNU "as" tool directly. | ||
* @noextend This class is not intended to be subclassed by clients. | ||
* @noinstantiate This class is not intended to be instantiated by clients. | ||
* @since 8.7 | ||
*/ | ||
public class GnuAsmFlagsCommandGenerator implements IOptionCommandGenerator { | ||
|
||
private static final String DO_NOT_LINK_FLAG = "-c"; //$NON-NLS-1$ | ||
private static final Pattern DO_NOT_LINK_PATTERN = Pattern.compile("(^|\\s)-c($|\\s)"); //$NON-NLS-1$ | ||
private static final Pattern ASM_FLAG_PATTERN = Pattern.compile("-[aDKLR]\\S*"); //$NON-NLS-1$ | ||
|
||
@Override | ||
public String generateCommand(IOption option, IVariableSubstitutor macroSubstitutor) { | ||
String toolCommand = getToolCommand(option, macroSubstitutor); | ||
try { | ||
if (null != toolCommand && IOption.STRING == option.getValueType() && option.getCommand().isEmpty()) { | ||
String optionValue = option.getStringValue(); | ||
if (toolCommand.equals("gcc")) { //$NON-NLS-1$ | ||
// if the default assembler tool command has not been overridden | ||
String command = CdtVariableResolver.resolveToString(optionValue, macroSubstitutor); | ||
if (!DO_NOT_LINK_PATTERN.matcher(command).find()) { | ||
// if the "-c" flag is not already present on the command line we | ||
// assume the flags target the GNU "as" command line rather than the | ||
// "gcc" command line so we add the "-c" flag and apply the "-Wa," | ||
// prefix to those flags that are intended only for the assembler | ||
return DO_NOT_LINK_FLAG + " " + ASM_FLAG_PATTERN.matcher(command).replaceAll("-Wa,$0"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
} else if (toolCommand.endsWith("as") && optionValue.equals(DO_NOT_LINK_FLAG)) { //$NON-NLS-1$ | ||
// if GNU "as" is called directly and the default assembler flags have | ||
// not been overridden we remove the "-c" flag | ||
return ""; //$NON-NLS-1$ | ||
} | ||
} | ||
} catch (BuildException | CdtVariableException e) { | ||
Platform.getLog(getClass()).log(Status.error("Error generating GNU assembler command", e)); //$NON-NLS-1$ | ||
} | ||
return null; // fallback to default command generator | ||
} | ||
|
||
private static String getToolCommand(IOption option, IVariableSubstitutor macroSubstitutor) { | ||
// the option holder may be a super class of the assembler tool so we must | ||
// locate the tool from the build configuration to obtain the correct tool command | ||
IConfiguration config = getConfiguration(macroSubstitutor); | ||
if (config != null) { | ||
String optionHolderId = option.getOptionHolder().getId(); | ||
ITool[] tools = config.getToolsBySuperClassId(optionHolderId); | ||
if (1 == tools.length) { | ||
return tools[0].getToolCommand(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static IConfiguration getConfiguration(IVariableSubstitutor macroSubstitutor) { | ||
if (macroSubstitutor instanceof BuildfileMacroSubstitutor bms) { // case ToolSettingsPrefStore | ||
return bms.getConfiguration(); | ||
} else if (macroSubstitutor instanceof FileMacroExplicitSubstitutor fmes) { // case BuildStep | ||
return fmes.getConfiguration(); | ||
} | ||
return null; | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be late the party here, but should this line not match
arm-non-eabi-gcc
for example, orgcc.exe
? Or is it enough to have a strict check forgcc
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are checking only whether the tool command has been overridden. We don't care if it has been overridden by the user or by an extender. If the tool command has been overridden, then our new default value (
gcc
) will have no effect on the build and we do not need to modify the assembler flags.