Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 310819
Collapse All | Expand All

(-)plugin.xml (+8 lines)
Lines 597-601 Link Here
597
         </run>
597
         </run>
598
      </application>
598
      </application>
599
   </extension>
599
   </extension>
600
   <extension
601
         id="headlessSettings"
602
         name="HeadlessBuilder Additional Settings"
603
         point="org.eclipse.cdt.core.externalSettingsProvider">
604
      <provider
605
            class="org.eclipse.cdt.managedbuilder.internal.core.HeadlessBuilderExternalSettingsProvider">
606
      </provider>
607
   </extension>
600
608
601
</plugin>
609
</plugin>
(-)src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java (+29 lines)
Lines 30-35 Link Here
30
30
31
import org.eclipse.cdt.core.model.CoreModel;
31
import org.eclipse.cdt.core.model.CoreModel;
32
import org.eclipse.cdt.core.resources.ACBuilder;
32
import org.eclipse.cdt.core.resources.ACBuilder;
33
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
34
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
35
import org.eclipse.cdt.core.settings.model.CMacroEntry;
33
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
36
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
34
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
37
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
35
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
38
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
Lines 70-75 Link Here
70
 *   - Import all projects in the tree :       -importAll  {[uri:/]/path/to/projectTreeURI}
73
 *   - Import all projects in the tree :       -importAll  {[uri:/]/path/to/projectTreeURI}
71
 *   - Build projects / the workspace :        -build      {project_name_reg_ex/config_name_reg_ex | all}
74
 *   - Build projects / the workspace :        -build      {project_name_reg_ex/config_name_reg_ex | all}
72
 *   - Clean build projects / the workspace :  -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
75
 *   - Clean build projects / the workspace :  -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
76
 *   - Add Include path to build :             -I          {include_path}
77
 *   - Add Include file to build :             -include    {include_file}
78
 *   - Add preprocessor define to build :      -D          {prepoc_define}
73
 *
79
 *
74
 * Build output is automatically sent to stdout.
80
 * Build output is automatically sent to stdout.
75
 * @since 6.0
81
 * @since 6.0
Lines 363-368 Link Here
363
					return status;
369
					return status;
364
			}
370
			}
365
371
372
			// Hook in our external settings to the build
373
			HeadlessBuilderExternalSettingsProvider.hookExternalSettingsProvider();
374
366
			IProject[] allProjects = root.getProjects();
375
			IProject[] allProjects = root.getProjects();
367
			// Map from Project -> Configurations to build. We also Build all projects which are clean'd
376
			// Map from Project -> Configurations to build. We also Build all projects which are clean'd
368
			Map<IProject, Set<ICConfigurationDescription>> configsToBuild = new HashMap<IProject, Set<ICConfigurationDescription>>();
377
			Map<IProject, Set<ICConfigurationDescription>> configsToBuild = new HashMap<IProject, Set<ICConfigurationDescription>>();
Lines 411-416 Link Here
411
			} finally {
420
			} finally {
412
				// Reset the build_all_configs preference value to its previous state
421
				// Reset the build_all_configs preference value to its previous state
413
				ACBuilder.setAllConfigBuild(buildAllConfigs);
422
				ACBuilder.setAllConfigBuild(buildAllConfigs);
423
				// Unhook the external settings provider
424
				HeadlessBuilderExternalSettingsProvider.unhookExternalSettingsProvider();
414
			}
425
			}
415
		} finally {
426
		} finally {
416
			// Wait for any outstanding jobs to finish
427
			// Wait for any outstanding jobs to finish
Lines 466-471 Link Here
466
	 *   -importAll  {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
477
	 *   -importAll  {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
467
	 *   -build      {project_name_reg_ex/config_name_reg_ex | all}
478
	 *   -build      {project_name_reg_ex/config_name_reg_ex | all}
468
	 *   -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
479
	 *   -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
480
	 *   -I          {include_path} additional include_path to add to tools
481
	 *   -include    {include_file} additional include_file to pass to tools
482
	 *   -D          {prepoc_define} addition preprocessor defines to pass to the tools
469
	 *
483
	 *
470
	 * Each argument may be specified more than once
484
	 * Each argument may be specified more than once
471
	 * @param args String[] of arguments to parse
485
	 * @param args String[] of arguments to parse
Lines 484-489 Link Here
484
					projectRegExToBuild.add(args[++i]);
498
					projectRegExToBuild.add(args[++i]);
485
				} else if ("-cleanBuild".equals(args[i])) { //$NON-NLS-1$
499
				} else if ("-cleanBuild".equals(args[i])) { //$NON-NLS-1$
486
					projectRegExToClean.add(args[++i]);
500
					projectRegExToClean.add(args[++i]);
501
				} else if ("-D".equals(args[i])) { //$NON-NLS-1$
502
					String macro = args[++i];
503
					String macroVal = ""; //$NON-NLS-1$
504
					if (macro.indexOf('=') != -1) {
505
						macroVal = macro.substring(macro.indexOf('=') + 1);
506
						macro = macro.substring(0, macro.indexOf('='));
507
					}
508
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CMacroEntry(macro, macroVal, 0));
509
				} else if ("-I".equals(args[i])) { //$NON-NLS-1$
510
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludePathEntry(args[++i], 0));
511
				} else if ("-include".equals(args[i])) { //$NON-NLS-1$
512
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludeFileEntry(args[++i], 0));
487
				} else {
513
				} else {
488
					throw new Exception(HeadlessBuildMessages.HeadlessBuilder_unknown_argument + args[i]);
514
					throw new Exception(HeadlessBuildMessages.HeadlessBuilder_unknown_argument + args[i]);
489
				}
