Skip to content

Commit

Permalink
Rework setting PATH variable to not store in a File temporarily
Browse files Browse the repository at this point in the history
Fixes #230
  • Loading branch information
jonahgraham committed Jun 21, 2023
1 parent 413c0a3 commit 3b6ec14
Showing 1 changed file with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -88,12 +90,10 @@ public static PathEnvironmentVariable create(IConfiguration configuration) {

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

String path = "";
List<String> 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.
Expand All @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -216,7 +204,7 @@ public int getOperation() {

@Override
public String getValue() {
return path.getAbsolutePath();
return path;
}

}
Expand Down

0 comments on commit 3b6ec14

Please sign in to comment.