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