1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-03-28 14:56:28 +01:00

Fix meson build under Docker Tooling (#491)

* Fix meson build under Docker Tooling

- add new IToolChainConstants containing SECCOMP_UNCONFINED property constant
- add new setLauncher() method to CBuildConfiguration so that
  watchProcess() can be used for container building
- enhance ContainerCommandLauncher to discover specification of
  SECCOMP_UNDEFINED boolean option for execute() so "seccomp=undefined" can be specified
- fix ContainerCommandLauncherFactory.verifyIncludePaths() to only
  look at filtered includes that have been made absolute and to
  recognize matches when the prefix shows up in the loaded list
- add setting a property to ContainerGCCToolChain to set SECCOMP_UNCONFINED to true
  by default for the time-being
- when generating scannerinfo, specify "seccomp=unconfined"
- in ContainerGCCToolChain.startBuildProcess() remove extraneous
  banner statement and ensure that the build directory is created
- fixes #479
This commit is contained in:
Jeff Johnston 2023-08-10 16:36:05 -04:00 committed by GitHub
parent 1e04efa017
commit dd4a40a683
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 19 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
Bundle-Version: 8.3.0.qualifier
Bundle-Version: 8.4.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2022 QNX Software Systems and others.
* Copyright (c) 2015, 2023 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -80,7 +80,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
@ -1052,6 +1051,14 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
}
}
/**
* @since 8.4
* @param launcher - launcher to set
*/
public void setLauncher(ICommandLauncher launcher) {
this.launcher = launcher;
}
/**
* @since 6.5
* @throws CoreException

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial contribution
*******************************************************************************/
package org.eclipse.cdt.core.build;
/**
* Tool chain constants
*
* @since 8.4
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
public interface IToolChainConstants {
public final static String SECCOMP_UNDEFINED = "seccomp_undefined"; //$NON-NLS-1$
}

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.cdt.docker.launcher;singleton:=true
Bundle-Version: 2.0.100.qualifier
Bundle-Version: 2.0.200.qualifier
Bundle-Activator: org.eclipse.cdt.docker.launcher.DockerLaunchUIPlugin
Bundle-Vendor: %Plugin.vendor
Bundle-Localization: plugin

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Red Hat Inc. and others.
* Copyright (c) 2017, 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.build.ICBuildCommandLauncher;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainConstants;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.core.ProcessClosure;
@ -67,6 +68,8 @@ public class ContainerCommandLauncher implements ICommandLauncher, ICBuildComman
public final static String VOLUME_SEPARATOR_REGEX = "[|]"; //$NON-NLS-1$
public final static String SECCOMP_UNCONFINED_STR = "seccomp=unconfined"; //$NON-NLS-1$
private IProject fProject;
private Process fProcess;
private boolean fShowCommand;
@ -259,12 +262,14 @@ public class ContainerCommandLauncher implements ICommandLauncher, ICBuildComman
final String connectionName;
final String imageName;
final String pathMapProperty;
final String seccompUndefinedStr;
if (buildCfg != null) {
IToolChain toolChain = buildCfg.getToolChain();
selectedVolumeString = toolChain.getProperty(SELECTED_VOLUMES_ID);
connectionName = toolChain.getProperty(IContainerLaunchTarget.ATTR_CONNECTION_URI);
imageName = toolChain.getProperty(IContainerLaunchTarget.ATTR_IMAGE_ID);
pathMapProperty = toolChain.getProperty(DOCKERD_PATH);
seccompUndefinedStr = toolChain.getProperty(IToolChainConstants.SECCOMP_UNDEFINED);
} else {
ICConfigurationDescription cfgd = CoreModel.getDefault().getProjectDescription(fProject)
.getActiveConfiguration();
@ -277,6 +282,7 @@ public class ContainerCommandLauncher implements ICommandLauncher, ICBuildComman
connectionName = props.getProperty(ContainerCommandLauncher.CONNECTION_ID);
imageName = props.getProperty(ContainerCommandLauncher.IMAGE_ID);
pathMapProperty = props.getProperty(DOCKERD_PATH);
seccompUndefinedStr = props.getProperty(IToolChainConstants.SECCOMP_UNDEFINED);
}
// Add any specified volumes to additional dir list
@ -314,8 +320,10 @@ public class ContainerCommandLauncher implements ICommandLauncher, ICBuildComman
return null;
}
boolean seccompUndefined = Boolean.parseBoolean(seccompUndefinedStr);
fProcess = launcher.runCommand(connectionName, imageName, fProject, this, cmdList, workingDir, additionalDirs,
origEnv, fEnvironment, supportStdin, privilegedMode, labels, keepContainer);
origEnv, fEnvironment, supportStdin, privilegedMode, labels, keepContainer,
seccompUndefined ? List.of(SECCOMP_UNCONFINED_STR) : null);
return fProcess;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Red Hat Inc. and others.
* Copyright (c) 2017, 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -302,7 +302,7 @@ public class ContainerCommandLauncherFactory implements ICommandLauncherFactory,
return includePaths;
}
if (!getPaths(imgCnn, includePaths)) {
if (!getPaths(imgCnn, fetchPaths)) {
// There should be sufficient log messages by the root cause
return includePaths;
}
@ -313,13 +313,20 @@ public class ContainerCommandLauncherFactory implements ICommandLauncherFactory,
Set<IPath> copiedVolumes = ContainerLauncher.getCopiedVolumes(tpath);
List<String> newEntries = new ArrayList<>();
for (String path : includePaths) {
if (copiedVolumes.contains(new Path(path))) {
IPath newPath = tpath.append(path);
String newEntry = newPath.toOSString();
newEntries.add(newEntry);
} else {
newEntries.add(path);
for (String includePath : includePaths) {
IPath path = new Path(includePath).makeAbsolute();
boolean found = false;
for (IPath copiedVolume : copiedVolumes) {
if (copiedVolume.isPrefixOf(path)) {
IPath newPath = tpath.append(path);
String newEntry = newPath.toOSString();
newEntries.add(newEntry);
found = true;
break;
}
}
if (!found) {
newEntries.add(path.toPortableString());
}
}
return newEntries;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2019 QNX Software Systems and others.
* Copyright (c) 2015, 2023 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -33,10 +33,12 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncherManager;
import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildCommandLauncher;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChain2;
import org.eclipse.cdt.core.build.IToolChainConstants;
import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
@ -94,6 +96,7 @@ public class ContainerGCCToolChain extends PlatformObject implements IToolChain,
this.id = id;
this.properties.putAll(properties);
setProperty(IToolChainConstants.SECCOMP_UNDEFINED, "true"); //$NON-NLS-1$
this.envVars = envVars;
}
@ -356,6 +359,9 @@ public class ContainerGCCToolChain extends PlatformObject implements IToolChain,
return null;
}
if (!Files.exists(buildDirectory)) {
Files.createDirectories(buildDirectory);
}
Path tmpFile = Files.createTempFile(buildDirectory, ".sc", extension); //$NON-NLS-1$
commandLine.add(tmpFile.toString());
@ -624,8 +630,6 @@ public class ContainerGCCToolChain extends PlatformObject implements IToolChain,
buf.deleteCharAt(buf.length() - 1); // remove last blank;
argList.add(buf.toString());
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(config);
// Bug 536884 - following is a kludge to allow us to check if the
// Container headers have been deleted by the user in which case
// we need to re-perform scanner info collection and copy headers
@ -633,16 +637,20 @@ public class ContainerGCCToolChain extends PlatformObject implements IToolChain,
// TODO: make this cleaner
CommandLauncherManager.getInstance().processIncludePaths(config, Collections.emptyList());
ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(config);
launcher.setProject(config.getBuildConfiguration().getProject());
((CBuildConfiguration) config).setLauncher(launcher);
if (launcher instanceof ICBuildCommandLauncher) {
((ICBuildCommandLauncher) launcher).setBuildConfiguration(config);
console.getOutputStream().write(((ICBuildCommandLauncher) launcher).getConsoleHeader());
}
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(buildDirectory);
Files.createDirectories(Path.of(buildDirectory));
Process p = launcher.execute(cmdPath, argList.toArray(new String[0]), new String[0], workingDir, monitor);
return p;
}
}