From cf74c35e5b638b7f3e8c67f2a08e87587ddb1bdd Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Fri, 27 Jun 2025 16:04:00 +0100 Subject: [PATCH] Detect Homebrew installations on macOS hosts We provide immediate access to tools installed using the Homebrew package manager as for the MSYS2 package manager. --- .../META-INF/MANIFEST.MF | 5 +- .../plugin.xml | 4 +- .../MacosEnvironmentVariableSupplier.java | 64 ++++++++++++ .../eclipse/cdt/internal/core/Homebrew.java | 98 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../ui/LlvmEnvironmentVariableSupplier.java | 42 +++++--- 6 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/macos/MacosEnvironmentVariableSupplier.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Homebrew.java diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF index 6c24e923a5b..17350090e11 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF @@ -2,17 +2,18 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.gnu.ui; singleton:=true -Bundle-Version: 8.7.300.qualifier +Bundle-Version: 8.7.400.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.cdt.managedbuilder.gnu.cygwin, + org.eclipse.cdt.managedbuilder.gnu.macos;x-internal:=true, org.eclipse.cdt.managedbuilder.gnu.mingw;x-internal:=true, org.eclipse.cdt.managedbuilder.gnu.templates;x-internal:=true, org.eclipse.cdt.managedbuilder.gnu.ui Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4.0.0)", org.eclipse.cdt.managedbuilder.core;bundle-version="[9.7.100,10.0.0)", - org.eclipse.cdt.core;bundle-version="[9.1.0,10.0.0)", + org.eclipse.cdt.core;bundle-version="[9.2.0,10.0.0)", org.eclipse.core.resources;bundle-version="[3.22.200,4)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml index f8bcf8c12d8..2a05b502b37 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml @@ -1,7 +1,7 @@ @@ -2270,6 +2271,7 @@ Contributors: llvmEnvironmentVariables = new HashMap<>(6); + private static HashMap llvmEnvironmentVariables = new HashMap<>(7); // Environment variables for HashMap usage private static final String ENV_VAR_NAME_LLVM_BIN = "LLVM_BIN_PATH"; //$NON-NLS-1$ private static final String ENV_VAR_NAME_LLVMINTERP = "LLVMINTERP"; //$NON-NLS-1$ @@ -52,10 +55,12 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen private static final String ENV_VAR_NAME_LIBRARIES = "LIBRARIES"; //$NON-NLS-1$ private static final List LLVM_BIN_SELECTION_TOOLS = List.of("llvm-ar", "clang"); //$NON-NLS-1$ //$NON-NLS-2$ + private static boolean isInitialized = false; + /** * Initializes llvm environment variable paths from the system environment variables. */ - public static void initializePaths() { //TODO: Is this actually called anywhere? + public static void initializePaths() { // get bin path String binPath = getBinPath(); // set LLVM bin path environment variable @@ -69,16 +74,12 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen // try to find mingw or cygwin path from PATH environment variable IBuildEnvironmentVariable envPath = llvmEnvironmentVariables.get(ENV_VAR_NAME_PATH); IBuildEnvironmentVariable mingwPath = null, cygwinPath = null; - // if path is empty - if (envPath == null) { - // try to find mingw path from MingwEnvironmentVariableSupplier - IConfigurationEnvironmentVariableSupplier mingwEnvironmentVariables = new MingwEnvironmentVariableSupplier(); - mingwPath = mingwEnvironmentVariables.getVariable(ENV_VAR_NAME_PATH, null, null); - // try to find cygwin path from GnuCygwinConfigurationEnvironmentSupplier - IConfigurationEnvironmentVariableSupplier cygwinEnvironmentVariables = new GnuCygwinConfigurationEnvironmentSupplier(); - cygwinPath = cygwinEnvironmentVariables.getVariable(ENV_VAR_NAME_PATH, null, null); - - } + // try to find mingw path from MingwEnvironmentVariableSupplier + IConfigurationEnvironmentVariableSupplier mingwEnvironmentVariables = new MingwEnvironmentVariableSupplier(); + mingwPath = mingwEnvironmentVariables.getVariable(ENV_VAR_NAME_PATH, null, null); + // try to find cygwin path from GnuCygwinConfigurationEnvironmentSupplier + IConfigurationEnvironmentVariableSupplier cygwinEnvironmentVariables = new GnuCygwinConfigurationEnvironmentSupplier(); + cygwinPath = cygwinEnvironmentVariables.getVariable(ENV_VAR_NAME_PATH, null, null); // if mingw found if (mingwPath != null) { //form full path @@ -93,6 +94,14 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen //TODO: Emit proper error message and enter it to Eclipse error log. e.printStackTrace(); } + } else if (Platform.OS_MACOSX.equals(Platform.getOS())) { + // use MacosEnvironmentVariableSupplier to find PATH + IBuildEnvironmentVariable macosPath = new MacosEnvironmentVariableSupplier() + .getVariable(ENV_VAR_NAME_PATH, null, null); + if (macosPath != null) { + setLlvmEnvironmentVariable(Homebrew.ENV_HOMEBREW_HOME, Homebrew.getHomebrewHome()); + pathStr += File.pathSeparator + macosPath.getValue(); + } } //initialize environment variable cache values setLlvmEnvironmentVariable(ENV_VAR_NAME_PATH, pathStr); @@ -440,15 +449,24 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen return ""; //$NON-NLS-1$ } + private static synchronized void init() { + if (!isInitialized) { + initializePaths(); + isInitialized = true; + } + } + @Override public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) { + init(); return llvmEnvironmentVariables.get(variableName); } @Override public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) { + init(); return llvmEnvironmentVariables.values().toArray(new IBuildEnvironmentVariable[0]); } }