515
				}
Lines 497-502 Link Here
497
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_importAll);
523
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_importAll);
498
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_build);
524
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_build);
499
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_clean_build);
525
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_usage_clean_build);
526
			System.err.println("   -I          {include_path} additional include_path to add to tools");
527
			System.err.println("   -include    {include_file} additional include_file to pass to tools");
528
			System.err.println("   -D          {prepoc_define} addition preprocessor defines to pass to the tools");
500
			return false;
529
			return false;
501
		}
530
		}
502
531
(-)src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilderExternalSettingsProvider.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Broadcom Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * James Blackburn (Broadcom Corp.) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.managedbuilder.internal.core;
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.cdt.core.CCorePlugin;
19
import org.eclipse.cdt.core.model.CoreModel;
20
import org.eclipse.cdt.core.settings.model.CExternalSetting;
21
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
22
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
23
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
24
import org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider;
25
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
26
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.CoreException;
29
30
/**
31
 * This class allows extending the set of -D's, -I's and -includes that
32
 * are passed to projects using the external settings provider mechanism.
33
 */
34
public class HeadlessBuilderExternalSettingsProvider extends CExternalSettingProvider {
35
36
	private static final String ID = "org.eclipse.cdt.managedbuilder.core.headlessSettings"; //$NON-NLS-1$
37
38
	/** List of external settings which should be appended to build */
39
	static List<ICSettingEntry> additionalSettings = new ArrayList<ICSettingEntry>();
40
41
	public HeadlessBuilderExternalSettingsProvider() {
42
	}
43
44
	@Override
45
	public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfg) {
46
		if (additionalSettings.isEmpty())
47
			return new CExternalSetting[0];
48
		return new CExternalSetting[] { new CExternalSetting(null, null, null, additionalSettings.toArray(new ICSettingEntry[additionalSettings.size()])) };
49
	}
50
51
	/**
52
	 * Hook the external settings provider if the user has added c settings
53
	 */
54
	static void hookExternalSettingsProvider() {
55
		if (additionalSettings.isEmpty())
56
			return;
57
		// Remove the external settings providers from all the hooked projects
58
		for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
59
			ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project);
60
			if (desc == null)
61
				continue;
62
			for (ICConfigurationDescription cfg : desc.getConfigurations()) {
63
				String[] extSettingIds = cfg.getExternalSettingsProviderIds();
64
				String[] newSettingIds = new String[extSettingIds.length + 1];
65
				System.arraycopy(extSettingIds, 0, newSettingIds, 0, extSettingIds.length);
66
				newSettingIds[extSettingIds.length] = ID;
67
				cfg.setExternalSettingsProviderIds(newSettingIds);
68
			}
69
			try {
70
				CoreModel.getDefault().setProjectDescription(project, desc);
71
			} catch (CoreException e) {
72
				ManagedBuilderCorePlugin.log(e);
73
			}
74
		}
75
	}
76
77
	/**
78
	 * Unhook the external settings provider if the user has added c settings
79
	 */
80
	static void unhookExternalSettingsProvider() {
81
		if (additionalSettings.isEmpty())
82
			return;
83
84
		// Remove the external settings providers from all the hooked projects
85
		for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
86
			ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project);
87
			if (desc == null)
88
				continue;
89
			for (ICConfigurationDescription cfg : desc.getConfigurations()) {
90
				ArrayList<String> extSettingIds = new ArrayList<String>(Arrays.asList(cfg.getExternalSettingsProviderIds()));
91
				for (Iterator<String> it = extSettingIds.iterator(); it.hasNext();)
92
					if (ID.equals(it.next()))
93
						it.remove();
94
				cfg.setExternalSettingsProviderIds(extSettingIds.toArray(new String[extSettingIds.size()]));
95
			}
96
			try {
97
				CoreModel.getDefault().setProjectDescription(project, desc);
98
			} catch (CoreException e) {
99
				ManagedBuilderCorePlugin.log(e);
100
			}
101
		}
102
	}
103
104
}

Return to bug 310819