mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-10 18:45:26 +02:00
Implement Homebrew toolchain provider for core build
This commit is contained in:
parent
9d4243f219
commit
a03e303f36
3 changed files with 84 additions and 1 deletions
|
@ -7,7 +7,7 @@ Bundle-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator
|
|||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4)",
|
||||
org.eclipse.core.resources;bundle-version="[3.22.200,4)",
|
||||
org.eclipse.cdt.core;bundle-version="[9.1.0,10)",
|
||||
org.eclipse.cdt.core;bundle-version="[9.2.0,10)",
|
||||
com.google.gson;bundle-version="[2.13.1,3)"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-17
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
class="org.eclipse.cdt.build.gcc.core.internal.GCCPathToolChainProvider"
|
||||
id="org.eclipse.cdt.build.gcc.core.gccPathProvider">
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.build.gcc.core.internal.HomebrewToolChainProvider"
|
||||
id="org.eclipse.cdt.build.gcc.core.homebrewProvider">
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.build.gcc.core.internal.Msys2ToolChainProvider"
|
||||
id="org.eclipse.cdt.build.gcc.core.msys2Provider">
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2025 QNX Software Systems 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:
|
||||
* QNX Software Systems - MinGW implementation
|
||||
* John Dallaway - Initial Homebrew implementation (#1175)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.build.gcc.core.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
|
||||
import org.eclipse.cdt.build.gcc.core.GCCToolChain;
|
||||
import org.eclipse.cdt.core.build.IToolChain;
|
||||
import org.eclipse.cdt.core.build.IToolChainManager;
|
||||
import org.eclipse.cdt.core.build.IToolChainProvider;
|
||||
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||
import org.eclipse.cdt.internal.core.Homebrew;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
public class HomebrewToolChainProvider implements IToolChainProvider {
|
||||
|
||||
private static final String ID = "org.eclipse.cdt.build.gcc.core.homebrewProvider"; //$NON-NLS-1$
|
||||
private static final Pattern CLANG_PATTERN = Pattern.compile("clang-\\d+"); //$NON-NLS-1$
|
||||
private static final Pattern GCC_PATTERN = Pattern.compile("gcc-\\d+"); //$NON-NLS-1$
|
||||
private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
|
||||
private static final String HOMEBREW_PACKAGE = "homebrew"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IToolChainManager manager) {
|
||||
final String homebrewHome = Homebrew.getHomebrewHome();
|
||||
if (null != homebrewHome) {
|
||||
Path homebrewPath = new File(homebrewHome).toPath();
|
||||
Path homebrewBinPath = homebrewPath.resolve("bin"); //$NON-NLS-1$
|
||||
Path homebrewLlvmBinPath = homebrewPath.resolve("opt/llvm/bin"); //$NON-NLS-1$
|
||||
for (File clangFile : getFiles(homebrewLlvmBinPath, CLANG_PATTERN)) {
|
||||
IEnvironmentVariable[] vars = createEnvironmentVariables(homebrewLlvmBinPath);
|
||||
IToolChain toolChain = new ClangToolChain(this, clangFile.toPath(), Platform.getOSArch(), vars);
|
||||
toolChain.setProperty(IToolChain.ATTR_PACKAGE, HOMEBREW_PACKAGE);
|
||||
manager.addToolChain(toolChain);
|
||||
}
|
||||
for (File gccFile : getFiles(homebrewBinPath, GCC_PATTERN)) {
|
||||
IEnvironmentVariable[] vars = createEnvironmentVariables(homebrewBinPath);
|
||||
IToolChain toolChain = new GCCToolChain(this, gccFile.toPath(), Platform.getOSArch(), vars);
|
||||
toolChain.setProperty(IToolChain.ATTR_PACKAGE, HOMEBREW_PACKAGE);
|
||||
manager.addToolChain(toolChain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File[] getFiles(Path path, Pattern filePattern) {
|
||||
File dir = path.toFile();
|
||||
if (dir.isDirectory()) {
|
||||
return dir.listFiles(file -> file.isFile() && filePattern.matcher(file.getName()).matches());
|
||||
}
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
private IEnvironmentVariable[] createEnvironmentVariables(Path path) {
|
||||
EnvironmentVariable pathVariable = new EnvironmentVariable(ENV_PATH, path.toString(),
|
||||
IEnvironmentVariable.ENVVAR_PREPEND, File.pathSeparator);
|
||||
return new IEnvironmentVariable[] { pathVariable };
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue