Skip to content

Commit f78d1a2

Browse files
committed
#534: add OPTION_PREFER_XPACKS_BIN for RISC-V
1 parent 5aa12fb commit f78d1a2

File tree

6 files changed

+82
-5
lines changed

6 files changed

+82
-5
lines changed

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.core/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@
676676
id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.path"
677677
superClass="ilg.gnumcueclipse.managedbuild.cross.option.base.toolchain.path">
678678
</option>
679+
<option
680+
category="ilg.gnumcueclipse.managedbuild.cross.riscv.optionCategory.target"
681+
id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.preferxpacksbin"
682+
superClass="ilg.gnumcueclipse.managedbuild.cross.option.base.preferxpacksbin">
683+
</option>
679684
<option
680685
category="ilg.gnumcueclipse.managedbuild.cross.riscv.optionCategory.target"
681686
id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash"

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.core/src/org/eclipse/embedcdt/managedbuild/cross/riscv/core/EnvironmentVariableSupplier.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
2929
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
3030
import org.eclipse.core.resources.IProject;
31+
import org.eclipse.core.runtime.IPath;
3132
import org.eclipse.core.runtime.Platform;
3233
import org.eclipse.embedcdt.core.EclipseUtils;
3334
import org.eclipse.embedcdt.internal.managedbuild.cross.riscv.core.Activator;
@@ -86,11 +87,31 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
8687

8788
IProject project = (IProject) configuration.getManagedProject().getOwner();
8889

90+
Boolean preferXpacksBin = Option.getOptionBooleanValue(configuration, Option.OPTION_PREFER_XPACKS_BIN);
91+
92+
String path = "";
93+
if (preferXpacksBin) {
94+
IPath projectPath = project.getWorkspace().getRoot().getLocation().append(project.getFullPath());
95+
IPath xpackBinPath = projectPath.append("xpacks").append(".bin");
96+
97+
path = xpackBinPath.toOSString();
98+
}
99+
89100
// Get the build tools path from the common store.
90101
PersistentPreferences commonPersistentPreferences = org.eclipse.embedcdt.internal.managedbuild.cross.core.Activator
91102
.getInstance().getPersistentPreferences();
92103

93-
String path = commonPersistentPreferences.getBuildToolsPath(project);
104+
String buildToolsPath = commonPersistentPreferences.getBuildToolsPath(project);
105+
106+
if (path.isEmpty()) {
107+
path = buildToolsPath;
108+
} else {
109+
if (!buildToolsPath.isEmpty()) {
110+
// Concatenate build tools path with toolchain path.
111+
path += EclipseUtils.getPathSeparator();
112+
path += buildToolsPath;
113+
}
114+
}
94115

95116
IOption optionId;
96117
optionId = toolchain.getOptionBySuperClassId(Option.OPTION_TOOLCHAIN_ID); // $NON-NLS-1$
@@ -100,7 +121,7 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
100121
optionName = toolchain.getOptionBySuperClassId(Option.OPTION_TOOLCHAIN_NAME); // $NON-NLS-1$
101122
String toolchainName = (String) optionName.getValue();
102123

103-
String toolchainPath = null;
124+
String toolchainPath = "";
104125

105126
// Get the toolchain path from this plug-in store.
106127
PersistentPreferences persistentPreferences = Activator.getInstance().getPersistentPreferences();
@@ -140,7 +161,8 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
140161
}
141162

142163
if (Activator.getInstance().isDebugging()) {
143-
System.out.println("riscv.PathEnvironmentVariable.create(" + configuration.getName() + ") returns null");
164+
System.out
165+
.println("riscv.PathEnvironmentVariable.create(" + configuration.getName() + ") returns null");
144166
}
145167
return null;
146168
}
@@ -156,8 +178,8 @@ private static String resolveMacros(String str, IConfiguration configuration) {
156178
}
157179

