@@ -718,28 +718,63 @@ void compileCore()
718
718
if (variantFolder != null )
719
719
includeFolders .add (variantFolder );
720
720
721
+
722
+ if (variantFolder != null )
723
+ objectFiles .addAll (compileFiles (buildFolder , variantFolder , true ,
724
+ includeFolders ));
725
+
726
+ File afile = new File (buildFolder , "core.a" );
727
+
721
728
List <File > coreObjectFiles = compileFiles (buildFolder , coreFolder , true ,
722
729
includeFolders );
723
- for (File file : coreObjectFiles ) {
724
730
725
- PreferencesMap dict = new PreferencesMap (prefs );
726
- dict .put ("ide_version" , "" + Base .REVISION );
727
- dict .put ("archive_file" , "core.a" );
728
- dict .put ("object_file" , file .getAbsolutePath ());
731
+ // See if the .a file is already uptodate
732
+ if (afile .exists ()) {
733
+ boolean changed = false ;
734
+ for (File file : coreObjectFiles ) {
735
+ if (file .lastModified () > afile .lastModified ()) {
736
+ changed = true ;
737
+ break ;
738
+ }
739
+ }
729
740
730
- String [] cmdArray ;
731
- try {
732
- String cmd = prefs .get ("recipe.ar.pattern" );
733
- cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
734
- } catch (Exception e ) {
735
- throw new RunnerException (e );
741
+ // If none of the object files is newer than the .a file, don't
742
+ // bother rebuilding the .a file. There is a small corner case
743
+ // here: If a source file was removed, but no other source file
744
+ // was modified, this will not rebuild core.a even when it
745
+ // should. It's hard to fix and not a realistic case, so it
746
+ // shouldn't be a problem.
747
+ if (!changed ) {
748
+ if (verbose )
749
+ System .out .println (I18n .format (_ ("Using previously compiled file: {0}" ), afile .getPath ()));
750
+ return ;
736
751
}
737
- execAsynchronously (cmdArray );
738
752
}
739
753
740
- if (variantFolder != null )
741
- objectFiles .addAll (compileFiles (buildFolder , variantFolder , true ,
742
- includeFolders ));
754
+ // Delete the .a file, to prevent any previous code from lingering
755
+ afile .delete ();
756
+
757
+ try {
758
+ for (File file : coreObjectFiles ) {
759
+
760
+ PreferencesMap dict = new PreferencesMap (prefs );
761
+ dict .put ("ide_version" , "" + Base .REVISION );
762
+ dict .put ("archive_file" , afile .getName ());
763
+ dict .put ("object_file" , file .getAbsolutePath ());
764
+
765
+ String [] cmdArray ;
766
+ try {
767
+ String cmd = prefs .get ("recipe.ar.pattern" );
768
+ cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
769
+ } catch (Exception e ) {
770
+ throw new RunnerException (e );
771
+ }
772
+ execAsynchronously (cmdArray );
773
+ }
774
+ } catch (RunnerException e ) {
775
+ afile .delete ();
776
+ throw e ;
777
+ }
743
778
}
744
779
745
780
// 4. link it all together into the .elf file
0 commit comments