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
1717package org .eclipse .embedcdt .managedbuild .cross .riscv .core ;
1818
1919import 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
2126import org .eclipse .cdt .core .cdtvariables .CdtVariableException ;
2227import org .eclipse .cdt .managedbuilder .core .IConfiguration ;
3035import org .eclipse .core .resources .IProject ;
3136import org .eclipse .core .runtime .IPath ;
3237import org .eclipse .core .runtime .Platform ;
33- import org .eclipse .embedcdt .core .EclipseUtils ;
3438import org .eclipse .embedcdt .internal .managedbuild .cross .riscv .core .Activator ;
3539import 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