158180
if (Activator.getInstance().isDebugging()) {
159-
Activator.log("riscv.PathEnvironmentVariable.resolveMacros(\"" + str + "\", \"" + configuration.getName()
160-
+ "\") = \"" + "\"");
181+
Activator.log("riscv.PathEnvironmentVariable.resolveMacros(\"" + str + "\", \""
182+
+ configuration.getName() + "\") = \"" + "\"");
161183
}
162184
return result;
163185

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.core/src/org/eclipse/embedcdt/managedbuild/cross/riscv/core/Option.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public class Option {
126126
public static final String OPTION_COMMAND_MAKE = OPTION_COMMAND + "make";
127127
public static final String OPTION_COMMAND_RM = OPTION_COMMAND + "rm";
128128

129+
public static final String OPTION_PREFER_XPACKS_BIN = OPTION_PREFIX + ".preferxpacksbin";
130+
129131
public static final String OPTION_ADDTOOLS = OPTION_PREFIX + ".addtools.";
130132
public static final String OPTION_ADDTOOLS_CREATEFLASH = OPTION_ADDTOOLS + "createflash";
131133
public static final String OPTION_ADDTOOLS_CREATELISTING = OPTION_ADDTOOLS + "createlisting";
@@ -134,6 +136,7 @@ public class Option {
134136
public static final String OPTION_CREATEFLASH_CHOICE = OPTION_PREFIX + ".createflash.choice";
135137

136138
// These should be in sync with plugin.xml definitions
139+
public static final boolean OPTION_PREFER_XPACKS_BIN_DEFAULT = false;
137140
public static final boolean OPTION_ADDTOOLS_CREATEFLASH_DEFAULT = true;
138141
public static final boolean OPTION_ADDTOOLS_CREATELISTING_DEFAULT = false;
139142
public static final boolean OPTION_ADDTOOLS_PRINTSIZE_DEFAULT = true;

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.ui/src/org/eclipse/embedcdt/internal/managedbuild/cross/riscv/ui/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class Messages extends NLS {
5757
public static String ToolChainSettingsTab_path_link;
5858
public static String ToolChainSettingsTab_warning_link;
5959

60+
public static String ToolChainSettingsTab_preferXpacksBin;
61+
6062
public static String ToolsSettingsTab_path_label;
6163
public static String ToolsSettingsTab_path_link;
6264

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.ui/src/org/eclipse/embedcdt/internal/managedbuild/cross/riscv/ui/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ preferences pages or the <a>project</a> properties page)
5252
ToolChainSettingsTab_warning_link=\
5353
Warning: these definitions do not affect the build and are for the benefit of the indexer only.
5454

55+
ToolChainSettingsTab_preferXpacksBin=\
56+
Prefer local xpacks/.bin path
57+
5558
# ----- Tools Paths, preferences and properties pages -----
5659

5760
ToolsPaths_label=Build tools folder:

plugins/org.eclipse.embedcdt.managedbuild.cross.riscv.ui/src/org/eclipse/embedcdt/managedbuild/cross/riscv/ui/TabToolchains.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class TabToolchains extends AbstractCBuildPropertyTab {
106106
private Button fFlashButton;
107107
private Button fListingButton;
108108
private Button fSizeButton;
109+
private Button fUseXpacksBin;
109110

110111
// private boolean fIsExecutable;
111112
// private boolean fIsStaticLibrary;
@@ -353,6 +354,13 @@ public void modifyText(ModifyEvent e) {
353354
empty.setLayoutData(layoutData);
354355
}
355356

357+
{
358+
fUseXpacksBin = new Button(usercomp, SWT.CHECK);
359+
fUseXpacksBin.setText(Messages.ToolChainSettingsTab_preferXpacksBin);
360+
layoutData = new GridData(SWT.LEFT, SWT.TOP, false, false, 3, 1);
361+
fUseXpacksBin.setLayoutData(layoutData);
362+
}
363+
356364
{
357365
Label label = new Label(usercomp, SWT.NONE);
358366
label.setText(Messages.ToolChainSettingsTab_path_label);
@@ -489,6 +497,16 @@ public void widgetSelected(SelectionEvent e) {
489497
}
490498
});
491499

500+
fUseXpacksBin.addSelectionListener(new SelectionAdapter() {
501+
@Override
502+
public void widgetSelected(SelectionEvent event) {
503+
504+
// Disable the paths if xpacks are preferred.
505+
fToolchainPathLabel.setEnabled(!fUseXpacksBin.getSelection());
506+
fBuildToolsPathLabel.setEnabled(!fUseXpacksBin.getSelection());
507+
}
508+
});
509+
492510
// --------------------------------------------------------------------
493511

494512
updateControlsForConfig(fConfig);
@@ -615,6 +633,8 @@ public void updateData(ICResourceDescription cfgd) {
615633
fFlashButton.setEnabled(isExecutable);
616634
fListingButton.setEnabled(isExecutable);
617635
fSizeButton.setEnabled(isExecutable);
636+
637+
fUseXpacksBin.setEnabled(isExecutable);
618638
}
619639
}
620640

@@ -816,6 +836,17 @@ private void updateControlsForConfig(IConfiguration config) {
816836
fCommandRmText.setText(toolchainDefinition.getCmdRm());
817837
}
818838

839+
Boolean useXpacksBin = Option.getOptionBooleanValue(config, Option.OPTION_PREFER_XPACKS_BIN);
840+
if (useXpacksBin != null) {
841+
fUseXpacksBin.setSelection(useXpacksBin);
842+
} else {
843+
fUseXpacksBin.setSelection(Option.OPTION_PREFER_XPACKS_BIN_DEFAULT);
844+
}
845+
846+
// Disable the paths if xpacks are preferred.
847+
fToolchainPathLabel.setEnabled(!fUseXpacksBin.getSelection());
848+
fBuildToolsPathLabel.setEnabled(!fUseXpacksBin.getSelection());
849+
819850
Boolean isCreateFlash = Option.getOptionBooleanValue(config, Option.OPTION_ADDTOOLS_CREATEFLASH);
820851
if (isCreateFlash != null) {
821852
fFlashButton.setSelection(isCreateFlash);
@@ -929,6 +960,9 @@ private void updateOptions(IConfiguration config) {
929960
propagateCommandRmUpdate(config);
930961
}
931962

963+
option = toolchain.getOptionBySuperClassId(Option.OPTION_PREFER_XPACKS_BIN); // $NON-NLS-1$
964+
config.setOption(toolchain, option, fUseXpacksBin.getSelection());
965+
932966
option = toolchain.getOptionBySuperClassId(Option.OPTION_ADDTOOLS_CREATEFLASH); // $NON-NLS-1$
933967
config.setOption(toolchain, option, fFlashButton.getSelection());
934968

@@ -1032,6 +1066,13 @@ public static void setOptionsForToolchain(IConfiguration config, int toolchainIn
10321066
option = toolchain.getOptionBySuperClassId(Option.OPTION_COMMAND_RM); // $NON-NLS-1$
10331067
config.setOption(toolchain, option, td.getCmdRm());
10341068

1069+
// If already set by the template engine, keep it.
1070+
Boolean useXpacksBin = Option.getOptionBooleanValue(config, Option.OPTION_PREFER_XPACKS_BIN);
1071+
if (useXpacksBin == null) {
1072+
option = toolchain.getOptionBySuperClassId(Option.OPTION_PREFER_XPACKS_BIN); // $NON-NLS-1$
1073+
config.setOption(toolchain, option, Option.OPTION_PREFER_XPACKS_BIN_DEFAULT);
1074+
}
1075+
10351076
option = toolchain.getOptionBySuperClassId(Option.OPTION_ADDTOOLS_CREATEFLASH); // $NON-NLS-1$
10361077
config.setOption(toolchain, option, Option.OPTION_ADDTOOLS_CREATEFLASH_DEFAULT);
10371078

@@ -1078,6 +1119,7 @@ protected void performDefaults() {
10781119
updateInterfaceAfterToolchainChange();
10791120

10801121
if (isManaged()) {
1122+
fUseXpacksBin.setSelection(Option.OPTION_PREFER_XPACKS_BIN_DEFAULT);
10811123
fFlashButton.setSelection(Option.OPTION_ADDTOOLS_CREATEFLASH_DEFAULT);
10821124
fListingButton.setSelection(Option.OPTION_ADDTOOLS_CREATELISTING_DEFAULT);
10831125
fSizeButton.setSelection(Option.OPTION_ADDTOOLS_PRINTSIZE_DEFAULT);

0 commit comments

Comments
 (0)