Skip to content

Commit 02981a8

Browse files
committed
Merge branch 'develop' of https://github.com/eclipse-embed-cdt/eclipse-plugins into develop
2 parents 91614c7 + 5f5a527 commit 02981a8

File tree

2 files changed

+53
-67
lines changed

2 files changed

+53
-67
lines changed

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

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2013 Wind River Systems, Inc. and others.
2+
* Copyright (c) 2009, 2023 Wind River Systems, Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,11 @@
1616
package org.eclipse.embedcdt.managedbuild.cross.arm.core;
1717

1818
import java.io.File;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.function.Predicate;
22+
import java.util.stream.Collectors;
23+
import java.util.stream.Stream;
1924

2025
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
2126
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@@ -29,7 +34,6 @@
2934
import org.eclipse.core.resources.IProject;
3035
import org.eclipse.core.runtime.IPath;
3136
import org.eclipse.core.runtime.Platform;
32-
import org.eclipse.embedcdt.core.EclipseUtils;
3337
import org.eclipse.embedcdt.internal.managedbuild.cross.arm.core.Activator;
3438
import org.eclipse.embedcdt.managedbuild.cross.core.preferences.PersistentPreferences;
3539

@@ -74,9 +78,9 @@ private static class PathEnvironmentVariable implements IBuildEnvironmentVariabl
7478

7579
public static String name = "PATH"; //$NON-NLS-1$
7680

77-
private File path;
81+
private String path;
7882

79-
private PathEnvironmentVariable(File path) {
83+
private PathEnvironmentVariable(String path) {
8084
// System.out.println("cpath=" + path);
8185
this.path = path;
8286
}
@@ -88,12 +92,12 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
8892

8993
Boolean preferXpacksBin = Option.getOptionBooleanValue(configuration, Option.OPTION_PREFER_XPACKS_BIN);
9094

91-
String path = "";
95+
List<String> path = new ArrayList<>();
9296
if (preferXpacksBin) {
9397
IPath projectPath = project.getWorkspace().getRoot().getLocation().append(project.getFullPath());
9498
IPath xpackBinPath = projectPath.append("xpacks").append(".bin");
9599

96-
path = xpackBinPath.toOSString();
100+
path.add(xpackBinPath.toOSString());
97101
}
98102

99103
// Get the build tools path from the common store.
@@ -109,14 +113,8 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
109113
buildToolsPath = deprecatedPersistentPreferences.getBuildToolsPath(project);
110114
}
111115

112-
if (path.isEmpty()) {
113-
path = buildToolsPath;
114-
} else {
115-
if (!buildToolsPath.isEmpty()) {
116-
// Concatenate build tools path with toolchain path.
117-
path += EclipseUtils.getPathSeparator();
118-
path += buildToolsPath;
119-
}
116+
if (!buildToolsPath.isEmpty()) {
117+
path.add(buildToolsPath);
120118
}
121119

122120
IOption optionId;
@@ -139,34 +137,29 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
139137
toolchainPath = deprecatedPersistentPreferences.getToolchainPath(toolchainId, toolchainName, project);
140138
}
141139

142-
if (path.isEmpty()) {
143-
path = toolchainPath;
144-
} else {
145-
if (!toolchainPath.isEmpty()) {
146-
// Concatenate build tools path with toolchain path.
147-
path += EclipseUtils.getPathSeparator();
148-
path += toolchainPath;
149-
}
140+
if (!toolchainPath.isEmpty()) {
141+
path.add(toolchainPath);
150142
}
151143

152144
if (!path.isEmpty()) {
153145
// if present, substitute macros
154-
if (path.indexOf("${") >= 0) {
155-
path = resolveMacros(path, configuration);
156-
}
146+
Stream<String> macrosResolved = path.stream().map(p -> {
147+
if (p.indexOf("${") >= 0) {
148+
p = resolveMacros(p, configuration);
149+
}
150+
return p;
151+
});
152+
// filter out empty entries and convert string to absolute paths
153+
String pathVar = macrosResolved.filter(Predicate.not(String::isBlank)).map(File::new)
154+
.map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator));
157155

158-
File sysroot = new File(path);
159-
// File bin = new File(sysroot, "bin"); //$NON-NLS-1$
160-
// if (bin.isDirectory()) {
161-
// sysroot = bin;
162-
// }
163156
if (DEBUG_PATH) {
164157
if (Activator.getInstance().isDebugging()) {
165-
System.out.println("arm.PathEnvironmentVariable.create() PATH=\"" + sysroot + "\" cfg="
158+
System.out.println("arm.PathEnvironmentVariable.create() PATH=\"" + pathVar + "\" cfg="
166159
+ configuration + " prj=" + configuration.getManagedProject().getOwner().getName());
167160
}
168161
}
169-
return new PathEnvironmentVariable(sysroot);
162+
return new PathEnvironmentVariable(pathVar);
170163
}
171164

