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

Bug 533588 - respect OS-specific override in platform.txt

HierarchicalProperties already allow for OS-specific overrides, so

1 - convert platformProperties to HierarchicalProperties
2 - change HierarchicalProperties to allow overwriting of non-empty
properties. Before it would only use the platform child if the value for
the entry itself was null. With this change, if a platform child exists
its value is used if
- it contains a property or
- has an empty property and no further children. In this case the value
was specifically overridden with null

This change also allows proper parsing of esp32 platform.txt

Change-Id: Ie13a1bee57c216f6ab37cfc0208ef7711dfc62e8

Change-Id: Ie13a1bee57c216f6ab37cfc0208ef7711dfc62e8
Signed-off-by: Lutz Hamann <lhamann@planettime.de>
This commit is contained in:
Lutz Hamann 2018-12-03 15:37:47 +01:00 committed by Doug Schaefer
parent 4c605d68c5
commit 12207e79db
3 changed files with 39 additions and 29 deletions

View file

@ -22,11 +22,24 @@ public class HierarchicalProperties {
private String value;
private Map<String, HierarchicalProperties> children;
private String platName;
public HierarchicalProperties() {
switch (Platform.getOS()) {
case Platform.OS_WIN32:
platName = "windows"; //$NON-NLS-1$
break;
case Platform.OS_MACOSX:
platName = "macosx"; //$NON-NLS-1$
break;
case Platform.OS_LINUX:
platName = "linux"; //$NON-NLS-1$
break;
}
}
public HierarchicalProperties(LinkedProperties properties) {
this();
for (Object keyObj : properties.orderedKeys()) {
String key = (String) keyObj;
String value = (String) properties.get(key);
@ -81,25 +94,15 @@ public class HierarchicalProperties {
}
public String getValue() {
if (value == null) {
// Try a platform child
String platName = null;
switch (Platform.getOS()) {
case Platform.OS_WIN32:
platName = "windows"; //$NON-NLS-1$
break;
case Platform.OS_MACOSX:
platName = "macosx"; //$NON-NLS-1$
break;
case Platform.OS_LINUX:
platName = "linux"; //$NON-NLS-1$
break;
}
if (platName != null) {
HierarchicalProperties platChild = getChild(platName);
if (platChild != null) {
return platChild.getValue();
}
// Try a platform child
if (platName != null && hasChild(platName)) {
HierarchicalProperties child = getChild(platName);
// return the child's value if
// - it has a property
// - it has no more children. In that case the value could even be null (specifically overridden)
if ((null != child.getValue()) || (!child.hasChildren())) {
return child.getValue();
}
}
return value;
@ -113,6 +116,14 @@ public class HierarchicalProperties {
return children;
}
private boolean hasChildren() {
return (children != null && children.size() > 0);
}
private boolean hasChild(String key) {
return (children != null && children.containsKey(key));
}
public HierarchicalProperties getChild(String key) {
return children != null ? children.get(key) : null;
}
@ -180,5 +191,4 @@ public class HierarchicalProperties {
}
}
}
}

View file

@ -58,7 +58,7 @@ public class ArduinoPlatform {
private Path installPath;
private ArduinoPackage pkg;
private HierarchicalProperties boardsProperties;
private LinkedProperties platformProperties;
private HierarchicalProperties platformProperties;
private HierarchicalProperties programmerProperties;
private Map<String, String> menus = new HashMap<>();
private Map<String, ArduinoLibrary> libraries;
@ -109,7 +109,7 @@ public class ArduinoPlatform {
return size;
}
public void setPlatformProperties(LinkedProperties platformProperties) {
public void setPlatformProperties(HierarchicalProperties platformProperties) {
this.platformProperties = platformProperties;
}
@ -187,9 +187,9 @@ public class ArduinoPlatform {
return null;
}
public LinkedProperties getPlatformProperties() throws CoreException {
public HierarchicalProperties getPlatformProperties() throws CoreException {
if (platformProperties == null) {
platformProperties = new LinkedProperties();
LinkedProperties rawPlatformProps = new LinkedProperties();
try (BufferedReader reader = new BufferedReader(
new FileReader(getInstallPath().resolve("platform.txt").toFile()))) { //$NON-NLS-1$
// There are regex's here and need to preserve the \'s
@ -199,11 +199,12 @@ public class ArduinoPlatform {
buffer.append('\n');
}
try (Reader reader1 = new StringReader(buffer.toString())) {
platformProperties.load(reader1);
rawPlatformProps.load(reader1);
}
} catch (IOException e) {
throw Activator.coreException(e);
}
platformProperties = new HierarchicalProperties(rawPlatformProps);
}
return platformProperties;
}

View file

@ -187,13 +187,13 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
ArduinoPlatform superPlatform = manager.getInstalledPlatform(segments[0],
platform.getArchitecture());
if (superPlatform != null) {
boardProperties.putAll(superPlatform.getPlatformProperties());
boardProperties.putAll(superPlatform.getPlatformProperties().flatten());
}
}
}
// Platform
boardProperties.putAll(platform.getPlatformProperties());
boardProperties.putAll(platform.getPlatformProperties().flatten());
// Tools
for (ToolDependency toolDep : platform.getToolsDependencies()) {
@ -520,8 +520,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
properties.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// properties for the tool flattened
HierarchicalProperties toolsProps = new HierarchicalProperties(platform.getPlatformProperties())
.getChild("tools"); //$NON-NLS-1$
HierarchicalProperties toolsProps = platform.getPlatformProperties().getChild("tools"); //$NON-NLS-1$
if (toolsProps != null) {
HierarchicalProperties toolProps = toolsProps.getChild(toolName);
if (toolProps != null) {