Skip to content

Commit

Permalink
Add GNU linker library grouping option to MBS
Browse files Browse the repository at this point in the history
  • Loading branch information
jld01 committed Nov 10, 2023
1 parent 08abfa2 commit e318152
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +11,7 @@
# Contributors:
# Texas Instruments Inc. - initial API and implementation
# IBM Corporation
# John Dallaway - add library grouping option (#608)
###############################################################################

# plugin names
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

}

0 comments on commit e318152

Please sign in to comment.