@@ -45,7 +45,7 @@ public class BaseNoGui {
45
45
static private File toolsFolder ;
46
46
47
47
// maps #included files to their library folder
48
- public static Map <String , UserLibrary > importToLibraryTable ;
48
+ public static Map <String , LibraryList > importToLibraryTable ;
49
49
50
50
// maps library name to their library folder
51
51
static private LibraryList libraries ;
@@ -787,14 +787,24 @@ static private void createToolPreferences(ContributionsIndexer indexer) {
787
787
}
788
788
789
789
static public void populateImportToLibraryTable () {
790
- // Populate importToLibraryTable
791
- importToLibraryTable = new HashMap <String , UserLibrary >();
790
+ // Populate importToLibraryTable. Each header filename maps to
791
+ // a list of libraries. Compiler.java will use only the first
792
+ // library on each list. The others are used only to advise
793
+ // user of ambiguously matched and duplicate libraries.
794
+ importToLibraryTable = new HashMap <String , LibraryList >();
792
795
for (UserLibrary lib : librariesIndexer .getInstalledLibraries ()) {
793
796
try {
794
797
String headers [] = headerListFromIncludePath (lib .getSrcFolder ());
795
798
for (String header : headers ) {
796
- UserLibrary old = importToLibraryTable .get (header );
797
- if (old != null ) {
799
+ LibraryList list = importToLibraryTable .get (header );
800
+ if (list == null ) {
801
+ // This is the first library found with this header
802
+ list = new LibraryList ();
803
+ list .addFirst (lib );
804
+ importToLibraryTable .put (header , list );
805
+ } else {
806
+ UserLibrary old = list .peekFirst ();
807
+ boolean useThisLib = true ;
798
808
// This is the case where 2 libraries have a .h header
799
809
// with the same name. We must decide which library to
800
810
// use when a sketch has #include "name.h"
@@ -812,58 +822,81 @@ static public void populateImportToLibraryTable() {
812
822
String oldName = old .getInstalledFolder ().getName (); // just the library folder name
813
823
String libName = lib .getInstalledFolder ().getName (); // just the library folder name
814
824
//System.out.println("name conflict: " + name);
815
- //System.out.println(" old = " + oldName + " -> " + old.getFolder ().getPath());
816
- //System.out.println(" new = " + libName + " -> " + lib.getFolder ().getPath());
825
+ //System.out.println(" old = " + oldName + " -> " + old.getInstalledFolder ().getPath());
826
+ //System.out.println(" new = " + libName + " -> " + lib.getInstalledFolder ().getPath());
817
827
String name_lc = name .toLowerCase ();
818
828
String oldName_lc = oldName .toLowerCase ();
819
829
String libName_lc = libName .toLowerCase ();
820
830
// always favor a perfect name match
821
831
if (libName .equals (name )) {
822
832
} else if (oldName .equals (name )) {
823
- continue ;
833
+ useThisLib = false ;
824
834
// check for "-master" appended (zip file from github)
825
835
} else if (libName .equals (name +"-master" )) {
826
836
} else if (oldName .equals (name +"-master" )) {
827
- continue ;
837
+ useThisLib = false ;
828
838
// next, favor a match with other stuff appended
829
839
} else if (libName .startsWith (name )) {
830
840
} else if (oldName .startsWith (name )) {
831
- continue ;
841
+ useThisLib = false ;
832
842
// otherwise, favor a match with stuff prepended
833
843
} else if (libName .endsWith (name )) {
834
844
} else if (oldName .endsWith (name )) {
835
- continue ;
845
+ useThisLib = false ;
836
846
// as a last resort, match if stuff prepended and appended
837
847
} else if (libName .contains (name )) {
838
848
} else if (oldName .contains (name )) {
839
- continue ;
849
+ useThisLib = false ;
840
850
// repeat all the above tests, with case insensitive matching
841
851
} else if (libName_lc .equals (name_lc )) {
842
852
} else if (oldName_lc .equals (name_lc )) {
843
- continue ;
853
+ useThisLib = false ;
844
854
} else if (libName_lc .equals (name_lc +"-master" )) {
845
855
} else if (oldName_lc .equals (name_lc +"-master" )) {
846
- continue ;
856
+ useThisLib = false ;
847
857
} else if (libName_lc .startsWith (name_lc )) {
848
858
} else if (oldName_lc .startsWith (name_lc )) {
849
- continue ;
859
+ useThisLib = false ;
850
860
} else if (libName_lc .endsWith (name_lc )) {
851
861
} else if (oldName_lc .endsWith (name_lc )) {
852
- continue ;
862
+ useThisLib = false ;
853
863
} else if (libName_lc .contains (name_lc )) {
854
864
} else if (oldName_lc .contains (name_lc )) {
855
- continue ;
865
+ useThisLib = false ;
856
866
} else {
857
867
// none of these tests matched, so just default to "libName".
858
868
}
869
+ if (useThisLib ) {
870
+ list .addFirst (lib );
871
+ } else {
872
+ list .addLast (lib );
873
+ }
859
874
}
860
- importToLibraryTable .put (header , lib );
861
875
}
862
876
} catch (IOException e ) {
863
877
showWarning (_ ("Error" ), I18n
864
878
.format ("Unable to list header files in {0}" , lib .getSrcFolder ()), e );
865
879
}
866
880
}
881
+ // repeat for ALL libraries, to pick up duplicates not visible normally.
882
+ // any new libraries found here are NEVER used, but they are added to the
883
+ // end of already-found headers, to allow Compiler to report them if
884
+ // the sketch tries to use them.
885
+ for (UserLibrary lib : librariesIndexer .getInstalledLibrariesWithDuplicates ()) {
886
+ try {
887
+ String headers [] = headerListFromIncludePath (lib .getSrcFolder ());
888
+ for (String header : headers ) {
889
+ LibraryList list = importToLibraryTable .get (header );
890
+ if (list != null ) {
891
+ if (!(list .hasLibrary (lib ))) {
892
+ list .addLast (lib );
893
+ //System.out.println(" duplicate lib: " + lib.getInstalledFolder().getPath());
894
+ }
895
+ }
896
+ }
897
+ } catch (IOException e ) {
898
+ }
899
+ }
867
900
}
868
901
869
902
static public void initParameters (String args []) {
0 commit comments