From 5a35be06da7b3424dc9f439c8883eeae0ae09842 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 15 Jun 2015 15:30:37 +0200 Subject: [PATCH 1/3] Compiler: cores files get compiled under "core", libraries under "libraries". Fixes #2997 --- .../src/processing/app/debug/Compiler.java | 15 ++++++++++++--- hardware/arduino/sam/platform.txt | 2 +- hardware/platform.keys.rewrite.txt | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 5f1bf9ad5..0d80a717f 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -1011,7 +1011,12 @@ public class Compiler implements MessageConsumer { private void compileLibrary(UserLibrary lib, List includeFolders) throws RunnerException, PreferencesMapException { File libFolder = lib.getSrcFolder(); - File libBuildFolder = prefs.getFile(("build.path"), lib.getName()); + File librariesFolder = new File(prefs.getFile("build.path"), "libraries"); + if (!librariesFolder.exists() && !librariesFolder.mkdirs()) { + throw new RunnerException("Unable to create folder " + librariesFolder); + } + + File libBuildFolder = new File(librariesFolder, lib.getName()); if (lib.useRecursion()) { // libBuildFolder == {build.path}/LibName @@ -1058,7 +1063,10 @@ public class Compiler implements MessageConsumer { File coreFolder = prefs.getFile("build.core.path"); File variantFolder = prefs.getFile("build.variant.path"); - File buildFolder = prefs.getFile("build.path"); + File buildFolder = new File(prefs.getFile("build.path"), "core"); + if (!buildFolder.exists() && !buildFolder.mkdirs()) { + throw new RunnerException("Unable to create folder " + buildFolder); + } List includeFolders = new ArrayList(); includeFolders.add(coreFolder); // include core path only @@ -1108,6 +1116,7 @@ public class Compiler implements MessageConsumer { dict.put("ide_version", "" + BaseNoGui.REVISION); dict.put("archive_file", afile.getName()); dict.put("object_file", file.getAbsolutePath()); + dict.put("build.path", buildFolder.getAbsolutePath()); String[] cmdArray; String cmd = prefs.getOrExcept("recipe.ar.pattern"); @@ -1144,7 +1153,7 @@ public class Compiler implements MessageConsumer { PreferencesMap dict = new PreferencesMap(prefs); String flags = dict.get("compiler.c.elf.flags") + optRelax; dict.put("compiler.c.elf.flags", flags); - dict.put("archive_file", "core.a"); + dict.put("archive_file", new File("core", "core.a").getPath()); dict.put("object_files", objectFileList); dict.put("ide_version", "" + BaseNoGui.REVISION); diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index d52fb98a4..a2706e43f 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -75,7 +75,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -mcpu={b recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc ## Create output (.bin file) recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" diff --git a/hardware/platform.keys.rewrite.txt b/hardware/platform.keys.rewrite.txt index e14de1e6d..bc6bb5e08 100644 --- a/hardware/platform.keys.rewrite.txt +++ b/hardware/platform.keys.rewrite.txt @@ -15,3 +15,6 @@ new.3.compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ old.4.tools.bossac.path={runtime.ide.path}/hardware/tools new.4.tools.bossac.path={runtime.tools.bossac.path} +old.5.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc +new.5.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc + From e097439eab6be8b63f786276cec87568044a3543 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 15 Jun 2015 15:51:58 +0200 Subject: [PATCH 2/3] Compiler: sketch files get compiled into "sketch" --- arduino-core/src/processing/app/debug/Compiler.java | 11 +++++++---- hardware/arduino/avr/platform.txt | 8 ++++---- hardware/arduino/sam/platform.txt | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 0d80a717f..d570e4534 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -358,7 +358,11 @@ public class Compiler implements MessageConsumer { * @throws RunnerException Only if there's a problem. Only then. */ public boolean compile(boolean _verbose, boolean _save) throws RunnerException, PreferencesMapException { - preprocess(prefs.get("build.path")); + File sketchBuildFolder = new File(prefs.get("build.path"), "sketch"); + if (!sketchBuildFolder.mkdirs()) { + throw new RunnerException("Unable to create folder " + sketchBuildFolder); + } + preprocess(sketchBuildFolder.getAbsolutePath()); verbose = _verbose || PreferencesData.getBoolean("build.verbose"); saveHex = _save; @@ -410,7 +414,7 @@ public class Compiler implements MessageConsumer { // 1. compile the sketch (already in the buildPath) progressListener.progress(20); - compileSketch(includeFolders); + compileSketch(includeFolders, sketchBuildFolder); sketchIsCompiled = true; runActions("hooks.sketch.postbuild", prefs); @@ -995,8 +999,7 @@ public class Compiler implements MessageConsumer { } // 1. compile the sketch (already in the buildPath) - void compileSketch(List includeFolders) throws RunnerException, PreferencesMapException { - File buildPath = prefs.getFile("build.path"); + void compileSketch(List includeFolders, File buildPath) throws RunnerException, PreferencesMapException { objectFiles.addAll(compileFiles(buildPath, buildPath, false, includeFolders)); } diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index b3c99864c..a597f26f8 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -65,18 +65,18 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={b recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/sketch/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm ## Create output files (.eep and .hex) -recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" -recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" +recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/sketch/{build.project_name}.elf" "{build.path}/sketch/{build.project_name}.eep" +recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/sketch/{build.project_name}.elf" "{build.path}/sketch/{build.project_name}.hex" ## Save hex recipe.output.tmp_file={build.project_name}.hex recipe.output.save_file={build.project_name}.{build.variant}.hex ## Compute size -recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/sketch/{build.project_name}.elf" recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).* recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index a2706e43f..cbb933278 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -75,17 +75,17 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -mcpu={b recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/sketch/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc ## Create output (.bin file) -recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" +recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/sketch/{build.project_name}.elf" "{build.path}/sketch/{build.project_name}.bin" ## Save hex recipe.output.tmp_file={build.project_name}.bin recipe.output.save_file={build.project_name}.{build.variant}.bin ## Compute size -recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/sketch/{build.project_name}.elf" recipe.size.regex=\.text\s+([0-9]+).* @@ -98,5 +98,5 @@ tools.bossac.cmd.windows=bossac.exe tools.bossac.upload.params.verbose=-i -d tools.bossac.upload.params.quiet= -tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -e -w -v -b "{build.path}/{build.project_name}.bin" -R +tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -e -w -v -b "{build.path}/sketch/{build.project_name}.bin" -R From a853372872a070207c33f0e5c41d4ccd0da9b60f Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 29 Jun 2015 15:32:32 +0200 Subject: [PATCH 3/3] Compiler: fixed wrong check against non existent folder and a possible NPE --- arduino-core/src/processing/app/debug/Compiler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index d570e4534..9609dd65e 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -359,7 +359,7 @@ public class Compiler implements MessageConsumer { */ public boolean compile(boolean _verbose, boolean _save) throws RunnerException, PreferencesMapException { File sketchBuildFolder = new File(prefs.get("build.path"), "sketch"); - if (!sketchBuildFolder.mkdirs()) { + if (!sketchBuildFolder.exists() && !sketchBuildFolder.mkdirs()) { throw new RunnerException("Unable to create folder " + sketchBuildFolder); } preprocess(sketchBuildFolder.getAbsolutePath()); @@ -489,6 +489,9 @@ public class Compiler implements MessageConsumer { } private void adviseDuplicateLibraries() { + if (importedDuplicateHeaders == null) { + return; + } for (int i=0; i < importedDuplicateHeaders.size(); i++) { System.out.println(I18n.format(_("Multiple libraries were found for \"{0}\""), importedDuplicateHeaders.get(i)));