@@ -27,6 +27,8 @@ import (
27
27
"github.com/arduino/go-paths-helper"
28
28
"github.com/stretchr/testify/require"
29
29
"go.bug.st/testifyjson/requirejson"
30
+ "gopkg.in/src-d/go-git.v4"
31
+ "gopkg.in/src-d/go-git.v4/plumbing"
30
32
)
31
33
32
34
func TestCompile (t * testing.T ) {
@@ -711,3 +713,247 @@ func compileUsingBoardsLocalTxt(t *testing.T, env *integrationtest.Environment,
711
713
_ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
712
714
require .NoError (t , err )
713
715
}
716
+
717
+ func TestCompileWithoutPrecompiledLibraries (t * testing.T ) {
718
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
719
+ defer env .CleanUp ()
720
+
721
+ // Init the environment explicitly
722
+ url := "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
723
+ _ , _ , err := cli .Run ("core" , "update-index" , "--additional-urls=" + url )
724
+ require .NoError (t , err )
725
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:mbed@1.3.1" , "--additional-urls=" + url )
726
+ require .NoError (t , err )
727
+
728
+ // // Precompiled version of Arduino_TensorflowLite
729
+ // _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1")
730
+ // require.NoError(t, err)
731
+ // _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.1-ALPHA-precompiled")
732
+ // require.NoError(t, err)
733
+
734
+ // sketchPath := cli.SketchbookDir().Join("libraries", "Arduino_TensorFlowLite", "examples", "hello_world")
735
+ // _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
736
+ // require.NoError(t, err)
737
+
738
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:samd@1.8.7" , "--additional-urls=" + url )
739
+ require .NoError (t , err )
740
+ // _, _, err = cli.Run("core", "install", "adafruit:samd@1.6.4", "--additional-urls="+url)
741
+ // require.NoError(t, err)
742
+ // // should work on adafruit too after https://github.com/arduino/arduino-cli/pull/1134
743
+ // _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String())
744
+ // require.NoError(t, err)
745
+
746
+ // // Non-precompiled version of Arduino_TensorflowLite
747
+ // _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.0-ALPHA")
748
+ // require.NoError(t, err)
749
+ // _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
750
+ // require.NoError(t, err)
751
+ // _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String())
752
+ // require.NoError(t, err)
753
+
754
+ // Bosch sensor library
755
+ _ , _ , err = cli .Run ("lib" , "install" , "BSEC Software Library@1.5.1474" )
756
+ require .NoError (t , err )
757
+ sketchPath := cli .SketchbookDir ().Join ("libraries" , "BSEC_Software_Library" , "examples" , "basic" )
758
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:samd:mkr1000" , sketchPath .String ())
759
+ require .NoError (t , err )
760
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:mbed:nano33ble" , sketchPath .String ())
761
+ require .NoError (t , err )
762
+
763
+ // USBBlaster library
764
+ _ , _ , err = cli .Run ("lib" , "install" , "USBBlaster@1.0.0" )
765
+ require .NoError (t , err )
766
+ sketchPath = cli .SketchbookDir ().Join ("libraries" , "USBBlaster" , "examples" , "USB_Blaster" )
767
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:samd:mkrvidor4000" , sketchPath .String ())
768
+ require .NoError (t , err )
769
+ }
770
+
771
+ func TestCompileWithCustomLibraries (t * testing.T ) {
772
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
773
+ defer env .CleanUp ()
774
+
775
+ // Creates config with additional URL to install necessary core
776
+ url := "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
777
+ _ , _ , err := cli .Run ("config" , "init" , "--dest-dir" , "." , "--additional-urls" , url )
778
+ require .NoError (t , err )
779
+
780
+ // Init the environment explicitly
781
+ _ , _ , err = cli .Run ("update" )
782
+ require .NoError (t , err )
783
+
784
+ _ , _ , err = cli .Run ("core" , "install" , "esp8266:esp8266" )
785
+ require .NoError (t , err )
786
+
787
+ sketchName := "sketch_with_multiple_custom_libraries"
788
+ sketchPath := cli .CopySketch (sketchName )
789
+ fqbn := "esp8266:esp8266:nodemcu:xtal=80,vt=heap,eesz=4M1M,wipe=none,baud=115200"
790
+
791
+ firstLib := sketchPath .Join ("libraries1" )
792
+ secondLib := sketchPath .Join ("libraries2" )
793
+ _ , _ , err = cli .Run ("compile" , "--libraries" , firstLib .String (), "--libraries" , secondLib .String (), "-b" , fqbn , sketchPath .String ())
794
+ require .NoError (t , err )
795
+ }
796
+
797
+ func TestCompileWithArchivesAndLongPaths (t * testing.T ) {
798
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
799
+ defer env .CleanUp ()
800
+
801
+ // Creates config with additional URL to install necessary core
802
+ url := "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
803
+ _ , _ , err := cli .Run ("config" , "init" , "--dest-dir" , "." , "--additional-urls" , url )
804
+ require .NoError (t , err )
805
+
806
+ // Init the environment explicitly
807
+ _ , _ , err = cli .Run ("update" )
808
+ require .NoError (t , err )
809
+
810
+ // Install core to compile
811
+ _ , _ , err = cli .Run ("core" , "install" , "esp8266:esp8266@2.7.4" )
812
+ require .NoError (t , err )
813
+
814
+ // Install test library
815
+ _ , _ , err = cli .Run ("lib" , "install" , "ArduinoIoTCloud" )
816
+ require .NoError (t , err )
817
+
818
+ stdout , _ , err := cli .Run ("lib" , "examples" , "ArduinoIoTCloud" , "--format" , "json" )
819
+ require .NoError (t , err )
820
+ var libOutput []map [string ]interface {}
821
+ err = json .Unmarshal (stdout , & libOutput )
822
+ require .NoError (t , err )
823
+ sketchPath := paths .New (libOutput [0 ]["library" ].(map [string ]interface {})["install_dir" ].(string ))
824
+ sketchPath = sketchPath .Join ("examples" , "ArduinoIoTCloud-Advanced" )
825
+
826
+ _ , _ , err = cli .Run ("compile" , "-b" , "esp8266:esp8266:huzzah" , sketchPath .String ())
827
+ require .NoError (t , err )
828
+ }
829
+
830
+ func TestCompileWithPrecompileLibrary (t * testing.T ) {
831
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
832
+ defer env .CleanUp ()
833
+
834
+ _ , _ , err := cli .Run ("update" )
835
+ require .NoError (t , err )
836
+
837
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:samd@1.8.11" )
838
+ require .NoError (t , err )
839
+ fqbn := "arduino:samd:mkrzero"
840
+
841
+ // Install precompiled library
842
+ // For more information see:
843
+ // https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries
844
+ _ , _ , err = cli .Run ("lib" , "install" , "BSEC Software Library@1.5.1474" )
845
+ require .NoError (t , err )
846
+ sketchFolder := cli .SketchbookDir ().Join ("libraries" , "BSEC_Software_Library" , "examples" , "basic" )
847
+
848
+ // Compile and verify dependencies detection for fully precompiled library is not skipped
849
+ stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchFolder .String (), "-v" )
850
+ require .NoError (t , err )
851
+ require .NotContains (t , string (stdout ), "Skipping dependencies detection for precompiled library BSEC Software Library" )
852
+ }
853
+
854
+ func TestCompileWithFullyPrecompiledLibrary (t * testing.T ) {
855
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
856
+ defer env .CleanUp ()
857
+
858
+ _ , _ , err := cli .Run ("update" )
859
+ require .NoError (t , err )
860
+
861
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:mbed@1.3.1" )
862
+ require .NoError (t , err )
863
+ fqbn := "arduino:mbed:nano33ble"
864
+
865
+ // Create settings with library unsafe install set to true
866
+ envVar := cli .GetDefaultEnv ()
867
+ envVar ["ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL" ] = "true"
868
+ _ , _ , err = cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
869
+ require .NoError (t , err )
870
+
871
+ // Install fully precompiled library
872
+ // For more information see:
873
+ // https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries
874
+ wd , err := paths .Getwd ()
875
+ require .NoError (t , err )
876
+ _ , _ , err = cli .Run ("lib" , "install" , "--zip-path" , wd .Parent ().Join ("testdata" , "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip" ).String ())
877
+ require .NoError (t , err )
878
+ sketchFolder := cli .SketchbookDir ().Join ("libraries" , "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled" , "examples" , "hello_world" )
879
+
880
+ // Install example dependency
881
+ _ , _ , err = cli .Run ("lib" , "install" , "Arduino_LSM9DS1" )
882
+ require .NoError (t , err )
883
+
884
+ // Compile and verify dependencies detection for fully precompiled library is skipped
885
+ stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchFolder .String (), "-v" )
886
+ require .NoError (t , err )
887
+ require .Contains (t , string (stdout ), "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite" )
888
+ }
889
+
890
+ func TestCompileManuallyInstalledPlatform (t * testing.T ) {
891
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
892
+ defer env .CleanUp ()
893
+
894
+ _ , _ , err := cli .Run ("update" )
895
+ require .NoError (t , err )
896
+
897
+ sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
898
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
899
+ fqbn := "arduino-beta-development:avr:uno"
900
+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
901
+ require .NoError (t , err )
902
+
903
+ // Manually installs a core in sketchbooks hardware folder
904
+ gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
905
+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
906
+ _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
907
+ URL : gitUrl ,
908
+ ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
909
+ })
910
+ require .NoError (t , err )
911
+
912
+ // Installs also the same core via CLI so all the necessary tools are installed
913
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
914
+ require .NoError (t , err )
915
+
916
+ // Verifies compilation works without issues
917
+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
918
+ require .NoError (t , err )
919
+ }
920
+
921
+ func TestCompileManuallyInstalledPlatformUsingPlatformLocalTxt (t * testing.T ) {
922
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
923
+ defer env .CleanUp ()
924
+
925
+ _ , _ , err := cli .Run ("update" )
926
+ require .NoError (t , err )
927
+
928
+ sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
929
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
930
+ fqbn := "arduino-beta-development:avr:uno"
931
+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
932
+ require .NoError (t , err )
933
+
934
+ // Manually installs a core in sketchbooks hardware folder
935
+ gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
936
+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
937
+ _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
938
+ URL : gitUrl ,
939
+ ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
940
+ })
941
+ require .NoError (t , err )
942
+
943
+ // Installs also the same core via CLI so all the necessary tools are installed
944
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
945
+ require .NoError (t , err )
946
+
947
+ // Verifies compilation works without issues
948
+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
949
+ require .NoError (t , err )
950
+
951
+ // Overrides default platform compiler with an unexisting one
952
+ platformLocalTxt := repoDir .Join ("platform.local.txt" )
953
+ platformLocalTxt .WriteFile ([]byte ("compiler.c.cmd=my-compiler-that-does-not-exist" ))
954
+
955
+ // Verifies compilation now fails because compiler is not found
956
+ _ , stderr , err := cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
957
+ require .Error (t , err )
958
+ require .Contains (t , string (stderr ), "my-compiler-that-does-not-exist" )
959
+ }
0 commit comments