1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

Bug 514385: defaultValue-generation for a build-option

Change-Id: I15550a75206baf906285d3fc7becb491cac13ffa
Signed-off-by: cartu38 opendev <cartu38.opendev@gmail.com>
This commit is contained in:
cartu38 opendev 2017-04-18 09:06:25 +01:00 committed by Jonah Graham
parent 41b15da668
commit a27309d507
7 changed files with 102 additions and 1 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core; singleton:=true
Bundle-Version: 8.4.0.qualifier
Bundle-Version: 8.5.0.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -1363,6 +1363,16 @@ Additional special types exist to flag options of special relevance to the build
</documentation>
</annotation>
</attribute>
<attribute name="defaultValueGenerator" type="string">
<annotation>
<documentation>
Optional class which can be used to override the default value for an option. This class must implement the IOptionDefaultValueGenerator interface. If no generator is specified then the &apos;defaultValue&apos; attribute is used to generate the option&apos;s default value.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.managedbuilder.core.IOptionDefaultValueGenerator"/>
</appInfo>
</annotation>
</attribute>
<attribute name="command" type="string">
<annotation>
<documentation>

View file

@ -11,6 +11,7 @@
* James Blackburn (Broadcom Corp.)
* Petri Tuononen - [321040] Get Library Search Paths
* Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support
* cartu38 opendev (STMicroelectronics) - [514385] Custom defaultValue-generator support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core;
@ -107,6 +108,10 @@ public interface IOption extends IBuildObject {
public static final String TOOL_TIP = "tip"; //$NON-NLS-1$
public static final String CONTEXT_ID = "contextId"; //$NON-NLS-1$
public static final String DEFAULT_VALUE = "defaultValue"; //$NON-NLS-1$
/**
* @since 8.5
*/
public static final String DEFAULTVALUE_GENERATOR = "defaultValueGenerator"; //$NON-NLS-1$
public static final String ENUM_VALUE = "enumeratedOptionValue"; //$NON-NLS-1$
/**
* @since 8.1
@ -482,6 +487,12 @@ public interface IOption extends IBuildObject {
*/
public Object getDefaultValue();
/**
* @return an instance of the class that overrides the default defaultValue generation for the option
* @since 8.5
*/
public IOptionDefaultValueGenerator getDefaultValueGenerator();
/**
* @return the type for the value of the option.
*/

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2017 STMicroelectronics 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:
* cartu38 opendev (STMicroelectronics) - [514385] Custom defaultValue-generator support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core;
/**
* This interface can be implemented by clients to contribute custom defaultValue-generator for a
* build-option.
*
* The custom defaultValue-generator class should be referenced in the <option>/defaultValueGenerator
* attribute of the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point.
*
* @since 8.5
*/
public interface IOptionDefaultValueGenerator {
/**
* Generate the defaultValue for the given option.
*
* @param option
* the underlying build-option
* @return the generated build-option defaultValue. May return {@code null} to fall back to the default
* defaultValue generation logic.
*/
Object generateDefaultValue(IOption option);
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Intel Corporation - Initial API and implementation
* cartu38 opendev (STMicroelectronics) - [514385] Custom defaultValue-generator support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;
@ -1334,6 +1335,11 @@ public class FolderInfo extends ResourceInfo implements IFolderInfo {
IOption[] opts = holder.getOptions();
for (IOption opt : opts) {
Object val = opt.getDefaultValue();
if (opt.getDefaultValueGenerator() != null) {
val = opt.getDefaultValueGenerator().generateDefaultValue(opt);
}
if (val instanceof Boolean) {
ManagedBuildManager.setOption(toolChain.getParent(), holder, opt, (Boolean)val);
} else if (val instanceof String[]) {

View file

@ -10,6 +10,7 @@
* ARM Ltd. - basic tooltip support
* Petri Tuononen - [321040] Get Library Search Paths
* Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support
* cartu38 opendev (STMicroelectronics) - [514385] Custom defaultValue-generator support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;
@ -32,6 +33,7 @@ import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator;
import org.eclipse.cdt.managedbuilder.core.IOptionDefaultValueGenerator;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
@ -79,6 +81,8 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
private Map<String, String> namesMap;
private Object value;
private Object defaultValue;
private IConfigurationElement defaultValueGeneratorElement;
private IOptionDefaultValueGenerator defaultValueGenerator;
private Integer valueType;
private Boolean isAbstract;
private Integer resourceFilter;
@ -303,6 +307,9 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
category = option.category;
defaultValueGeneratorElement = option.defaultValueGeneratorElement;
defaultValueGenerator = option.defaultValueGenerator;
commandGeneratorElement = option.commandGeneratorElement;
commandGenerator = option.commandGenerator;
@ -366,6 +373,12 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
isAbstract = Boolean.parseBoolean(isAbs);
}
// Get the defaultValue-generator, if any
String defaultValueGeneratorStr = element.getAttribute(DEFAULTVALUE_GENERATOR);
if (defaultValueGeneratorStr != null && element instanceof DefaultManagedConfigElement) {
defaultValueGeneratorElement = ((DefaultManagedConfigElement) element).getConfigurationElement();
}
// Get the command defined for the option
command = SafeStringInterner.safeIntern(element.getAttribute(COMMAND));
@ -1228,6 +1241,26 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
return category;
}
@Override
public IOptionDefaultValueGenerator getDefaultValueGenerator() {
if (defaultValueGenerator == null) {
if (defaultValueGeneratorElement != null) {
try {
if (defaultValueGeneratorElement.getAttribute(DEFAULTVALUE_GENERATOR) != null) {
defaultValueGenerator = (IOptionDefaultValueGenerator) defaultValueGeneratorElement
.createExecutableExtension(DEFAULTVALUE_GENERATOR);
}
} catch (CoreException e) {
ManagedBuilderCorePlugin.log(e);
}
} else if (superClass != null) {
defaultValueGenerator = superClass.getDefaultValueGenerator();
}
}
return defaultValueGenerator;
}
@Override
public String getCommand() {
if (command == null) {

View file

@ -10,6 +10,7 @@
* ARM Ltd. - basic tooltip support
* Petri Tuononen - [321040] Get Library Search Paths
* Baltasar Belyavsky (Texas Instruments) - [279633] Custom command-generator support
* cartu38 opendev (STMicroelectronics) - [514385] Custom defaultValue-generator support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;
@ -27,6 +28,7 @@ import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IOptionCommandGenerator;
import org.eclipse.cdt.managedbuilder.core.IOptionDefaultValueGenerator;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.OptionStringValue;
import org.eclipse.cdt.managedbuilder.macros.IOptionContextData;
@ -765,6 +767,11 @@ public class OptionReference implements IOption {
return value;
}
@Override
public IOptionDefaultValueGenerator getDefaultValueGenerator() {
return option.getDefaultValueGenerator();
}
@Override
public void setDefaultValue(Object v) {
}