diff --git a/plugins/org.eclipse.embedcdt.managedbuild.cross.arm.core/src/org/eclipse/embedcdt/managedbuild/cross/arm/core/EnvironmentVariableSupplier.java b/plugins/org.eclipse.embedcdt.managedbuild.cross.arm.core/src/org/eclipse/embedcdt/managedbuild/cross/arm/core/EnvironmentVariableSupplier.java index 222d59f43..f648aa8a8 100644 --- a/plugins/org.eclipse.embedcdt.managedbuild.cross.arm.core/src/org/eclipse/embedcdt/managedbuild/cross/arm/core/EnvironmentVariableSupplier.java +++ b/plugins/org.eclipse.embedcdt.managedbuild.cross.arm.core/src/org/eclipse/embedcdt/managedbuild/cross/arm/core/EnvironmentVariableSupplier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2023 Wind River Systems, Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,10 @@ package org.eclipse.embedcdt.managedbuild.cross.arm.core; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; import org.eclipse.cdt.core.cdtvariables.CdtVariableException; import org.eclipse.cdt.managedbuilder.core.IConfiguration; @@ -27,9 +31,7 @@ import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; -import org.eclipse.embedcdt.core.EclipseUtils; import org.eclipse.embedcdt.internal.managedbuild.cross.arm.core.Activator; import org.eclipse.embedcdt.managedbuild.cross.core.preferences.PersistentPreferences; @@ -74,9 +76,9 @@ private static class PathEnvironmentVariable implements IBuildEnvironmentVariabl public static String name = "PATH"; //$NON-NLS-1$ - private File path; + private String path; - private PathEnvironmentVariable(File path) { + private PathEnvironmentVariable(String path) { // System.out.println("cpath=" + path); this.path = path; } @@ -88,12 +90,10 @@ public static PathEnvironmentVariable create(IConfiguration configuration) { Boolean preferXpacksBin = Option.getOptionBooleanValue(configuration, Option.OPTION_PREFER_XPACKS_BIN); - String path = ""; + List path = new ArrayList<>(); if (preferXpacksBin) { - IPath projectPath = project.getWorkspace().getRoot().getLocation().append(project.getFullPath()); - IPath xpackBinPath = projectPath.append("xpacks").append(".bin"); - - path = xpackBinPath.toOSString(); + String xpackBinPath = project.getFolder("xpacks").getFolder(".bin").getLocation().toOSString(); + path.add(xpackBinPath); } // Get the build tools path from the common store. @@ -109,14 +109,8 @@ public static PathEnvironmentVariable create(IConfiguration configuration) { buildToolsPath = deprecatedPersistentPreferences.getBuildToolsPath(project); } - if (path.isEmpty()) { - path = buildToolsPath; - } else { - if (!buildToolsPath.isEmpty()) { - // Concatenate build tools path with toolchain path. - path += EclipseUtils.getPathSeparator(); - path += buildToolsPath; - } + if (!buildToolsPath.isEmpty()) { + path.add(buildToolsPath); } IOption optionId; @@ -139,34 +133,28 @@ public static PathEnvironmentVariable create(IConfiguration configuration) { toolchainPath = deprecatedPersistentPreferences.getToolchainPath(toolchainId, toolchainName, project); } - if (path.isEmpty()) { - path = toolchainPath; - } else { - if (!toolchainPath.isEmpty()) { - // Concatenate build tools path with toolchain path. - path += EclipseUtils.getPathSeparator(); - path += toolchainPath; - } + if (!toolchainPath.isEmpty()) { + path.add(toolchainPath); } - if (!path.isEmpty()) { + if (!path.isEmpty()) + + { // if present, substitute macros - if (path.indexOf("${") >= 0) { - path = resolveMacros(path, configuration); - } + String pathVar = path.stream().map(p -> { + if (p.indexOf("${") >= 0) { + p = resolveMacros(p, configuration); + } + return p; + }).filter(Predicate.not(String::isBlank)).collect(Collectors.joining(File.pathSeparator)); - File sysroot = new File(path); - // File bin = new File(sysroot, "bin"); //$NON-NLS-1$ - // if (bin.isDirectory()) { - // sysroot = bin; - // } if (DEBUG_PATH) { if (Activator.getInstance().isDebugging()) { - System.out.println("arm.PathEnvironmentVariable.create() PATH=\"" + sysroot + "\" cfg=" + System.out.println("arm.PathEnvironmentVariable.create() PATH=\"" + path + "\" cfg=" + configuration + " prj=" + configuration.getManagedProject().getOwner().getName()); } } - return new PathEnvironmentVariable(sysroot); + return new PathEnvironmentVariable(pathVar); } if (Activator.getInstance().isDebugging()) { @@ -216,7 +204,7 @@ public int getOperation() { @Override public String getValue() { - return path.getAbsolutePath(); + return path; } }