@@ -20,6 +20,7 @@ import (
20
20
"cmp"
21
21
"encoding/json"
22
22
"os/exec"
23
+ "regexp"
23
24
"slices"
24
25
"strings"
25
26
"testing"
@@ -904,56 +905,75 @@ func comparePreprocessGoldenFile(t *testing.T, sketchDir *paths.Path, preprocess
904
905
require .Equal (t , buf .String (), strings .ReplaceAll (preprocessedSketch , "\r \n " , "\n " ))
905
906
}
906
907
907
- func TestCoreCaching (t * testing.T ) {
908
+ func TestBuildCaching (t * testing.T ) {
908
909
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
909
910
defer env .CleanUp ()
910
911
911
- sketchPath , err := paths .New (".." , "testdata" , "bare_minimum" ).Abs ()
912
- require .NoError (t , err )
913
-
914
912
// Install Arduino AVR Boards
915
- _ ,
_ ,
err = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
913
+ _ ,
_ ,
err : = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
916
914
require .NoError (t , err )
917
915
918
- // Create temporary cache dir
919
- buildCachePath , err := paths .MkTempDir ("" , "test_build_cache" )
920
- require .NoError (t , err )
921
- defer buildCachePath .RemoveAll ()
916
+ t .Run ("CoreCaching" , func (t * testing.T ) {
917
+ sketchPath , err := paths .New (".." , "testdata" , "bare_minimum" ).Abs ()
918
+ require .NoError (t , err )
922
919
923
- // Build first time
924
- _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath .String (), sketchPath .String ())
925
- require .NoError (t , err )
920
+ // Create temporary cache dir
921
+ buildCachePath , err := paths .MkTempDir ("" , "test_build_cache" )
922
+ require .NoError (t , err )
923
+ defer buildCachePath .RemoveAll ()
926
924
927
- // Find cached core and save timestamp
928
- pathList , err := buildCachePath .ReadDirRecursiveFiltered (nil , paths .FilterPrefixes ("core.a" ))
929
- require .NoError (t , err )
930
- require .Len (t , pathList , 1 )
931
- cachedCoreFile := pathList [0 ]
932
- lastUsedPath := cachedCoreFile .Parent ().Join (".last-used" )
933
- require .True (t , lastUsedPath .Exist ())
934
- coreStatBefore , err := cachedCoreFile .Stat ()
935
- require .NoError (t , err )
925
+ // Build first time
926
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath .String (), sketchPath .String ())
927
+ require .NoError (t , err )
936
928
937
- // Run build again and check timestamp is unchanged
938
- _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath .String (), sketchPath .String ())
939
- require .NoError (t , err )
940
- coreStatAfterRebuild , err := cachedCoreFile .Stat ()
941
- require .NoError (t , err )
942
- require .Equal (t , coreStatBefore .ModTime (), coreStatAfterRebuild .ModTime ())
929
+ // Find cached core and save timestamp
930
+ pathList , err := buildCachePath .ReadDirRecursiveFiltered (nil , paths .FilterPrefixes ("core.a" ))
931
+ require .NoError (t , err )
932
+ require .Len (t , pathList , 1 )
933
+ cachedCoreFile := pathList [0 ]
934
+ lastUsedPath := cachedCoreFile .Parent ().Join (".last-used" )
935
+ require .True (t , lastUsedPath .Exist ())
936
+ coreStatBefore , err := cachedCoreFile .Stat ()
937
+ require .NoError (t , err )
943
938
944
- // Touch a file of the core and check if the builder invalidate the cache
945
- time . Sleep ( time . Second )
946
- now := time . Now (). Local ( )
947
- coreFolder := cli . DataDir (). Join ( "packages" , "arduino" , "hardware" , "avr" , "1.8.6" )
948
- err = coreFolder . Join ( "cores" , "arduino" , "Arduino.h" ). Chtimes ( now , now )
949
- require .NoError (t , err )
939
+ // Run build again and check timestamp is unchanged
940
+ _ , _ , err = cli . Run ( "compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath . String (), sketchPath . String () )
941
+ require . NoError ( t , err )
942
+ coreStatAfterRebuild , err := cachedCoreFile . Stat ( )
943
+ require . NoError ( t , err )
944
+ require .Equal (t , coreStatBefore . ModTime (), coreStatAfterRebuild . ModTime () )
950
945
951
- // Run build again, to verify that the builder rebuilds core.a
952
- _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath .String (), sketchPath .String ())
953
- require .NoError (t , err )
954
- coreStatAfterTouch , err := cachedCoreFile .Stat ()
955
- require .NoError (t , err )
956
- require .NotEqual (t , coreStatBefore .ModTime (), coreStatAfterTouch .ModTime ())
946
+ // Touch a file of the core and check if the builder invalidate the cache
947
+ time .Sleep (time .Second )
948
+ now := time .Now ().Local ()
949
+ coreFolder := cli .DataDir ().Join ("packages" , "arduino" , "hardware" , "avr" , "1.8.6" )
950
+ err = coreFolder .Join ("cores" , "arduino" , "Arduino.h" ).Chtimes (now , now )
951
+ require .NoError (t , err )
952
+
953
+ // Run build again, to verify that the builder rebuilds core.a
954
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-cache-path" , buildCachePath .String (), sketchPath .String ())
955
+ require .NoError (t , err )
956
+ coreStatAfterTouch , err := cachedCoreFile .Stat ()
957
+ require .NoError (t , err )
958
+ require .NotEqual (t , coreStatBefore .ModTime (), coreStatAfterTouch .ModTime ())
959
+ })
960
+
961
+ t .Run ("LibraryCacheWithDifferentDirname" , func (t * testing.T ) {
962
+ _ , _ , err = cli .Run ("lib" , "install" , "Robot IR Remote" )
963
+ require .NoError (t , err )
964
+
965
+ // Run first compile
966
+ sketchPath , err := paths .New ("testdata" , "SketchUsingRobotIRRemote" ).Abs ()
967
+ require .NoError (t , err )
968
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:robotControl" , "-v" , sketchPath .String ())
969
+ require .NoError (t , err )
970
+
971
+ // Run second compile and check that previous build is re-used
972
+ out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:robotControl" , "-v" , sketchPath .String ())
973
+ require .NoError (t , err )
974
+ check := regexp .MustCompile (`(?m)^Using previously compiled file:.*IRremoteTools\.cpp\.o$` )
975
+ require .True (t , check .Match (out ))
976
+ })
957
977
}
958
978
959
979
func TestMergeSketchWithBootloader (t * testing.T ) {
0 commit comments