1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

Add GNU linker library grouping option to MBS

This commit is contained in:
John Dallaway 2023-11-07 18:22:35 +00:00
parent 08abfa2957
commit e31815210e
4 changed files with 70 additions and 2 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.gnu.ui; singleton:=true
Bundle-Version: 8.5.300.qualifier
Bundle-Version: 8.6.0.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2005, 2010 Texas Instruments Inc. and others.
# Copyright (c) 2005, 2023 Texas Instruments Inc. and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@ -11,6 +11,7 @@
# Contributors:
# Texas Instruments Inc. - initial API and implementation
# IBM Corporation
# John Dallaway - add library grouping option (#608)
###############################################################################
# plugin names
@ -208,6 +209,7 @@ Option.Posix.Linker.Strip.debug=Omit debug symbol information (-S)
Option.Posix.Linker.Static=No shared libraries (-static)
Option.Posix.Linker.XLinker=Other options (-Xlinker [option])
Option.Posix.Linker.Flags=Linker flags
Option.Posix.Linker.GroupLibs=Group libraries (-Wl,--start-group ... -Wl,--end-group)
Option.Posix.Libs=Libraries (-l)
Option.Posix.Libsearch=Library search path (-L)
Option.Posix.UserObjs=Other objects

View file

@ -83,6 +83,7 @@
name="%Option.Posix.Libs"
category="gnu.c.link.category.libs"
command="-l"
commandGenerator="org.eclipse.cdt.managedbuilder.gnu.ui.LibrariesCommandGenerator"
id="gnu.c.link.option.libs"
browseType="none"
valueType="libs">
@ -95,6 +96,13 @@
browseType="directory"
valueType="libPaths">
</option>
<option
defaultValue="false"
name="%Option.Posix.Linker.GroupLibs"
category="gnu.c.link.category.libs"
id="gnu.c.link.option.group"
valueType="boolean">
</option>
<optionCategory
owner="cdt.managedbuild.tool.gnu.c.linker"
name="%OptionCategory.Misc"

View file

@ -0,0 +1,58 @@
/*******************************************************************************
* 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 implementation (#608)
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.ui;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator;
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;
/**
* An option command generator to group libraries on the GNU linker command line
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 8.6
*/
public class LibrariesCommandGenerator implements IOptionCommandGenerator {
private static final String GROUP_LIBRARIES_COMMAND_FORMAT = "-Wl,--start-group %s -Wl,--end-group"; //$NON-NLS-1$
private static final String GROUP_LIBRARIES_OPTION_ID = "gnu.c.link.option.group"; //$NON-NLS-1$
@Override
public String generateCommand(IOption option, IVariableSubstitutor macroSubstitutor) {
IOption groupOption = option.getOptionHolder().getOptionBySuperClassId(GROUP_LIBRARIES_OPTION_ID);
try {
if ((groupOption != null) && groupOption.getBooleanValue()) { // if library grouping enabled
String command = option.getCommand();
String libraries = Arrays.stream(option.getLibraries()).map(lib -> command + lib)
.collect(Collectors.joining(" ")); //$NON-NLS-1$
if (!libraries.isEmpty()) {
libraries = CdtVariableResolver.resolveToString(libraries, macroSubstitutor);
return String.format(GROUP_LIBRARIES_COMMAND_FORMAT, libraries);
}
}
} catch (BuildException | CdtVariableException e) {
Platform.getLog(getClass()).log(Status.error("Error generating libraries command", e)); //$NON-NLS-1$
}
return null; // fallback to default command generator
}
}