mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
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
This commit is contained in:
parent
9cc97ac406
commit
09e3b5ca29
2 changed files with 23 additions and 70 deletions
|
@ -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<String> 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<String> 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<String> command, IPath dir, IConsole console, IProgressMonitor monitor)
|
||||
protected void executeRemote(List<String> 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$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue