From 09e3b5ca29f61dc202b9005a282538ffa8faee8d Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 28 Oct 2022 22:47:59 -0400 Subject: [PATCH] Execute autoreconf in the same environment as configure and make Changed the execute to take the cwd to run the command in and clean up the related code, including some error message handling and removing some redundant code. Fixes #125 --- .../core/AutotoolsBuildConfiguration.java | 91 +++++-------------- .../internal/core/build/messages.properties | 2 +- 2 files changed, 23 insertions(+), 70 deletions(-) diff --git a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java index 4dc47efb12f..055f8972115 100644 --- a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java +++ b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java @@ -15,17 +15,12 @@ package org.eclipse.cdt.core.autotools.core; import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IConsoleParser; -import org.eclipse.cdt.core.autotools.core.internal.Activator; import org.eclipse.cdt.core.build.CBuildConfiguration; import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; @@ -37,7 +32,8 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; public class AutotoolsBuildConfiguration extends CBuildConfiguration { @@ -65,92 +61,49 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration { IProject project = getProject(); - execute(Arrays.asList(new String[] { "autoreconf", "--install" }), project.getLocation(), console, monitor); //$NON-NLS-1$ //$NON-NLS-2$ - executeRemote(Arrays.asList(new String[] { "./configure" }), project.getLocation(), console, monitor); //$NON-NLS-1$ - executeRemote(Arrays.asList(new String[] { "make" }), project.getLocation(), console, monitor); //$NON-NLS-1$ + executeRemote(List.of("autoreconf", "--install"), project.getLocation(), //$NON-NLS-1$//$NON-NLS-2$ + console, monitor); + + String configure = "./configure"; //$NON-NLS-1$ + java.nio.file.Path cmdPath = java.nio.file.Path.of(project.getLocation().toString(), configure); + if (cmdPath.toFile().exists()) { + configure = cmdPath.toAbsolutePath().toString(); + } + executeRemote(List.of(configure), new Path(getBuildDirectory().toString()), console, monitor); + + executeRemote(List.of("make"), new Path(getBuildDirectory().toString()), console, monitor); //$NON-NLS-1$ return new IProject[] { project }; } @Override public void clean(IConsole console, IProgressMonitor monitor) throws CoreException { - executeRemote(Arrays.asList(new String[] { "make", "clean" }), getProject().getLocation(), console, monitor); //$NON-NLS-1$ //$NON-NLS-2$ + executeRemote(List.of("make", "clean"), new Path(getBuildDirectory().toString()), console, monitor); //$NON-NLS-1$//$NON-NLS-2$ } - protected void execute(List command, IPath dir, IConsole console, IProgressMonitor monitor) - throws CoreException { - String cmd = command.get(0); - - if (Platform.getOS().equals(Platform.OS_WIN32) && !(cmd.endsWith(".exe") && !cmd.endsWith(".bat"))) { //$NON-NLS-1$ //$NON-NLS-2$ - // Maybe a shell script, see if we can launch it in sh - // TODO this probably should be generalized in CBuildConfiguration - Path shPath = findCommand("sh"); //$NON-NLS-1$ - if (shPath != null) { - List shCommand = new ArrayList<>(); - shCommand.add(shPath.toString()); - shCommand.add("-c"); //$NON-NLS-1$ - shCommand.add("\"" + String.join(" ", command) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - command = shCommand; - } - } else { - Path cmdPath = findCommand(cmd); - if (cmdPath != null) { - cmd = cmdPath.toString(); - command.set(0, cmd); - } - } - - ProcessBuilder builder = new ProcessBuilder(command).directory(dir.toFile()); - setBuildEnvironment(builder.environment()); - - try { - // TODO Error parsers - Process process = builder.start(); - watchProcess(console, monitor); - } catch (IOException e) { - throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-1$ //$NON-NLS-2$ - } - - getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); - } - - protected void executeRemote(List command, IPath dir, IConsole console, IProgressMonitor monitor) + protected void executeRemote(List command, IPath processCwd, IConsole console, IProgressMonitor monitor) throws CoreException { IProject project = getProject(); + String commandJoined = String.join(" ", command); //$NON-NLS-1$ try { project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); ConsoleOutputStream outStream = console.getOutputStream(); - Path buildDir = getBuildDirectory(); - - String cmd = command.get(0); - - if (cmd.startsWith(".")) { //$NON-NLS-1$ - Path cmdPath = Paths.get(dir.toString(), cmd); - if (cmdPath.toFile().exists()) { - command.set(0, cmdPath.toAbsolutePath().toString()); - } - } - - outStream.write("Building in: " + buildDir.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ - try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this, getToolChain().getErrorParserIds())) { epm.setOutputStream(console.getOutputStream()); IEnvironmentVariable[] env = new IEnvironmentVariable[0]; - org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path( - getBuildDirectory().toString()); - - Process p = startBuildProcess(command, env, workingDir, console, monitor); + outStream.write("Building in: " + processCwd.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + outStream.write("Running: " + commandJoined + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + Process p = startBuildProcess(command, env, processCwd, console, monitor); if (p == null) { - console.getErrorStream().write(String.format("Error executing: {0}", String.join(" ", command))); //$NON-NLS-1$ //$NON-NLS-2$ - throw new CoreException( - Activator.errorStatus("Error executing: " + String.join(" ", command), null)); //$NON-NLS-1$ //$NON-NLS-2$ + console.getErrorStream().write("Error executing: " + commandJoined); //$NON-NLS-1$ + throw new CoreException(Status.error("Error executing: " + commandJoined)); //$NON-NLS-1$ } watchProcess(new IConsoleParser[] { epm }, monitor); @@ -159,7 +112,7 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (IOException e) { - throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-1$ //$NON-NLS-2$ + throw new CoreException(Status.error("Error executing: " + commandJoined, e)); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties index 6473f66a22a..7f3ba52f955 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties @@ -16,7 +16,7 @@ StandardBuildConfiguration_0=Building in: %s\n StandardBuildConfiguration_1=Build complete (%d errors, %d warnings): %s\n StandardBuildConfiguration_Failure=Error: %s CBuildConfiguration_BuildComplete=Build complete\n -CBuildConfiguration_CommandNotFound=Error: build command '%s' not found +CBuildConfiguration_CommandNotFound=Error: build command '%s' not found\n CBuildConfiguration_CreateJob=Create Build Folder CBuildConfiguration_Location=line %d, external location: %s CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration