mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +02:00
Bug 310819 Headless Builder need a way to extend set of -Ds -Is and -includes
This commit is contained in:
parent
1285350432
commit
72d386703f
5 changed files with 147 additions and 0 deletions
|
@ -597,5 +597,13 @@
|
|||
</run>
|
||||
</application>
|
||||
</extension>
|
||||
<extension
|
||||
id="headlessSettings"
|
||||
name="HeadlessBuilder Additional Settings"
|
||||
point="org.eclipse.cdt.core.externalSettingsProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.managedbuilder.internal.core.HeadlessBuilderExternalSettingsProvider">
|
||||
</provider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -24,6 +24,8 @@ public class HeadlessBuildMessages extends NLS {
|
|||
public static String HeadlessBuilder_Directory;
|
||||
public static String HeadlessBuilder_Error;
|
||||
public static String HeadlessBuilder_importAll;
|
||||
public static String HeadlessBuilder_IncludeFile;
|
||||
public static String HeadlessBuilder_InlucdePath;
|
||||
public static String HeadlessBuilder_invalid_argument;
|
||||
public static String HeadlessBuilder_is_not_accessible;
|
||||
public static String HeadlessBuilder_is_not_valid_in_workspace;
|
||||
|
@ -43,6 +45,7 @@ public class HeadlessBuildMessages extends NLS {
|
|||
public static String HeadlessBuilder_usage_build;
|
||||
public static String HeadlessBuilder_usage_clean_build;
|
||||
public static String HeadlessBuilder_invalid_uri;
|
||||
public static String HeadlessBuilder_PreprocessorDefine;
|
||||
public static String HeadlessBuilder_usage_import;
|
||||
public static String HeadlessBuilder_Workspace;
|
||||
public static String HeadlessBuilder_WorkspaceInUse;
|
||||
|
|
|
@ -30,6 +30,9 @@ import java.util.regex.PatternSyntaxException;
|
|||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.resources.ACBuilder;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
|
@ -70,6 +73,9 @@ import org.eclipse.osgi.service.datalocation.Location;
|
|||
* - Import all projects in the tree : -importAll {[uri:/]/path/to/projectTreeURI}
|
||||
* - Build projects / the workspace : -build {project_name_reg_ex/config_name_reg_ex | all}
|
||||
* - Clean build projects / the workspace : -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
|
||||
* - Add Include path to build : -I {include_path}
|
||||
* - Add Include file to build : -include {include_file}
|
||||
* - Add preprocessor define to build : -D {prepoc_define}
|
||||
*
|
||||
* Build output is automatically sent to stdout.
|
||||
* @since 6.0
|
||||
|
@ -363,6 +369,9 @@ public class HeadlessBuilder implements IApplication {
|
|||
return status;
|
||||
}
|
||||
|
||||
// Hook in our external settings to the build
|
||||
HeadlessBuilderExternalSettingsProvider.hookExternalSettingsProvider();
|
||||
|
||||
IProject[] allProjects = root.getProjects();
|
||||
// Map from Project -> Configurations to build. We also Build all projects which are clean'd
|
||||
Map<IProject, Set<ICConfigurationDescription>> configsToBuild = new HashMap<IProject, Set<ICConfigurationDescription>>();
|
||||
|
@ -411,6 +420,8 @@ public class HeadlessBuilder implements IApplication {
|
|||
} finally {
|
||||
// Reset the build_all_configs preference value to its previous state
|
||||
ACBuilder.setAllConfigBuild(buildAllConfigs);
|
||||
// Unhook the external settings provider
|
||||
HeadlessBuilderExternalSettingsProvider.unhookExternalSettingsProvider();
|
||||
}
|
||||
} finally {
|
||||
// Wait for any outstanding jobs to finish
|
||||
|
@ -466,6 +477,9 @@ public class HeadlessBuilder implements IApplication {
|
|||
* -importAll {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
|
||||
* -build {project_name_reg_ex/config_name_reg_ex | all}
|
||||
* -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
|
||||
* -I {include_path} additional include_path to add to tools
|
||||
* -include {include_file} additional include_file to pass to tools
|
||||
* -D {prepoc_define} addition preprocessor defines to pass to the tools
|
||||
*
|
||||
* Each argument may be specified more than once
|
||||
* @param args String[] of arguments to parse
|
||||
|
@ -484,6 +498,18 @@ public class HeadlessBuilder implements IApplication {
|
|||
projectRegExToBuild.add(args[++i]);
|
||||
} else if ("-cleanBuild".equals(args[i])) { //$NON-NLS-1$
|
||||
projectRegExToClean.add(args[++i]);
|
||||
} else if ("-D".equals(args[i])) { //$NON-NLS-1$
|
||||
String macro = args[++i];
|
||||
String macroVal = ""; //$NON-NLS-1$
|
||||
if (macro.indexOf('=') != -1) {
|
||||
macroVal = macro.substring(macro.indexOf('=') + 1);
|
||||
macro = macro.substring(0, macro.indexOf('='));
|
||||
}
|
||||
HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CMacroEntry(macro, macroVal, 0));
|
||||
} else if ("-I".equals(args[i])) { //$NON-NLS-1$
|
||||
HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludePathEntry(args[++i], 0));
|
||||
} else if ("-include".equals(args[i])) { //$NON-NLS-1$
|
||||
HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludeFileEntry(args[++i], 0));
|
||||
} else {
|
||||
throw new Exception(HeadlessBuildMessages.HeadlessBuilder_unknown_argument + args[i]);
|
||||
}
|
||||
|
@ -497,6 +523,9 @@ public class HeadlessBuilder implements IApplication {
|
|||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_importAll);
|
||||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_build);
|
||||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_clean_build);
|
||||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_InlucdePath);
|
||||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_IncludeFile);
|
||||
System.err.println(HeadlessBuildMessages.HeadlessBuilder_PreprocessorDefine);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Broadcom Corporation 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
|
||||
*
|
||||
* Contributors:
|
||||
* James Blackburn (Broadcom Corp.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.internal.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* This class allows extending the set of -D's, -I's and -includes that
|
||||
* are passed to projects using the external settings provider mechanism.
|
||||
*/
|
||||
public class HeadlessBuilderExternalSettingsProvider extends CExternalSettingProvider {
|
||||
|
||||
private static final String ID = "org.eclipse.cdt.managedbuilder.core.headlessSettings"; //$NON-NLS-1$
|
||||
|
||||
/** List of external settings which should be appended to build */
|
||||
static List<ICSettingEntry> additionalSettings = new ArrayList<ICSettingEntry>();
|
||||
|
||||
public HeadlessBuilderExternalSettingsProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfg) {
|
||||
if (additionalSettings.isEmpty())
|
||||
return new CExternalSetting[0];
|
||||
return new CExternalSetting[] { new CExternalSetting(null, null, null, additionalSettings.toArray(new ICSettingEntry[additionalSettings.size()])) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook the external settings provider if the user has added c settings
|
||||
*/
|
||||
static void hookExternalSettingsProvider() {
|
||||
if (additionalSettings.isEmpty())
|
||||
return;
|
||||
// Remove the external settings providers from all the hooked projects
|
||||
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
|
||||
ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
if (desc == null)
|
||||
continue;
|
||||
for (ICConfigurationDescription cfg : desc.getConfigurations()) {
|
||||
String[] extSettingIds = cfg.getExternalSettingsProviderIds();
|
||||
String[] newSettingIds = new String[extSettingIds.length + 1];
|
||||
System.arraycopy(extSettingIds, 0, newSettingIds, 0, extSettingIds.length);
|
||||
newSettingIds[extSettingIds.length] = ID;
|
||||
cfg.setExternalSettingsProviderIds(newSettingIds);
|
||||
}
|
||||
try {
|
||||
CoreModel.getDefault().setProjectDescription(project, desc);
|
||||
} catch (CoreException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhook the external settings provider if the user has added c settings
|
||||
*/
|
||||
static void unhookExternalSettingsProvider() {
|
||||
if (additionalSettings.isEmpty())
|
||||
return;
|
||||
|
||||
// Remove the external settings providers from all the hooked projects
|
||||
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
|
||||
ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
if (desc == null)
|
||||
continue;
|
||||
for (ICConfigurationDescription cfg : desc.getConfigurations()) {
|
||||
ArrayList<String> extSettingIds = new ArrayList<String>(Arrays.asList(cfg.getExternalSettingsProviderIds()));
|
||||
for (Iterator<String> it = extSettingIds.iterator(); it.hasNext();)
|
||||
if (ID.equals(it.next()))
|
||||
it.remove();
|
||||
cfg.setExternalSettingsProviderIds(extSettingIds.toArray(new String[extSettingIds.size()]));
|
||||
}
|
||||
try {
|
||||
CoreModel.getDefault().setProjectDescription(project, desc);
|
||||
} catch (CoreException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -189,8 +189,11 @@ HeadlessBuilder_usage_build=\ \ \ -build {project_name_reg_ex{/config_reg_e
|
|||
HeadlessBuilder_usage_clean_build=\ \ \ -cleanBuild {project_name_reg_ex{/config_reg_ex} | all}
|
||||
HeadlessBuilder_usage_import=\ \ \ -import {[uri:/]/path/to/project}
|
||||
HeadlessBuilder_importAll=\ \ \ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI
|
||||
HeadlessBuilder_IncludeFile=\ \ \ -include {include_file} additional include_file to pass to tools
|
||||
HeadlessBuilder_InlucdePath=\ \ \ -I {include_path} additional include_path to add to tools
|
||||
HeadlessBuilder_invalid_uri=Invalid project URI:
|
||||
HeadlessBuilder_MustSpecifyWorkspace=Must specify a location for the workspace. Restart with the '-data' switch.
|
||||
HeadlessBuilder_PreprocessorDefine=\ \ \ -D {prepoc_define} addition preprocessor defines to pass to the tools
|
||||
HeadlessBuilder_Workspace=Workspace
|
||||
HeadlessBuilder_WorkspaceInUse=Workspace already in use\!
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue