@@ -250,3 +250,49 @@ func TestCompileWithInvalidBuildOptionJson(t *testing.T) {
250250 _ , _ , err = cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--verbose" )
251251 require .NoError (t , err )
252252}
253+
254+ func TestCompileWithEsp32BundledLibraries (t * testing.T ) {
255+ // Some esp cores have have bundled libraries that are optimize for that architecture,
256+ // it might happen that if the user has a library with the same name installed conflicts
257+ // can ensue and the wrong library is used for compilation, thus it fails.
258+ // This happens because for "historical" reasons these platform have their "name" key
259+ // in the "library.properties" flag suffixed with "(esp32)" or similar even though that
260+ // doesn't respect the libraries specification.
261+ // https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format
262+ //
263+ // The reason those libraries have these suffixes is to avoid an annoying bug in the Java IDE
264+ // that would have caused the libraries that are both bundled with the core and the Java IDE to be
265+ // always marked as updatable. For more info see: https://github.com/arduino/Arduino/issues/4189
266+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
267+ defer env .CleanUp ()
268+
269+ _ , _ , err := cli .Run ("update" )
270+ require .NoError (t , err )
271+
272+ // Update index with esp32 core and install it
273+ url := "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json"
274+ coreVersion := "1.0.6"
275+ _ , _ , err = cli .Run ("core" , "update-index" , "--additional-urls=" + url )
276+ require .NoError (t , err )
277+ _ , _ , err = cli .Run ("core" , "install" , "esp32:esp32@" + coreVersion , "--additional-urls=" + url )
278+ require .NoError (t , err )
279+
280+ // Install a library with the same name as one bundled with the core
281+ _ , _ , err = cli .Run ("lib" , "install" , "SD" )
282+ require .NoError (t , err )
283+
284+ sketchPath := cli .CopySketch ("sketch_with_sd_library" )
285+ fqbn := "esp32:esp32:esp32"
286+
287+ stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--verbose" )
288+ require .Error (t , err )
289+
290+ coreBundledLibPath := cli .DataDir ().Join ("packages" , "esp32" , "hardware" , "esp32" , coreVersion , "libraries" , "SD" )
291+ cliInstalledLibPath := cli .SketchbookDir ().Join ("libraries" , "SD" )
292+ expectedOutput := [3 ]string {
293+ "Multiple libraries were found for \" OneWire.h\" " ,
294+ " Used: " + coreBundledLibPath .String (),
295+ " Not used: " + cliInstalledLibPath .String (),
296+ }
297+ require .NotContains (t , string (stdout ), expectedOutput [0 ]+ "\n " + expectedOutput [1 ]+ "\n " + expectedOutput [2 ]+ "\n " )
298+ }
0 commit comments