1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +02:00

Support for platform libraries for Arduino.

Went to use the ESP8266 wifi library and couldn't since it's shipped
with the esp8266 platform.

Also fixed up a platform sdk problem that prevented the project from
building even after I added the library.

Change-Id: If99596f1f531f62f7553b238aa7cf0d6c426aca8
This commit is contained in:
Doug Schaefer 2015-09-06 02:08:34 -04:00
parent a887378f70
commit eca5073324
6 changed files with 119 additions and 44 deletions

View file

@ -1,15 +1,18 @@
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration; import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -31,6 +34,29 @@ public class ArduinoLibrary {
private int size; private int size;
private String checksum; private String checksum;
private Path installPath;
public ArduinoLibrary() {
}
public ArduinoLibrary(Path propertiesFile) throws IOException {
installPath = propertiesFile.getParent();
Properties props = new Properties();
try (FileReader reader = new FileReader(propertiesFile.toFile())) {
props.load(reader);
}
name = props.getProperty("name"); //$NON-NLS-1$
version = props.getProperty("version"); //$NON-NLS-1$
author = props.getProperty("author"); //$NON-NLS-1$
maintainer = props.getProperty("maintainer"); //$NON-NLS-1$
sentence = props.getProperty("sentence"); //$NON-NLS-1$
paragraph = props.getProperty("paragraph"); //$NON-NLS-1$
category = props.getProperty("category"); //$NON-NLS-1$
architectures = Arrays.asList(props.getProperty("architectures").split(",")); //$NON-NLS-1$ //$NON-NLS-2$
}
public String getName() { public String getName() {
return name; return name;
} }
@ -144,7 +170,8 @@ public class ArduinoLibrary {
} }
public Path getInstallPath() { public Path getInstallPath() {
return ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replace(' ', '_')) //$NON-NLS-1$ return installPath != null ? installPath
: ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replace(' ', '_')) //$NON-NLS-1$
.resolve(version); .resolve(version);
} }
@ -171,31 +198,31 @@ public class ArduinoLibrary {
} }
} }
private void getSources(IProject project, Collection<Path> sources, Path dir, boolean recurse) { private void getSources(Collection<String> sources, Path dir, boolean recurse) {
for (File file : dir.toFile().listFiles()) { for (File file : dir.toFile().listFiles()) {
if (file.isDirectory()) { if (file.isDirectory()) {
if (recurse) { if (recurse) {
getSources(project, sources, file.toPath(), recurse); getSources(sources, file.toPath(), recurse);
} }
} else { } else {
if (ArduinoBuildConfiguration.isSource(file.getName())) { if (ArduinoBuildConfiguration.isSource(file.getName())) {
sources.add(file.toPath()); sources.add(file.getAbsolutePath());
} }
} }
} }
} }
public Collection<Path> getSources(IProject project) { public Collection<String> getSources() {
List<Path> sources = new ArrayList<>(); List<String> sources = new ArrayList<>();
Path installPath = getInstallPath(); Path installPath = getInstallPath();
Path srcPath = installPath.resolve("src"); //$NON-NLS-1$ Path srcPath = installPath.resolve("src"); //$NON-NLS-1$
if (srcPath.toFile().isDirectory()) { if (srcPath.toFile().isDirectory()) {
getSources(project, sources, srcPath, true); getSources(sources, srcPath, true);
} else { } else {
getSources(project, sources, installPath, false); getSources(sources, installPath, false);
Path utilityPath = installPath.resolve("utility"); //$NON-NLS-1$ Path utilityPath = installPath.resolve("utility"); //$NON-NLS-1$
if (utilityPath.toFile().isDirectory()) { if (utilityPath.toFile().isDirectory()) {
getSources(project, sources, utilityPath, false); getSources(sources, utilityPath, false);
} }
} }
return sources; return sources;

View file

@ -107,7 +107,7 @@ public class ArduinoManager {
} }
} }
public synchronized List<PackageIndex> getPackageIndices() throws CoreException { public synchronized List<PackageIndex> getPackageIndices() {
if (packageIndices == null) { if (packageIndices == null) {
String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$ String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$
packageIndices = new ArrayList<>(boardUrls.length); packageIndices = new ArrayList<>(boardUrls.length);
@ -118,7 +118,7 @@ public class ArduinoManager {
return packageIndices; return packageIndices;
} }
private void loadLibraryIndex(boolean download) { public void loadLibraryIndex(boolean download) {
try { try {
URL librariesUrl = new URL(LIBRARIES_URL); URL librariesUrl = new URL(LIBRARIES_URL);
Path librariesPath = ArduinoPreferences.getArduinoHome() Path librariesPath = ArduinoPreferences.getArduinoHome()
@ -130,6 +130,7 @@ public class ArduinoManager {
if (librariesFile.exists()) { if (librariesFile.exists()) {
try (Reader reader = new FileReader(librariesFile)) { try (Reader reader = new FileReader(librariesFile)) {
libraryIndex = new Gson().fromJson(reader, LibraryIndex.class); libraryIndex = new Gson().fromJson(reader, LibraryIndex.class);
libraryIndex.resolve();
} }
} }
} catch (IOException e) { } catch (IOException e) {

View file

@ -8,6 +8,7 @@
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -17,6 +18,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -25,6 +27,7 @@ import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
@ -193,6 +196,29 @@ public class ArduinoPlatform {
installPath.resolve("variants/{build.variant}")); //$NON-NLS-1$ installPath.resolve("variants/{build.variant}")); //$NON-NLS-1$
} }
private void getSources(Collection<String> sources, Path dir, boolean recurse) {
for (File file : dir.toFile().listFiles()) {
if (file.isDirectory()) {
if (recurse) {
getSources(sources, file.toPath(), recurse);
}
} else {
if (ArduinoBuildConfiguration.isSource(file.getName())) {
sources.add(file.getAbsolutePath());
}
}
}
}
public Collection<String> getSources(String core) {
List<String> sources = new ArrayList<>();
Path srcPath = getInstallPath().resolve("cores").resolve(core); //$NON-NLS-1$
if (srcPath.toFile().isDirectory()) {
getSources(sources, srcPath, true);
}
return sources;
}
public IStatus install(IProgressMonitor monitor) { public IStatus install(IProgressMonitor monitor) {
// Check if we're installed already // Check if we're installed already
if (isInstalled()) { if (isInstalled()) {
@ -234,6 +260,9 @@ public class ArduinoPlatform {
} }
} }
// Reload the library index to pick up platform libraries
ArduinoManager.instance.loadLibraryIndex(false);
return mstatus != null ? mstatus : Status.OK_STATUS; return mstatus != null ? mstatus : Status.OK_STATUS;
} }

View file

@ -1,5 +1,8 @@
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -18,7 +21,26 @@ public class LibraryIndex {
// library name to latest version of library // library name to latest version of library
private Map<String, ArduinoLibrary> latestLibs = new HashMap<>(); private Map<String, ArduinoLibrary> latestLibs = new HashMap<>();
public void resolve() { public void resolve() throws IOException {
// Add in platform libraries
for (PackageIndex index : ArduinoManager.instance.getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) {
for (ArduinoPlatform platform : pkg.getPlatforms()) {
if (platform.isInstalled()) {
File[] libraryDirs = platform.getInstallPath().resolve("libraries").toFile().listFiles(); //$NON-NLS-1$
if (libraryDirs != null) {
for (File libraryDir : libraryDirs) {
Path propsPath = libraryDir.toPath().resolve("library.properties"); //$NON-NLS-1$
if (propsPath.toFile().exists()) {
libraries.add(new ArduinoLibrary(propsPath));
}
}
}
}
}
}
}
for (ArduinoLibrary library : libraries) { for (ArduinoLibrary library : libraries) {
String name = library.getName(); String name = library.getName();

View file

@ -2,7 +2,6 @@ package org.eclipse.cdt.arduino.core.internal.build;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
@ -332,9 +331,7 @@ public class ArduinoBuildConfiguration {
// The list of library sources // The list of library sources
List<String> librarySources = new ArrayList<>(); List<String> librarySources = new ArrayList<>();
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) { for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
for (Path path : lib.getSources(project)) { librarySources.addAll(lib.getSources());
librarySources.add(pathString(path));
}
} }
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$ buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
buildModel.put("libraries_path", pathString(ArduinoPreferences.getArduinoHome().resolve("libraries"))); //$NON-NLS-1$ //$NON-NLS-2$ buildModel.put("libraries_path", pathString(ArduinoPreferences.getArduinoHome().resolve("libraries"))); //$NON-NLS-1$ //$NON-NLS-2$
@ -363,20 +360,7 @@ public class ArduinoBuildConfiguration {
Path platformPath = platform.getInstallPath(); Path platformPath = platform.getInstallPath();
buildModel.put("platform_path", pathString(platformPath)); //$NON-NLS-1$ buildModel.put("platform_path", pathString(platformPath)); //$NON-NLS-1$
buildModel.put("platform_srcs", platform.getSources(properties.getProperty("build.core"))); //$NON-NLS-1$ //$NON-NLS-2$
Path corePath = platformPath.resolve("cores").resolve((String) properties.get("build.core")); //$NON-NLS-1$ //$NON-NLS-2$
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return isSource(name);
}
});
String[] platformSource = new String[platformFiles.length];
for (int i = 0; i < platformSource.length; ++i) {
platformSource[i] = pathString(platformFiles[i].toPath());
}
buildModel.put("platform_srcs", platformSource); //$NON-NLS-1$
properties.put("object_file", "$@"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("object_file", "$@"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("source_file", "$<"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("source_file", "$<"); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -10,7 +10,7 @@ PROJECT_OBJS = \
<#list project_srcs as file> <#list project_srcs as file>
<#assign cpp = file?matches("(.*)\\.cpp")> <#assign cpp = file?matches("(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/project/${cpp?groups[1]}.o \ ${build_path}/project/${cpp?groups[1]}.cpp.o \
</#if> </#if>
</#list> </#list>
@ -18,11 +18,11 @@ PLATFORM_OBJS = \
<#list platform_srcs as file> <#list platform_srcs as file>
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/platform/${cpp?groups[1]}.o \ ${build_path}/platform/${cpp?groups[1]}.cpp.o \
</#if> </#if>
<#assign c = file?matches("${platform_path}/(.*)\\.c")> <#assign c = file?matches("${platform_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/platform/${c?groups[1]}.o \ ${build_path}/platform/${c?groups[1]}.c.o \
</#if> </#if>
<#assign S = file?matches("${platform_path}/(.*)\\.S")> <#assign S = file?matches("${platform_path}/(.*)\\.S")>
<#if S> <#if S>
@ -33,12 +33,18 @@ PLATFORM_OBJS = \
LIBRARIES_OBJS = \ LIBRARIES_OBJS = \
<#list libraries_srcs as file> <#list libraries_srcs as file>
<#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")> <#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")>
<#if !cpp>
<#assign cpp = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.cpp")>
</#if>
<#if cpp> <#if cpp>
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.o \ ${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o \
</#if> </#if>
<#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")> <#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")>
<#if !c>
<#assign c = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.c")>
</#if>
<#if c> <#if c>
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.o \ ${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.o \
</#if> </#if>
</#list> </#list>
@ -64,7 +70,7 @@ size:
<#list project_srcs as file> <#list project_srcs as file>
<#assign cpp = file?matches("(.*)\\.cpp")> <#assign cpp = file?matches("(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/project/${cpp?groups[1]}.o: ../${file} ${build_path}/project/${cpp?groups[1]}.cpp.o: ../${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern}
@ -74,7 +80,7 @@ ${build_path}/project/${cpp?groups[1]}.o: ../${file}
<#list platform_srcs as file> <#list platform_srcs as file>
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/platform/${cpp?groups[1]}.o: ${file} ${build_path}/platform/${cpp?groups[1]}.cpp.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern}
${recipe_ar_pattern} ${recipe_ar_pattern}
@ -82,7 +88,7 @@ ${build_path}/platform/${cpp?groups[1]}.o: ${file}
</#if> </#if>
<#assign c = file?matches("${platform_path}/(.*)\\.c")> <#assign c = file?matches("${platform_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/platform/${c?groups[1]}.o: ${file} ${build_path}/platform/${c?groups[1]}.c.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_c_o_pattern} ${recipe_c_o_pattern}
${recipe_ar_pattern} ${recipe_ar_pattern}
@ -100,15 +106,21 @@ ${build_path}/platform/${S?groups[1]}.S.o: ${file}
<#list libraries_srcs as file> <#list libraries_srcs as file>
<#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")> <#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")>
<#if !cpp>
<#assign cpp = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.cpp")>
</#if>
<#if cpp> <#if cpp>
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.o: ${file} ${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern}
</#if> </#if>
<#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")> <#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")>
<#if !c>
<#assign c = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.c")>
</#if>
<#if c> <#if c>
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.o: ${file} ${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_c_o_pattern} ${recipe_c_o_pattern}