@@ -1022,3 +1022,83 @@ def test_compile_with_invalid_build_options_json(run_command, data_dir):
10221022 f .write ("invalid json" )
10231023
10241024 assert run_command (f"compile -b { fqbn } { sketch_path } --verbose" )
1025+
1026+
1027+ def test_compile_with_esp32_bundled_libraries (run_command , data_dir , copy_sketch ):
1028+ # Some esp cores have have bundled libraries that are optimize for that architecture,
1029+ # it might happen that if the user has a library with the same name installed conflicts
1030+ # can ensue and the wrong library is used for compilation, thus it fails.
1031+ # This happens because for "historical" reasons these platform have their "name" key
1032+ # in the "library.properties" flag suffixed with "(esp32)" or similar even though that
1033+ # doesn't respect the libraries specification.
1034+ # https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format
1035+ #
1036+ # The reason those libraries have these suffixes is to avoid an annoying bug in the Java IDE
1037+ # that would have caused the libraries that are both bundled with the core and the Java IDE to be
1038+ # always marked as updatable. For more info see: https://github.com/arduino/Arduino/issues/4189
1039+ assert run_command ("update" )
1040+
1041+ # Update index with esp32 core and install it
1042+ url = "https://dl.espressif.com/dl/package_esp32_index.json"
1043+ core_version = "1.0.6"
1044+ assert run_command (f"core update-index --additional-urls={ url } " )
1045+ assert run_command (f"core install esp32:esp32@{ core_version } --additional-urls={ url } " )
1046+
1047+ # Install a library with the same name as one bundled with the core
1048+ assert run_command ("lib install SD" )
1049+
1050+ sketch_path = copy_sketch ("sketch_with_sd_library" )
1051+ fqbn = "esp32:esp32:esp32"
1052+
1053+ res = run_command (f"compile -b { fqbn } { sketch_path } --verbose" )
1054+ assert res .ok
1055+
1056+ core_bundled_lib_path = Path (data_dir , "packages" , "esp32" , "hardware" , "esp32" , core_version , "libraries" , "SD" )
1057+ cli_installed_lib_path = Path (data_dir , "libraries" , "SD" )
1058+ expected_output = [
1059+ 'Multiple libraries were found for "SD.h"' ,
1060+ f" Used: { core_bundled_lib_path } " ,
1061+ f" Not used: { cli_installed_lib_path } " ,
1062+ ]
1063+ assert "\n " .join (expected_output ) in res .stdout
1064+
1065+
1066+ def test_compile_with_esp8266_bundled_libraries (run_command , data_dir , copy_sketch ):
1067+ # Some esp cores have have bundled libraries that are optimize for that architecture,
1068+ # it might happen that if the user has a library with the same name installed conflicts
1069+ # can ensue and the wrong library is used for compilation, thus it fails.
1070+ # This happens because for "historical" reasons these platform have their "name" key
1071+ # in the "library.properties" flag suffixed with "(esp32)" or similar even though that
1072+ # doesn't respect the libraries specification.
1073+ # https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format
1074+ #
1075+ # The reason those libraries have these suffixes is to avoid an annoying bug in the Java IDE
1076+ # that would have caused the libraries that are both bundled with the core and the Java IDE to be
1077+ # always marked as updatable. For more info see: https://github.com/arduino/Arduino/issues/4189
1078+ assert run_command ("update" )
1079+
1080+ # Update index with esp8266 core and install it
1081+ url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
1082+ core_version = "2.7.4"
1083+ assert run_command (f"core update-index --additional-urls={ url } " )
1084+ assert run_command (f"core install esp8266:esp8266@{ core_version } --additional-urls={ url } " )
1085+
1086+ # Install a library with the same name as one bundled with the core
1087+ assert run_command ("lib install SD" )
1088+
1089+ sketch_path = copy_sketch ("sketch_with_sd_library" )
1090+ fqbn = "esp8266:esp8266:generic"
1091+
1092+ res = run_command (f"compile -b { fqbn } { sketch_path } --verbose" )
1093+ assert res .ok
1094+
1095+ core_bundled_lib_path = Path (
1096+ data_dir , "packages" , "esp8266" , "hardware" , "esp8266" , core_version , "libraries" , "SD"
1097+ )
1098+ cli_installed_lib_path = Path (data_dir , "libraries" , "SD" )
1099+ expected_output = [
1100+ 'Multiple libraries were found for "SD.h"' ,
1101+ f" Used: { core_bundled_lib_path } " ,
1102+ f" Not used: { cli_installed_lib_path } " ,
1103+ ]
1104+ assert "\n " .join (expected_output ) in res .stdout
0 commit comments