Skip to content

Commit 0f997dc

Browse files
committed
Merge pull request #3303 from ffissore/object-files-in-subdirs
RFC > Compiler: core files in "core" subfolder, libraries in "libraries"
2 parents 46058a5 + a853372 commit 0f997dc

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

Diff for: arduino-core/src/processing/app/debug/Compiler.java

+22-7
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ protected void size(PreferencesMap prefs) throws RunnerException {
358358
* @throws RunnerException Only if there's a problem. Only then.
359359
*/
360360
public boolean compile(boolean _verbose, boolean _save) throws RunnerException, PreferencesMapException {
361-
preprocess(prefs.get("build.path"));
361+
File sketchBuildFolder = new File(prefs.get("build.path"), "sketch");
362+
if (!sketchBuildFolder.exists() && !sketchBuildFolder.mkdirs()) {
363+
throw new RunnerException("Unable to create folder " + sketchBuildFolder);
364+
}
365+
preprocess(sketchBuildFolder.getAbsolutePath());
362366

363367
verbose = _verbose || PreferencesData.getBoolean("build.verbose");
364368
saveHex = _save;
@@ -410,7 +414,7 @@ public boolean compile(boolean _verbose, boolean _save) throws RunnerException,
410414

411415
// 1. compile the sketch (already in the buildPath)
412416
progressListener.progress(20);
413-
compileSketch(includeFolders);
417+
compileSketch(includeFolders, sketchBuildFolder);
414418
sketchIsCompiled = true;
415419

416420
runActions("hooks.sketch.postbuild", prefs);
@@ -485,6 +489,9 @@ public boolean compile(boolean _verbose, boolean _save) throws RunnerException,
485489
}
486490

487491
private void adviseDuplicateLibraries() {
492+
if (importedDuplicateHeaders == null) {
493+
return;
494+
}
488495
for (int i=0; i < importedDuplicateHeaders.size(); i++) {
489496
System.out.println(I18n.format(_("Multiple libraries were found for \"{0}\""),
490497
importedDuplicateHeaders.get(i)));
@@ -995,8 +1002,7 @@ static public List<File> findFilesInFolder(File folder, String extension,
9951002
}
9961003

9971004
// 1. compile the sketch (already in the buildPath)
998-
void compileSketch(List<File> includeFolders) throws RunnerException, PreferencesMapException {
999-
File buildPath = prefs.getFile("build.path");
1005+
void compileSketch(List<File> includeFolders, File buildPath) throws RunnerException, PreferencesMapException {
10001006
objectFiles.addAll(compileFiles(buildPath, buildPath, false, includeFolders));
10011007
}
10021008

@@ -1011,7 +1017,12 @@ void compileLibraries(List<File> includeFolders) throws RunnerException, Prefere
10111017
private void compileLibrary(UserLibrary lib, List<File> includeFolders)
10121018
throws RunnerException, PreferencesMapException {
10131019
File libFolder = lib.getSrcFolder();
1014-
File libBuildFolder = prefs.getFile(("build.path"), lib.getName());
1020+
File librariesFolder = new File(prefs.getFile("build.path"), "libraries");
1021+
if (!librariesFolder.exists() && !librariesFolder.mkdirs()) {
1022+
throw new RunnerException("Unable to create folder " + librariesFolder);
1023+
}
1024+
1025+
File libBuildFolder = new File(librariesFolder, lib.getName());
10151026

10161027
if (lib.useRecursion()) {
10171028
// libBuildFolder == {build.path}/LibName
@@ -1058,7 +1069,10 @@ void compileCore()
10581069

10591070
File coreFolder = prefs.getFile("build.core.path");
10601071
File variantFolder = prefs.getFile("build.variant.path");
1061-
File buildFolder = prefs.getFile("build.path");
1072+
File buildFolder = new File(prefs.getFile("build.path"), "core");
1073+
if (!buildFolder.exists() && !buildFolder.mkdirs()) {
1074+
throw new RunnerException("Unable to create folder " + buildFolder);
1075+
}
10621076

10631077
List<File> includeFolders = new ArrayList<File>();
10641078
includeFolders.add(coreFolder); // include core path only
@@ -1108,6 +1122,7 @@ void compileCore()
11081122
dict.put("ide_version", "" + BaseNoGui.REVISION);
11091123
dict.put("archive_file", afile.getName());
11101124
dict.put("object_file", file.getAbsolutePath());
1125+
dict.put("build.path", buildFolder.getAbsolutePath());
11111126

11121127
String[] cmdArray;
11131128
String cmd = prefs.getOrExcept("recipe.ar.pattern");
@@ -1144,7 +1159,7 @@ void compileLink()
11441159
PreferencesMap dict = new PreferencesMap(prefs);
11451160
String flags = dict.get("compiler.c.elf.flags") + optRelax;
11461161
dict.put("compiler.c.elf.flags", flags);
1147-
dict.put("archive_file", "core.a");
1162+
dict.put("archive_file", new File("core", "core.a").getPath());
11481163
dict.put("object_files", objectFileList);
11491164
dict.put("ide_version", "" + BaseNoGui.REVISION);
11501165

Diff for: hardware/arduino/avr/platform.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={b
6565
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"
6666

6767
## Combine gc-sections, archives, and objects
68-
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
68+
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
6969

7070
## Create output files (.eep and .hex)
71-
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"
72-
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"
71+
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"
72+
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"
7373

7474
## Save hex
7575
recipe.output.tmp_file={build.project_name}.hex
7676
recipe.output.save_file={build.project_name}.{build.variant}.hex
7777

7878
## Compute size
79-
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
79+
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/sketch/{build.project_name}.elf"
8080
recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*
8181
recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*
8282
recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*

Diff for: hardware/arduino/sam/platform.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -mcpu={b
7575
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"
7676

7777
## Combine gc-sections, archives, and objects
78-
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
78+
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
7979

8080
## Create output (.bin file)
81-
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"
81+
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"
8282

8383
## Save hex
8484
recipe.output.tmp_file={build.project_name}.bin
8585
recipe.output.save_file={build.project_name}.{build.variant}.bin
8686

8787
## Compute size
88-
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
88+
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/sketch/{build.project_name}.elf"
8989
recipe.size.regex=\.text\s+([0-9]+).*
9090

9191

@@ -98,5 +98,5 @@ tools.bossac.cmd.windows=bossac.exe
9898

9999
tools.bossac.upload.params.verbose=-i -d
100100
tools.bossac.upload.params.quiet=
101-
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
101+
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
102102

Diff for: hardware/platform.keys.rewrite.txt

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ new.3.compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
1515
old.4.tools.bossac.path={runtime.ide.path}/hardware/tools
1616
new.4.tools.bossac.path={runtime.tools.bossac.path}
1717

18+
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
19+
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
20+

0 commit comments

Comments
 (0)