1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Hook up the clang toolchain now split out from GCC.

Change-Id: I6edba9e689d903546be3a65060c4ac1b9871167f
This commit is contained in:
Doug Schaefer 2017-11-07 11:06:07 -05:00
parent daad877559
commit b495a5faae
10 changed files with 349 additions and 238 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2017 QNX Software Systems and others.
* Copyright (c) 2017 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,7 +21,7 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
*/
public class ClangToolChain extends GCCToolChain {
private static final String TYPE_ID = "org.eclipse.cdt.build.clang"; //$NON-NLS-1$
public static final String TYPE_ID = "org.eclipse.cdt.build.clang"; //$NON-NLS-1$
public ClangToolChain(IToolChainProvider provider, Path pathToToolChain, String arch,
IEnvironmentVariable[] envVars) {

View file

@ -48,6 +48,7 @@ public class GCCUserToolChainProvider implements IUserToolChainProvider {
private static final String OPERATION = "operation"; //$NON-NLS-1$
private static final String PATH = "path"; //$NON-NLS-1$
private static final String PROPERTIES = "properties"; //$NON-NLS-1$
private static final String TYPE = "type"; //$NON-NLS-1$
private static final String VALUE = "value"; //$NON-NLS-1$
private IToolChainManager manager;
@ -73,6 +74,12 @@ public class GCCUserToolChainProvider implements IUserToolChainProvider {
toolChains = new JsonParser().parse(new FileReader(jsonFile)).getAsJsonArray();
for (JsonElement element : toolChains) {
JsonObject tc = element.getAsJsonObject();
String type;
if (tc.has(TYPE)) {
type = tc.get(TYPE).getAsString();
} else {
type = GCCToolChain.TYPE_ID;
}
String arch;
if (tc.has(ARCH)) {
arch = tc.get(ARCH).getAsString();
@ -100,14 +107,24 @@ public class GCCUserToolChainProvider implements IUserToolChainProvider {
envvars = envlist.toArray(new IEnvironmentVariable[0]);
}
GCCToolChain gcc = new GCCToolChain(this, path, arch, envvars);
if (tc.has(PROPERTIES)) {
for (JsonElement prop : tc.get(PROPERTIES).getAsJsonArray()) {
JsonObject propobj = prop.getAsJsonObject();
gcc.setProperty(propobj.get(NAME).getAsString(), propobj.get(VALUE).getAsString());
}
GCCToolChain gcc = null;
switch (type) {
case GCCToolChain.TYPE_ID:
gcc = new GCCToolChain(this, path, arch, envvars);
break;
case ClangToolChain.TYPE_ID:
gcc = new ClangToolChain(this, path, arch, envvars);
break;
}
if (gcc != null) {
if (tc.has(PROPERTIES)) {
for (JsonElement prop : tc.get(PROPERTIES).getAsJsonArray()) {
JsonObject propobj = prop.getAsJsonObject();
gcc.setProperty(propobj.get(NAME).getAsString(), propobj.get(VALUE).getAsString());
}
}
manager.addToolChain(gcc);
}
manager.addToolChain(gcc);
}
}
} catch (IOException | IllegalStateException e) {

View file

@ -12,6 +12,7 @@ import java.io.IOException;
import java.util.regex.Matcher;
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.build.gcc.core.GCCToolChain.GCCInfo;
import org.eclipse.cdt.core.build.IToolChain;
@ -26,7 +27,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
public static final String ID = "org.eclipse.cdt.build.gcc.core.gccPathProvider"; //$NON-NLS-1$
private static final Pattern gccPattern = Pattern.compile("(.*-)?((gcc|clang)(\\.exe)?)"); //$NON-NLS-1$
private static final Pattern gccPattern = Pattern.compile("(.*-)?gcc(\\.exe)?"); //$NON-NLS-1$
private static final Pattern clangPattern = Pattern.compile("clang(\\.exe)?"); //$NON-NLS-1$
@Override
public String getId() {
@ -51,7 +53,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
String[] tuple = info.target.split("-"); //$NON-NLS-1$
if (tuple.length > 2) {
GCCToolChain gcc = new GCCToolChain(this, file.toPath(), tuple[0], null);
// OS
switch (tuple[1]) {
case "w64": //$NON-NLS-1$
@ -70,6 +72,14 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
} catch (IOException e) {
Activator.log(e);
}
} else {
matcher = clangPattern.matcher(file.getName());
if (matcher.matches()) {
// TODO only support host clang for now, need to figure out multi
ClangToolChain clang = new ClangToolChain(this, file.toPath(), Platform.getOSArch(), null);
clang.setProperty(IToolChain.ATTR_OS, Platform.getOS());
manager.addToolChain(clang);
}
}
}
}

View file

@ -5,7 +5,12 @@
point="org.eclipse.cdt.ui.newToolChainWizards">
<wizard
class="org.eclipse.cdt.build.gcc.ui.internal.NewGCCToolChainWizard"
name="GCC or Compatible ToolChain"
name="GCC"
providerId="org.eclipse.cdt.build.gcc.core.provider.user">
</wizard>
<wizard
class="org.eclipse.cdt.build.gcc.ui.internal.NewClangToolChainWizard"
name="clang"
providerId="org.eclipse.cdt.build.gcc.core.provider.user">
</wizard>
</extension>

View file

@ -33,10 +33,10 @@ public class GCCToolChainSettingsPage extends WizardPage {
private Text osText;
private Text archText;
public GCCToolChainSettingsPage(GCCToolChain toolChain) {
public GCCToolChainSettingsPage(GCCToolChain toolChain, boolean isClang) {
super(GCCToolChainSettingsPage.class.getName());
this.toolChain = toolChain;
setTitle(Messages.GCCToolChainSettingsPage_Title);
setTitle(isClang ? Messages.GCCToolChainSettingsPage_ClangTitle : Messages.GCCToolChainSettingsPage_Title);
setDescription(Messages.GCCToolChainSettingsPage_Description);
}

View file

@ -1,54 +1,56 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.build.gcc.ui.internal;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.build.gcc.ui.internal.messages"; //$NON-NLS-1$
public static String GCCToolChainSettingsPage_Arch;
public static String GCCToolChainSettingsPage_Browse;
public static String GCCToolChainSettingsPage_Compiler;
public static String GCCToolChainSettingsPage_Description;
public static String GCCToolChainSettingsPage_OS;
public static String GCCToolChainSettingsPage_Title;
public static String NewEnvVarDialog_Append;
public static String NewEnvVarDialog_Delimiter;
public static String NewEnvVarDialog_Edit;
public static String NewEnvVarDialog_Name;
public static String NewEnvVarDialog_New;
public static String NewEnvVarDialog_Operation;
public static String NewEnvVarDialog_Prepend;
public static String NewEnvVarDialog_Replace;
public static String NewEnvVarDialog_Select;
public static String NewEnvVarDialog_Unset;
public static String NewEnvVarDialog_Value;
public static String NewGCCToolChainWizard_Add;
public static String NewGCCToolChainWizard_New;
public static String ToolChainEnvironmentPage_Add;
public static String ToolChainEnvironmentPage_Append;
public static String ToolChainEnvironmentPage_Description;
public static String ToolChainEnvironmentPage_Edit;
public static String ToolChainEnvironmentPage_Name;
public static String ToolChainEnvironmentPage_Operation;
public static String ToolChainEnvironmentPage_Prepend;
public static String ToolChainEnvironmentPage_Remove;
public static String ToolChainEnvironmentPage_RemoveMessage;
public static String ToolChainEnvironmentPage_RemoveTitle;
public static String ToolChainEnvironmentPage_Replace;
public static String ToolChainEnvironmentPage_Title;
public static String ToolChainEnvironmentPage_Unset;
public static String ToolChainEnvironmentPage_Value;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.build.gcc.ui.internal;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.build.gcc.ui.internal.messages"; //$NON-NLS-1$
public static String GCCToolChainSettingsPage_Arch;
public static String GCCToolChainSettingsPage_Browse;
public static String GCCToolChainSettingsPage_ClangTitle;
public static String GCCToolChainSettingsPage_Compiler;
public static String GCCToolChainSettingsPage_Description;
public static String GCCToolChainSettingsPage_OS;
public static String GCCToolChainSettingsPage_Title;
public static String NewClangToolChainWizard_Title;
public static String NewEnvVarDialog_Append;
public static String NewEnvVarDialog_Delimiter;
public static String NewEnvVarDialog_Edit;
public static String NewEnvVarDialog_Name;
public static String NewEnvVarDialog_New;
public static String NewEnvVarDialog_Operation;
public static String NewEnvVarDialog_Prepend;
public static String NewEnvVarDialog_Replace;
public static String NewEnvVarDialog_Select;
public static String NewEnvVarDialog_Unset;
public static String NewEnvVarDialog_Value;
public static String NewGCCToolChainWizard_Add;
public static String NewGCCToolChainWizard_New;
public static String ToolChainEnvironmentPage_Add;
public static String ToolChainEnvironmentPage_Append;
public static String ToolChainEnvironmentPage_Description;
public static String ToolChainEnvironmentPage_Edit;
public static String ToolChainEnvironmentPage_Name;
public static String ToolChainEnvironmentPage_Operation;
public static String ToolChainEnvironmentPage_Prepend;
public static String ToolChainEnvironmentPage_Remove;
public static String ToolChainEnvironmentPage_RemoveMessage;
public static String ToolChainEnvironmentPage_RemoveTitle;
public static String ToolChainEnvironmentPage_Replace;
public static String ToolChainEnvironmentPage_Title;
public static String ToolChainEnvironmentPage_Unset;
public static String ToolChainEnvironmentPage_Value;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.build.gcc.ui.internal;
import java.nio.file.Path;
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
import org.eclipse.cdt.build.gcc.core.GCCToolChain;
import org.eclipse.cdt.build.gcc.core.GCCUserToolChainProvider;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.build.IUserToolChainProvider;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.ui.build.ToolChainWizard;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
public class NewClangToolChainWizard extends ToolChainWizard {
private GCCToolChainSettingsPage settingsPage;
private ToolChainEnvironmentPage envPage;
@Override
public boolean performFinish() {
Path path = settingsPage.getPath();
String os = settingsPage.getOS();
String arch = settingsPage.getArch();
IEnvironmentVariable[] envvars = envPage.getEnvVars();
new Job(Messages.NewGCCToolChainWizard_Add) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
IToolChainManager manager = Activator.getService(IToolChainManager.class);
IUserToolChainProvider provider = (IUserToolChainProvider) manager
.getProvider(GCCUserToolChainProvider.PROVIDER_ID);
if (toolChain != null) {
provider.removeToolChain(toolChain);
}
ClangToolChain gcc = new ClangToolChain(provider, path, arch, envvars);
gcc.setProperty(IToolChain.ATTR_OS, os);
provider.addToolChain(gcc);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
}.schedule();
return true;
}
@Override
public void addPages() {
super.addPages();
settingsPage = new GCCToolChainSettingsPage((GCCToolChain) toolChain, true);
addPage(settingsPage);
envPage = new ToolChainEnvironmentPage(toolChain);
addPage(envPage);
setWindowTitle(Messages.NewClangToolChainWizard_Title);
}
}

View file

@ -62,7 +62,7 @@ public class NewGCCToolChainWizard extends ToolChainWizard {
public void addPages() {
super.addPages();
settingsPage = new GCCToolChainSettingsPage((GCCToolChain) toolChain);
settingsPage = new GCCToolChainSettingsPage((GCCToolChain) toolChain, false);
addPage(settingsPage);
envPage = new ToolChainEnvironmentPage(toolChain);

View file

@ -1,40 +1,42 @@
################################################################################
# Copyright (c) 2017 QNX Software Systems and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
################################################################################
GCCToolChainSettingsPage_Arch=CPU Architecture:
GCCToolChainSettingsPage_Browse=Browse...
GCCToolChainSettingsPage_Compiler=Compiler:
GCCToolChainSettingsPage_Description=Enter the path to the compiler and properties for the toolchain.
GCCToolChainSettingsPage_OS=Operating System:
GCCToolChainSettingsPage_Title=GCC ToolChain Settings
NewEnvVarDialog_Append=Append
NewEnvVarDialog_Delimiter=Delimiter:
NewEnvVarDialog_Edit=Edit Environment Variable
NewEnvVarDialog_Name=Name:
NewEnvVarDialog_New=New Environment Variable
NewEnvVarDialog_Operation=Operation
NewEnvVarDialog_Prepend=Prepend
NewEnvVarDialog_Replace=Replace
NewEnvVarDialog_Select=Select...
NewEnvVarDialog_Unset=Unset
NewEnvVarDialog_Value=Value:
NewGCCToolChainWizard_Add=Add ToolChain
NewGCCToolChainWizard_New=New GCC ToolChain
ToolChainEnvironmentPage_Add=Add...
ToolChainEnvironmentPage_Append=Append
ToolChainEnvironmentPage_Description=Environment variables to set when using toolchain.
ToolChainEnvironmentPage_Edit=Edit...
ToolChainEnvironmentPage_Name=Name
ToolChainEnvironmentPage_Operation=Operation
ToolChainEnvironmentPage_Prepend=Prepend
ToolChainEnvironmentPage_Remove=Remove
ToolChainEnvironmentPage_RemoveMessage=Are you sure you would like to remove the selected environment variable(s)
ToolChainEnvironmentPage_RemoveTitle=Remove
ToolChainEnvironmentPage_Replace=Replace
ToolChainEnvironmentPage_Title=Environment Variables
ToolChainEnvironmentPage_Unset=Unset
ToolChainEnvironmentPage_Value=Value
################################################################################
# Copyright (c) 2017 QNX Software Systems and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
################################################################################
GCCToolChainSettingsPage_Arch=CPU Architecture:
GCCToolChainSettingsPage_Browse=Browse...
GCCToolChainSettingsPage_ClangTitle=clang Toolchain Settings
GCCToolChainSettingsPage_Compiler=Compiler:
GCCToolChainSettingsPage_Description=Enter the path to the compiler and properties for the toolchain.
GCCToolChainSettingsPage_OS=Operating System:
GCCToolChainSettingsPage_Title=GCC ToolChain Settings
NewClangToolChainWizard_Title=New clang Toolchain
NewEnvVarDialog_Append=Append
NewEnvVarDialog_Delimiter=Delimiter:
NewEnvVarDialog_Edit=Edit Environment Variable
NewEnvVarDialog_Name=Name:
NewEnvVarDialog_New=New Environment Variable
NewEnvVarDialog_Operation=Operation
NewEnvVarDialog_Prepend=Prepend
NewEnvVarDialog_Replace=Replace
NewEnvVarDialog_Select=Select...
NewEnvVarDialog_Unset=Unset
NewEnvVarDialog_Value=Value:
NewGCCToolChainWizard_Add=Add ToolChain
NewGCCToolChainWizard_New=New GCC ToolChain
ToolChainEnvironmentPage_Add=Add...
ToolChainEnvironmentPage_Append=Append
ToolChainEnvironmentPage_Description=Environment variables to set when using toolchain.
ToolChainEnvironmentPage_Edit=Edit...
ToolChainEnvironmentPage_Name=Name
ToolChainEnvironmentPage_Operation=Operation
ToolChainEnvironmentPage_Prepend=Prepend
ToolChainEnvironmentPage_Remove=Remove
ToolChainEnvironmentPage_RemoveMessage=Are you sure you would like to remove the selected environment variable(s)
ToolChainEnvironmentPage_RemoveTitle=Remove
ToolChainEnvironmentPage_Replace=Replace
ToolChainEnvironmentPage_Title=Environment Variables
ToolChainEnvironmentPage_Unset=Unset
ToolChainEnvironmentPage_Value=Value

View file

@ -1,129 +1,129 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="newToolChainWizards" name="New ToolChain Wizards"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="wizard"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="wizard">
<complexType>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="icon" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="resource"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.ui.build.ToolChainWizard:"/>
</appInfo>
</annotation>
</attribute>
<attribute name="providerId" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.core.toolChainProvider/provider/@id"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="newToolChainWizards" name="New ToolChain Wizards"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="wizard"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="wizard">
<complexType>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="icon" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="resource"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.ui.build.ToolChainWizard:"/>
</appInfo>
</annotation>
</attribute>
<attribute name="providerId" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.core.toolChainProvider/provider/@id"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>