From dd4a40a683e62163f7b318ab8cfc7c15acda90ce Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 10 Aug 2023 16:36:05 -0400 Subject: [PATCH] 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 --- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../cdt/core/build/CBuildConfiguration.java | 11 ++++++-- .../cdt/core/build/IToolChainConstants.java | 27 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../launcher/ContainerCommandLauncher.java | 12 +++++++-- .../ContainerCommandLauncherFactory.java | 25 ++++++++++------- .../ui/launchbar/ContainerGCCToolChain.java | 16 ++++++++--- 7 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainConstants.java diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 8d1303efaa9..0e2998d20d0 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -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 diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java index 0b0c397ee9d..1a38a93ef08 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java @@ -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.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 void setActive() { } } + /** + * @since 8.4 + * @param launcher - launcher to set + */ + public void setLauncher(ICommandLauncher launcher) { + this.launcher = launcher; + } + /** * @since 6.5 * @throws CoreException diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainConstants.java new file mode 100644 index 00000000000..fffeba6a9a1 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainConstants.java @@ -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$ + +} diff --git a/launch/org.eclipse.cdt.docker.launcher/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.docker.launcher/META-INF/MANIFEST.MF index 50d021e96d1..7e2962b2dab 100644 --- a/launch/org.eclipse.cdt.docker.launcher/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.docker.launcher/META-INF/MANIFEST.MF @@ -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 diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java index 5c73e3384ab..2268f47ad17 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java @@ -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.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 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(); @@ -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 @@ -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; } diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java index 2f2a064f923..f07ed6ed9a3 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java @@ -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 List verifyIncludePaths(ICBuildConfiguration cfgd, List i 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 List verifyIncludePaths(ICBuildConfiguration cfgd, List i Set copiedVolumes = ContainerLauncher.getCopiedVolumes(tpath); List 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; diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChain.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChain.java index 3ead054b52a..46789a0d10c 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChain.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChain.java @@ -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 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 ContainerGCCToolChain(String id, IToolChainProvider provider, Map 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 @@ -633,16 +637,20 @@ public Process startBuildProcess(ICBuildConfiguration config, List comma // 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; } + }