Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation cleanup and automatic library dependencies #2174

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
import processing.app.helpers.FileUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
import processing.app.packages.HeuristicResolver;
import processing.app.packages.Library;
import processing.app.packages.LibraryList;
import processing.app.packages.LibraryResolver;
import processing.app.tools.MenuScroller;
import processing.app.tools.ZipDeflater;
import processing.core.*;
Expand All @@ -67,6 +68,11 @@ public class Base {
/** Set true if this a proper release rather than a numbered revision. */
static public boolean RELEASE = false;

// These should remain lowercase, they are matched against lowercased strings
public static final String[] SOURCE_EXTENSIONS = {"s", "c", "cpp"};
public static final String[] HEADER_EXTENSIONS = {"h"};
public static final String[] SKETCH_EXTENSIONS = {"ino", "pde"};

static Map<Integer, String> platformNames = new HashMap<Integer, String>();
static {
platformNames.put(PConstants.WINDOWS, "windows");
Expand Down Expand Up @@ -105,7 +111,7 @@ public class Base {
static private LibraryList libraries;

// maps #included files to their library folder
static Map<String, Library> importToLibraryTable;
static private LibraryResolver libraryResolver;

// classpath for all known libraries for p5
// (both those in the p5/libs folder and those with lib subfolders
Expand Down Expand Up @@ -1341,27 +1347,8 @@ public void onBoardOrPortChange() {
showWarning(_("Error"), _("Error loading libraries"), e);
}

// Populate importToLibraryTable
importToLibraryTable = new HashMap<String, Library>();
for (Library lib : libraries) {
try {
String headers[] = headerListFromIncludePath(lib.getSrcFolder());
for (String header : headers) {
Library old = importToLibraryTable.get(header);
if (old != null) {
// If a library was already found with this header, keep
// it if the library's name matches the header name.
String name = header.substring(0, header.length() - 2);
if (old.getFolder().getPath().endsWith(name))
continue;
}
importToLibraryTable.put(header, lib);
}
} catch (IOException e) {
showWarning(_("Error"), I18n
.format("Unable to list header files in {0}", lib.getSrcFolder()), e);
}
}
// Create library resolver
libraryResolver = new HeuristicResolver(libraries);

// Update editors status bar
for (Editor editor : editors)
Expand Down Expand Up @@ -1763,19 +1750,6 @@ public void actionPerformed(ActionEvent event) {
}
}

/**
* Given a folder, return a list of the header files in that folder (but not
* the header files in its sub-folders, as those should be included from
* within the header files at the top-level).
*/
static public String[] headerListFromIncludePath(File path) throws IOException {
String[] list = path.list(new OnlyFilesWithExtension(".h"));
if (list == null) {
throw new IOException();
}
return list;
}

protected void loadHardware(File folder) {
if (!folder.isDirectory()) return;

Expand Down Expand Up @@ -3009,4 +2983,8 @@ public void handleAddLibrary() {
public static DiscoveryManager getDiscoveryManager() {
return discoveryManager;
}

public static LibraryResolver getLibraryResolver() {
return libraryResolver;
}
}
2 changes: 1 addition & 1 deletion app/src/processing/app/EditorHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void paintComponent(Graphics screen) {
for (int i = 0; i < sketch.getCodeCount(); i++) {
SketchCode code = sketch.getCode(i);

String codeName = sketch.hideExtension(code.getExtension()) ?
String codeName = code.isExtension(sketch.getHiddenExtensions()) ?
code.getPrettyName() : code.getFileName();

// if modified, add the li'l glyph next to the name
Expand Down
Loading