mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 08:15:48 +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:
parent
a887378f70
commit
eca5073324
6 changed files with 119 additions and 44 deletions
|
@ -1,15 +1,18 @@
|
|||
package org.eclipse.cdt.arduino.core.internal.board;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
|
||||
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.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
@ -31,6 +34,29 @@ public class ArduinoLibrary {
|
|||
private int size;
|
||||
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() {
|
||||
return name;
|
||||
}
|
||||
|
@ -144,8 +170,9 @@ public class ArduinoLibrary {
|
|||
}
|
||||
|
||||
public Path getInstallPath() {
|
||||
return ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replace(' ', '_')) //$NON-NLS-1$
|
||||
.resolve(version);
|
||||
return installPath != null ? installPath
|
||||
: ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replace(' ', '_')) //$NON-NLS-1$
|
||||
.resolve(version);
|
||||
}
|
||||
|
||||
public boolean isInstalled() {
|
||||
|
@ -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()) {
|
||||
if (file.isDirectory()) {
|
||||
if (recurse) {
|
||||
getSources(project, sources, file.toPath(), recurse);
|
||||
getSources(sources, file.toPath(), recurse);
|
||||
}
|
||||
} else {
|
||||
if (ArduinoBuildConfiguration.isSource(file.getName())) {
|
||||
sources.add(file.toPath());
|
||||
sources.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<Path> getSources(IProject project) {
|
||||
List<Path> sources = new ArrayList<>();
|
||||
public Collection<String> getSources() {
|
||||
List<String> sources = new ArrayList<>();
|
||||
Path installPath = getInstallPath();
|
||||
Path srcPath = installPath.resolve("src"); //$NON-NLS-1$
|
||||
if (srcPath.toFile().isDirectory()) {
|
||||
getSources(project, sources, srcPath, true);
|
||||
getSources(sources, srcPath, true);
|
||||
} else {
|
||||
getSources(project, sources, installPath, false);
|
||||
getSources(sources, installPath, false);
|
||||
Path utilityPath = installPath.resolve("utility"); //$NON-NLS-1$
|
||||
if (utilityPath.toFile().isDirectory()) {
|
||||
getSources(project, sources, utilityPath, false);
|
||||
getSources(sources, utilityPath, false);
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
|
|
|
@ -107,7 +107,7 @@ public class ArduinoManager {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized List<PackageIndex> getPackageIndices() throws CoreException {
|
||||
public synchronized List<PackageIndex> getPackageIndices() {
|
||||
if (packageIndices == null) {
|
||||
String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$
|
||||
packageIndices = new ArrayList<>(boardUrls.length);
|
||||
|
@ -118,7 +118,7 @@ public class ArduinoManager {
|
|||
return packageIndices;
|
||||
}
|
||||
|
||||
private void loadLibraryIndex(boolean download) {
|
||||
public void loadLibraryIndex(boolean download) {
|
||||
try {
|
||||
URL librariesUrl = new URL(LIBRARIES_URL);
|
||||
Path librariesPath = ArduinoPreferences.getArduinoHome()
|
||||
|
@ -130,6 +130,7 @@ public class ArduinoManager {
|
|||
if (librariesFile.exists()) {
|
||||
try (Reader reader = new FileReader(librariesFile)) {
|
||||
libraryIndex = new Gson().fromJson(reader, LibraryIndex.class);
|
||||
libraryIndex.resolve();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package org.eclipse.cdt.arduino.core.internal.board;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -17,6 +18,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.ArduinoPreferences;
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -193,6 +196,29 @@ public class ArduinoPlatform {
|
|||
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) {
|
||||
// Check if we're installed already
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -18,7 +21,26 @@ public class LibraryIndex {
|
|||
// library name to latest version of library
|
||||
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) {
|
||||
String name = library.getName();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.eclipse.cdt.arduino.core.internal.build;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
|
@ -332,9 +331,7 @@ public class ArduinoBuildConfiguration {
|
|||
// The list of library sources
|
||||
List<String> librarySources = new ArrayList<>();
|
||||
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
|
||||
for (Path path : lib.getSources(project)) {
|
||||
librarySources.add(pathString(path));
|
||||
}
|
||||
librarySources.addAll(lib.getSources());
|
||||
}
|
||||
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
|
||||
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();
|
||||
buildModel.put("platform_path", pathString(platformPath)); //$NON-NLS-1$
|
||||
|
||||
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$
|
||||
buildModel.put("platform_srcs", platform.getSources(properties.getProperty("build.core"))); //$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$
|
||||
|
|
|
@ -10,7 +10,7 @@ PROJECT_OBJS = \
|
|||
<#list project_srcs as file>
|
||||
<#assign cpp = file?matches("(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
${build_path}/project/${cpp?groups[1]}.o \
|
||||
${build_path}/project/${cpp?groups[1]}.cpp.o \
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
|
@ -18,11 +18,11 @@ PLATFORM_OBJS = \
|
|||
<#list platform_srcs as file>
|
||||
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
${build_path}/platform/${cpp?groups[1]}.o \
|
||||
${build_path}/platform/${cpp?groups[1]}.cpp.o \
|
||||
</#if>
|
||||
<#assign c = file?matches("${platform_path}/(.*)\\.c")>
|
||||
<#if c>
|
||||
${build_path}/platform/${c?groups[1]}.o \
|
||||
${build_path}/platform/${c?groups[1]}.c.o \
|
||||
</#if>
|
||||
<#assign S = file?matches("${platform_path}/(.*)\\.S")>
|
||||
<#if S>
|
||||
|
@ -33,14 +33,20 @@ PLATFORM_OBJS = \
|
|||
LIBRARIES_OBJS = \
|
||||
<#list libraries_srcs as file>
|
||||
<#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")>
|
||||
<#if !cpp>
|
||||
<#assign cpp = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.cpp")>
|
||||
</#if>
|
||||
<#if cpp>
|
||||
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.o \
|
||||
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o \
|
||||
</#if>
|
||||
<#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")>
|
||||
<#if c>
|
||||
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.o \
|
||||
<#if !c>
|
||||
<#assign c = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.c")>
|
||||
</#if>
|
||||
</#list>
|
||||
<#if c>
|
||||
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.o \
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
all: ${build_path}/${project_name}.hex ${build_path}/${project_name}.eep
|
||||
|
||||
|
@ -64,7 +70,7 @@ size:
|
|||
<#list project_srcs as file>
|
||||
<#assign cpp = file?matches("(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
${build_path}/project/${cpp?groups[1]}.o: ../${file}
|
||||
${build_path}/project/${cpp?groups[1]}.cpp.o: ../${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_cpp_o_pattern}
|
||||
|
||||
|
@ -74,7 +80,7 @@ ${build_path}/project/${cpp?groups[1]}.o: ../${file}
|
|||
<#list platform_srcs as file>
|
||||
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
${build_path}/platform/${cpp?groups[1]}.o: ${file}
|
||||
${build_path}/platform/${cpp?groups[1]}.cpp.o: ${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_cpp_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
@ -82,7 +88,7 @@ ${build_path}/platform/${cpp?groups[1]}.o: ${file}
|
|||
</#if>
|
||||
<#assign c = file?matches("${platform_path}/(.*)\\.c")>
|
||||
<#if c>
|
||||
${build_path}/platform/${c?groups[1]}.o: ${file}
|
||||
${build_path}/platform/${c?groups[1]}.c.o: ${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_c_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
@ -100,15 +106,21 @@ ${build_path}/platform/${S?groups[1]}.S.o: ${file}
|
|||
|
||||
<#list libraries_srcs as file>
|
||||
<#assign cpp = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.cpp")>
|
||||
<#if !cpp>
|
||||
<#assign cpp = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.cpp")>
|
||||
</#if>
|
||||
<#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 $@))
|
||||
${recipe_cpp_o_pattern}
|
||||
|
||||
</#if>
|
||||
<#assign c = file?matches("${libraries_path}/(.*?)/.*?/(.*)\\.c")>
|
||||
<#if !c>
|
||||
<#assign c = file?matches("${platform_path}/libraries/(.*?)/.*?/(.*)\\.c")>
|
||||
</#if>
|
||||
<#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 $@))
|
||||
${recipe_c_o_pattern}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue