Skip to content

Commit

Permalink
Implemented library linking from archive files rather then object files.
Browse files Browse the repository at this point in the history
Feature exposed ONLY to libraries with "dot_a_linkage=true" in their
library.properties file
Fixes #10

Signed-off-by: Federico Fissore <[email protected]>
  • Loading branch information
Federico Fissore committed Sep 23, 2015
1 parent b966748 commit cd9236d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
for _, objectFile := range objectFiles {
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(archiveFilePath)
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile

_, err := ExecRecipe(properties, constants.RECIPE_AR_PATTERN, false, verbose, verbose, logger)
Expand Down
3 changes: 3 additions & 0 deletions src/arduino.cc/builder/hardware/platform.keys.rewrite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ new.6.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={buil
#specific to RFduino 1.6.3
old.7.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} {build.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -Wl,--cref -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/syscalls.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.variant.path}/libRFduino.a" "{build.variant.path}/libRFduinoBLE.a" "{build.variant.path}/libRFduinoGZLL.a" "{build.path}/{archive_file}" -Wl,--end-group
new.7.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} {build.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -Wl,--cref -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/core/syscalls.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.variant.path}/libRFduino.a" "{build.variant.path}/libRFduinoBLE.a" "{build.variant.path}/libRFduinoGZLL.a" "{build.path}/{archive_file}" -Wl,--end-group

old.8.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"
new.8.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
7 changes: 7 additions & 0 deletions src/arduino.cc/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func compileLibrary(objectFiles []string, library *types.Library, buildPath stri
if err != nil {
return nil, utils.WrapError(err)
}
if library.DotALinkage {
archiveFile, err := builder_utils.ArchiveCompiledFiles(libraryBuildPath, library.Name+".a", objectFiles, buildProperties, verbose, logger)
if err != nil {
return nil, utils.WrapError(err)
}
objectFiles = []string{archiveFile}
}
} else {
utilitySourcePath := filepath.Join(library.SrcFolder, constants.LIBRARY_FOLDER_UTILITY)
_, utilitySourcePathErr := os.Stat(utilitySourcePath)
Expand Down
10 changes: 7 additions & 3 deletions src/arduino.cc/builder/phases/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ func (s *Linker) Run(context map[string]interface{}) error {
objectFiles = append(objectFiles, objectFilesLibraries...)

coreArchiveFilePath := context[constants.CTX_ARCHIVE_FILE_PATH_CORE].(string)
buildPath := context[constants.CTX_BUILD_PATH].(string)
coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath)
if err != nil {
return utils.WrapError(err)
}

buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
verbose := context[constants.CTX_VERBOSE].(bool)
warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string)
logger := context[constants.CTX_LOGGER].(i18n.Logger)

err := link(objectFiles, coreArchiveFilePath, buildProperties, verbose, warningsLevel, logger)
err = link(objectFiles, coreDotARelPath, buildProperties, verbose, warningsLevel, logger)
if err != nil {
return utils.WrapError(err)
}
Expand All @@ -72,8 +77,7 @@ func link(objectFiles []string, coreArchiveFilePath string, buildProperties map[
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] + optRelax
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(coreArchiveFilePath)
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = coreArchiveFilePath
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = coreArchiveFilePath
properties[constants.BUILD_PROPERTIES_OBJECT_FILES] = objectFileList

_, err := builder_utils.ExecRecipe(properties, constants.RECIPE_C_COMBINE_PATTERN, false, verbose, verbose, logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) {

platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)

require.Equal(t, 8, len(platformKeysRewrite.Rewrites))
require.Equal(t, 9, len(platformKeysRewrite.Rewrites))
require.Equal(t, constants.BUILD_PROPERTIES_COMPILER_PATH, platformKeysRewrite.Rewrites[0].Key)
require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/", platformKeysRewrite.Rewrites[0].OldValue)
require.Equal(t, "{runtime.tools.avr-gcc.path}/bin/", platformKeysRewrite.Rewrites[0].NewValue)
Expand Down

0 comments on commit cd9236d

Please sign in to comment.