Skip to content

Commit

Permalink
Fix meson build under Docker Tooling (#491)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jjohnstn committed Aug 10, 2023
1 parent 1e04efa commit dd4a40a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,7 +80,6 @@
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;
Expand Down Expand Up @@ -1052,6 +1051,14 @@ public void setActive() {
}
}

/**
* @since 8.4
* @param launcher - launcher to set
*/
public void setLauncher(ICommandLauncher launcher) {
this.launcher = launcher;
}

/**
* @since 6.5
* @throws CoreException
Expand Down
Original file line number Diff line number Diff line change
@@ -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$

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -259,12 +262,14 @@ public Process execute(IPath commandPath, String[] args, String[] env, IPath wor
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();
Expand All @@ -277,6 +282,7 @@ public Process execute(IPath commandPath, String[] args, String[] env, IPath wor
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
Expand Down Expand Up @@ -314,8 +320,10 @@ public Process execute(IPath commandPath, String[] args, String[] env, IPath wor
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -302,7 +302,7 @@ public List<String> verifyIncludePaths(ICBuildConfiguration cfgd, List<String> i
return includePaths;
}

if (!getPaths(imgCnn, includePaths)) {
if (!getPaths(imgCnn, fetchPaths)) {
// There should be sufficient log messages by the root cause
return includePaths;
}
Expand All @@ -313,13 +313,20 @@ public List<String> verifyIncludePaths(ICBuildConfiguration cfgd, List<String> i
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,10 +33,12 @@
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;
Expand Down Expand Up @@ -94,6 +96,7 @@ public ContainerGCCToolChain(String id, IToolChainProvider provider, Map<String,
this.id = id;

this.properties.putAll(properties);
setProperty(IToolChainConstants.SECCOMP_UNDEFINED, "true"); //$NON-NLS-1$
this.envVars = envVars;
}

Expand Down Expand Up @@ -356,6 +359,9 @@ synchronized public IExtendedScannerInfo getDefaultScannerInfo(IBuildConfigurati
return null;
}

if (!Files.exists(buildDirectory)) {
Files.createDirectories(buildDirectory);
}
Path tmpFile = Files.createTempFile(buildDirectory, ".sc", extension); //$NON-NLS-1$
commandLine.add(tmpFile.toString());

Expand Down Expand Up @@ -624,25 +630,27 @@ public Process startBuildProcess(ICBuildConfiguration config, List<String> comma
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
// to the host.
// 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;
}

}

0 comments on commit dd4a40a

Please sign in to comment.