172165
if (Activator.getInstance().isDebugging()) {
@@ -216,7 +209,7 @@ public int getOperation() {
216209

217210
@Override
218211
public String getValue() {
219-
return path.getAbsolutePath();
212+
return path;
220213
}
221214

222215
}

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

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2013 Wind River Systems, Inc. and others.
2+
* Copyright (c) 2009, 2023 Wind River Systems, Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,11 @@
1717
package org.eclipse.embedcdt.managedbuild.cross.riscv.core;
1818

1919
import java.io.File;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.function.Predicate;
23+
import java.util.stream.Collectors;
24+
import java.util.stream.Stream;
2025

2126
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
2227
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@@ -30,7 +35,6 @@
3035
import org.eclipse.core.resources.IProject;
3136
import org.eclipse.core.runtime.IPath;
3237
import org.eclipse.core.runtime.Platform;
33-
import org.eclipse.embedcdt.core.EclipseUtils;
3438
import org.eclipse.embedcdt.internal.managedbuild.cross.riscv.core.Activator;
3539
import org.eclipse.embedcdt.managedbuild.cross.core.preferences.PersistentPreferences;
3640

@@ -75,9 +79,9 @@ private static class PathEnvironmentVariable implements IBuildEnvironmentVariabl
7579

7680
public static String name = "PATH"; //$NON-NLS-1$
7781

78-
private File path;
82+
private String path;
7983

80-
private PathEnvironmentVariable(File path) {
84+
private PathEnvironmentVariable(String path) {
8185
// System.out.println("cpath=" + path);
8286
this.path = path;
8387
}
@@ -89,28 +93,23 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
8993

9094
Boolean preferXpacksBin = Option.getOptionBooleanValue(configuration, Option.OPTION_PREFER_XPACKS_BIN);
9195

92-
String path = "";
96+
List<String> path = new ArrayList<>();
9397
if (preferXpacksBin) {
9498
IPath projectPath = project.getWorkspace().getRoot().getLocation().append(project.getFullPath());
9599
IPath xpackBinPath = projectPath.append("xpacks").append(".bin");
96100

97-
path = xpackBinPath.toOSString();
101+
path.add(xpackBinPath.toOSString());
98102
}
99103

100104
// Get the build tools path from the common store.
101105
PersistentPreferences commonPersistentPreferences = org.eclipse.embedcdt.internal.managedbuild.cross.core.Activator
102106
.getInstance().getPersistentPreferences();
103107

108+
// Get the build tools path from the common store.
104109
String buildToolsPath = commonPersistentPreferences.getBuildToolsPath(project);
105110

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-
}
111+
if (!buildToolsPath.isEmpty()) {
112+
path.add(buildToolsPath);
114113
}
115114

116115
IOption optionId;
@@ -129,35 +128,29 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {
129128
// Eclipse, defaults).
130129
toolchainPath = persistentPreferences.getToolchainPath(toolchainId, toolchainName, project);
131130

132-
if (path.isEmpty()) {
133-
path = toolchainPath;
134-
} else {
135-
if (!toolchainPath.isEmpty()) {
136-
// Concatenate build tools path with toolchain path.
137-
path += EclipseUtils.getPathSeparator();
138-
path += toolchainPath;
139-
}
131+
if (!toolchainPath.isEmpty()) {
132+
path.add(toolchainPath);
140133
}
141134

142135
if (!path.isEmpty()) {
143-
144136
// if present, substitute macros
145-
if (path.indexOf("${") >= 0) {
146-
path = resolveMacros(path, configuration);
147-
}
137+
Stream<String> macrosResolved = path.stream().map(p -> {
138+
if (p.indexOf("${") >= 0) {
139+
p = resolveMacros(p, configuration);
140+
}
141+
return p;
142+
});
143+
// filter out empty entries and convert string to absolute paths
144+
String pathVar = macrosResolved.filter(Predicate.not(String::isBlank)).map(File::new)
145+
.map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator));
148146

149-
File sysroot = new File(path);
150-
// File bin = new File(sysroot, "bin"); //$NON-NLS-1$
151-
// if (bin.isDirectory()) {
152-
// sysroot = bin;
153-
// }
154147
if (DEBUG_PATH) {
155148
if (Activator.getInstance().isDebugging()) {
156-
System.out.println("riscv.PathEnvironmentVariable.create() PATH=" + sysroot + " cfg="
149+
System.out.println("riscv.PathEnvironmentVariable.create() PATH=\"" + pathVar + "\" cfg="
157150
+ configuration + " prj=" + configuration.getManagedProject().getOwner().getName());
158151
}
159152
}
160-
return new PathEnvironmentVariable(sysroot);
153+
return new PathEnvironmentVariable(pathVar);
161154
}
162155

163156
if (Activator.getInstance().isDebugging()) {
@@ -208,7 +201,7 @@ public int getOperation() {
208201

209202
@Override
210203
public String getValue() {
211-
return path.getAbsolutePath();
204+
return path;
212205
}
213206

214207
}

0 commit comments

Comments
 (0)