mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-05 16:15:25 +02:00
Bug 496357 - Make Arduino Build configs target specific.
This allows us to change properties of the target and not get the builds confused. Also makes more sense to the user. Change-Id: Ic0b6be0699a366c20c5aedc9ec82451e0b3b0899
This commit is contained in:
parent
e9c8d30150
commit
acf0f4a943
5 changed files with 98 additions and 160 deletions
|
@ -31,8 +31,11 @@ public interface ICBuildConfiguration extends IAdaptable, IScannerInfoProvider {
|
|||
/**
|
||||
* CDT doesn't like that the Platform default config name is an empty string.
|
||||
* It needs a real name for the name of the build directory, for example.
|
||||
*
|
||||
* @deprecated each build config can use their own default name.
|
||||
*/
|
||||
public static String DEFAULT_NAME = "default";
|
||||
@Deprecated
|
||||
public static String DEFAULT_NAME = "default"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the resources build configuration that this CDT build
|
||||
|
|
|
@ -158,7 +158,7 @@ public class FullIntegration {
|
|||
ArduinoRemoteConnection arduinoTarget = createTarget(board);
|
||||
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
|
||||
.getProvider(ArduinoBuildConfigurationProvider.ID);
|
||||
ArduinoBuildConfiguration config = provider.createConfiguration(project, arduinoTarget, "run", monitor);
|
||||
ArduinoBuildConfiguration config = provider.getConfiguration(project, arduinoTarget, "run", monitor);
|
||||
|
||||
System.out.println(String.format("Building board: %s\n %s - %s", board.getName(), board.getId(),
|
||||
board.getPlatform().getInstallPath()));
|
||||
|
@ -181,12 +181,16 @@ public class FullIntegration {
|
|||
|
||||
private ArduinoRemoteConnection createTarget(ArduinoBoard board) throws Exception {
|
||||
IRemoteConnectionType type = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
IRemoteConnection connection = type.getConnection(board.getName());
|
||||
String arch = board.getPlatform().getArchitecture();
|
||||
String pkg = board.getPlatform().getPackage().getName();
|
||||
String targetName = pkg + '-' + arch + '-' + board.getName().replace('/', '_');
|
||||
|
||||
IRemoteConnection connection = type.getConnection(targetName);
|
||||
if (connection != null) {
|
||||
type.removeConnection(connection);
|
||||
}
|
||||
|
||||
IRemoteConnectionWorkingCopy workingCopy = type.newConnection(board.getName());
|
||||
IRemoteConnectionWorkingCopy workingCopy = type.newConnection(targetName);
|
||||
ArduinoRemoteConnection.setBoardId(workingCopy, board);
|
||||
ArduinoRemoteConnection.setPortName(workingCopy, "port1");
|
||||
|
||||
|
|
|
@ -69,113 +69,55 @@ import org.eclipse.core.runtime.IStatus;
|
|||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
|
||||
import freemarker.cache.TemplateLoader;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
public class ArduinoBuildConfiguration extends CBuildConfiguration implements TemplateLoader {
|
||||
public class ArduinoBuildConfiguration extends CBuildConfiguration
|
||||
implements TemplateLoader, IRemoteConnectionChangeListener {
|
||||
|
||||
private static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$
|
||||
private static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$
|
||||
private static final String BOARD_NAME = "boardName"; //$NON-NLS-1$
|
||||
private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$
|
||||
private static final String PROGRAMMER = "programmer"; //$NON-NLS-1$
|
||||
private static final ArduinoManager manager = Activator.getService(ArduinoManager.class);
|
||||
private static final boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
|
||||
|
||||
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
|
||||
|
||||
private final ArduinoBoard board;
|
||||
private final ArduinoRemoteConnection target;
|
||||
private final String launchMode;
|
||||
private ArduinoBoard defaultBoard;
|
||||
private Properties properties;
|
||||
|
||||
// for Makefile generation
|
||||
private Configuration templateConfig;
|
||||
|
||||
private final static boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
|
||||
|
||||
public ArduinoBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
|
||||
super(config, name);
|
||||
|
||||
Preferences settings = getSettings();
|
||||
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
|
||||
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$
|
||||
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$
|
||||
ArduinoBoard b = manager.getBoard(packageName, platformName, boardName);
|
||||
|
||||
if (b == null) {
|
||||
// Default to Uno or first one we find
|
||||
b = manager.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
if (b == null) {
|
||||
Collection<ArduinoBoard> boards = manager.getInstalledBoards();
|
||||
if (!boards.isEmpty()) {
|
||||
b = boards.iterator().next();
|
||||
}
|
||||
}
|
||||
}
|
||||
board = b;
|
||||
|
||||
int i = name.lastIndexOf('.');
|
||||
this.launchMode = name.substring(i + 1);
|
||||
/**
|
||||
* Default configuration.
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
ArduinoBuildConfiguration(IBuildConfiguration config, String name, String launchMode, ArduinoBoard defaultBoard, IToolChain toolChain) throws CoreException {
|
||||
super(config, ".default", toolChain); //$NON-NLS-1$
|
||||
this.target = null;
|
||||
this.launchMode = launchMode;
|
||||
this.defaultBoard = defaultBoard;
|
||||
}
|
||||
|
||||
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoBoard board, String launchMode,
|
||||
ArduinoBuildConfiguration(IBuildConfiguration config, String name, String launchMode, ArduinoRemoteConnection target,
|
||||
IToolChain toolChain) throws CoreException {
|
||||
super(config, name, toolChain);
|
||||
this.board = board;
|
||||
this.target = target;
|
||||
this.launchMode = launchMode;
|
||||
|
||||
// Store the board identifer
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
|
||||
Preferences settings = getSettings();
|
||||
settings.put(PACKAGE_NAME, pkg.getName());
|
||||
settings.put(PLATFORM_NAME, platform.getName());
|
||||
settings.put(BOARD_NAME, board.getName());
|
||||
|
||||
try {
|
||||
settings.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
|
||||
}
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
remoteManager.addRemoteConnectionChangeListener(this);
|
||||
}
|
||||
|
||||
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoRemoteConnection target,
|
||||
String launchMode, IToolChain toolChain) throws CoreException {
|
||||
this(config, name, target.getBoard(), launchMode, toolChain);
|
||||
|
||||
Preferences settings = getSettings();
|
||||
|
||||
// Store the menu settings
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (String id : menus.getChildren().keySet()) {
|
||||
String value = target.getMenuValue(id);
|
||||
if (value != null) {
|
||||
settings.put(MENU_QUALIFIER + id, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public synchronized void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||
if (event.getConnection().equals(target.getRemoteConnection())) {
|
||||
properties = null;
|
||||
}
|
||||
|
||||
String programmer = target.getProgrammer();
|
||||
if (programmer != null) {
|
||||
settings.put(PROGRAMMER, programmer);
|
||||
}
|
||||
|
||||
try {
|
||||
settings.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
static String generateName(ArduinoBoard board, String launchMode) {
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
return pkg.getName() + '.' + platform.getArchitecture() + '.' + board.getId() + '.' + launchMode;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -191,31 +133,21 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
|||
return launchMode;
|
||||
}
|
||||
|
||||
public boolean matches(ArduinoRemoteConnection target) throws CoreException {
|
||||
ArduinoBoard otherBoard = target.getBoard();
|
||||
if (!getBoard().equals(otherBoard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Preferences settings = getSettings();
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (String id : menus.getChildren().keySet()) {
|
||||
if (!settings.get(MENU_QUALIFIER + id, "").equals(target.getMenuValue(id))) { //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
public ArduinoRemoteConnection getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public ArduinoBoard getBoard() throws CoreException {
|
||||
return board;
|
||||
if (target != null) {
|
||||
return target.getBoard();
|
||||
} else {
|
||||
return defaultBoard;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized Properties getProperties() throws CoreException {
|
||||
if (properties == null) {
|
||||
ArduinoBoard board = getBoard();
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
|
||||
// IDE generated properties
|
||||
|
@ -265,24 +197,22 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
|||
}
|
||||
|
||||
// Board
|
||||
ArduinoBoard board = getBoard();
|
||||
properties.putAll(board.getBoardProperties());
|
||||
|
||||
// Menus
|
||||
Preferences settings = getSettings();
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (Entry<String, HierarchicalProperties> menuEntry : menus.getChildren().entrySet()) {
|
||||
String key = menuEntry.getKey();
|
||||
String defaultValue;
|
||||
Iterator<HierarchicalProperties> i = menuEntry.getValue().getChildren().values().iterator();
|
||||
if (i.hasNext()) {
|
||||
defaultValue = i.next().getValue();
|
||||
} else {
|
||||
defaultValue = ""; //$NON-NLS-1$
|
||||
String value = target.getMenuValue(key);
|
||||
if (value == null || value.isEmpty()) {
|
||||
Iterator<HierarchicalProperties> i = menuEntry.getValue().getChildren().values().iterator();
|
||||
if (i.hasNext()) {
|
||||
HierarchicalProperties first = i.next();
|
||||
value = first.getValue();
|
||||
}
|
||||
}
|
||||
String value = settings.get(MENU_QUALIFIER + key, defaultValue);
|
||||
if (!value.isEmpty()) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
properties.putAll(board.getMenuProperties(key, value));
|
||||
}
|
||||
}
|
||||
|
@ -597,9 +527,9 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
|||
command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
|
||||
} else {
|
||||
// use the bootloader
|
||||
String programmer = getSettings().get(PROGRAMMER, null);
|
||||
String programmer = target.getProgrammer();
|
||||
if (programmer != null) {
|
||||
HierarchicalProperties programmers = board.getPlatform().getProgrammers();
|
||||
HierarchicalProperties programmers = getBoard().getPlatform().getProgrammers();
|
||||
if (programmers != null) {
|
||||
HierarchicalProperties programmerProps = programmers.getChild(programmer);
|
||||
if (programmerProps != null) {
|
||||
|
@ -607,7 +537,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO preference
|
||||
properties.put("program.verbose", properties.getProperty("program.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
properties.put("program.verify", properties.getProperty("program.params.verify", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
|
|
@ -23,6 +23,9 @@ import org.eclipse.core.resources.IBuildConfiguration;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
|
||||
public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationProvider {
|
||||
|
||||
|
@ -49,52 +52,54 @@ public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationPr
|
|||
}
|
||||
}
|
||||
if (board != null) {
|
||||
// Create the toolChain
|
||||
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
|
||||
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
|
||||
IToolChain toolChain = new ArduinoToolChain(provider, config);
|
||||
toolChainManager.addToolChain(toolChain);
|
||||
|
||||
return new ArduinoBuildConfiguration(config, name, board, "run", toolChain); //$NON-NLS-1$
|
||||
IToolChain toolChain = createToolChain(config);
|
||||
return new ArduinoBuildConfiguration(config, name, "run", board, toolChain); //$NON-NLS-1$
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return new ArduinoBuildConfiguration(config, name);
|
||||
}
|
||||
}
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
IRemoteConnection connection = connectionType.getConnection(name);
|
||||
if (connection == null) {
|
||||
throw Activator.coreException(String.format("Unknown connection: %s", name), null);
|
||||
}
|
||||
|
||||
public ArduinoBuildConfiguration getConfiguration(IProject project, ArduinoRemoteConnection target,
|
||||
String launchMode,
|
||||
IProgressMonitor monitor) throws CoreException {
|
||||
ArduinoBoard board = target.getBoard();
|
||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||
ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
|
||||
if (cconfig != null) {
|
||||
ArduinoBuildConfiguration arduinoConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class);
|
||||
if (arduinoConfig != null && arduinoConfig.getLaunchMode().equals(launchMode)
|
||||
&& arduinoConfig.getBoard().equals(board) && arduinoConfig.matches(target)) {
|
||||
return arduinoConfig;
|
||||
}
|
||||
ArduinoRemoteConnection target = connection.getService(ArduinoRemoteConnection.class);
|
||||
if (target != null) {
|
||||
IToolChain toolChain = createToolChain(config);
|
||||
return new ArduinoBuildConfiguration(config, name, "run", target, toolChain); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArduinoBuildConfiguration createConfiguration(IProject project, ArduinoRemoteConnection target,
|
||||
String launchMode,
|
||||
IProgressMonitor monitor) throws CoreException {
|
||||
ArduinoBoard board = target.getBoard();
|
||||
String configName = ArduinoBuildConfiguration.generateName(board, launchMode);
|
||||
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName,
|
||||
monitor);
|
||||
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
|
||||
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
|
||||
IToolChain toolChain = new ArduinoToolChain(provider, config);
|
||||
toolChainManager.addToolChain(toolChain);
|
||||
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, target, launchMode,
|
||||
public ArduinoBuildConfiguration getConfiguration(IProject project, ArduinoRemoteConnection target,
|
||||
String launchMode, IProgressMonitor monitor) throws CoreException {
|
||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||
ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
|
||||
if (cconfig != null) {
|
||||
ArduinoBuildConfiguration arduinoConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class);
|
||||
if (arduinoConfig != null && target.equals(arduinoConfig.getTarget())
|
||||
&& arduinoConfig.getLaunchMode().equals(launchMode)) {
|
||||
return arduinoConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new one
|
||||
String configName = target.getRemoteConnection().getName();
|
||||
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, monitor);
|
||||
IToolChain toolChain = createToolChain(config);
|
||||
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, "run", target, //$NON-NLS-1$
|
||||
toolChain);
|
||||
configManager.addBuildConfiguration(config, arduinoConfig);
|
||||
return arduinoConfig;
|
||||
}
|
||||
|
||||
private IToolChain createToolChain(IBuildConfiguration config) throws CoreException {
|
||||
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
|
||||
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
|
||||
IToolChain toolChain = new ArduinoToolChain(provider, config);
|
||||
toolChainManager.addToolChain(toolChain);
|
||||
return toolChain;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,10 +115,6 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationTarge
|
|||
IProgressMonitor monitor) throws CoreException {
|
||||
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
|
||||
.getProvider(ArduinoBuildConfigurationProvider.ID);
|
||||
ArduinoBuildConfiguration config = provider.getConfiguration(project, arduinoTarget, launchMode, monitor);
|
||||
if (config == null) {
|
||||
config = provider.createConfiguration(project, arduinoTarget, launchMode, monitor);
|
||||
}
|
||||
return config;
|
||||
return provider.getConfiguration(project, arduinoTarget, launchMode, monitor);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue