Skip to content

Modularization of ctags and some refactorings #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ package builder

import (
"arduino.cc/builder/constants"
"arduino.cc/builder/props"
"arduino.cc/builder/types"
"arduino.cc/builder/utils"
)

type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{}

func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}) error {
packages := context[constants.CTX_HARDWARE].(*types.Packages)
targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package)
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)

buildProperties = utils.MergeMapsOfStrings(make(map[string]string), packages.Properties, targetPackage.Properties, buildProperties)
newBuildProperties := packages.Properties.Clone()
newBuildProperties.Merge(targetPackage.Properties)
newBuildProperties.Merge(buildProperties)

context[constants.CTX_BUILD_PROPERTIES] = buildProperties
context[constants.CTX_BUILD_PROPERTIES] = newBuildProperties

return nil
}
26 changes: 13 additions & 13 deletions src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"strings"
)

func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
objectFiles, err := CompileFiles(objectFiles, sourcePath, false, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
if err != nil {
return nil, utils.WrapError(err)
Expand All @@ -63,7 +63,7 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
return objectFiles, nil
}

func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
objectFiles, err := compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN, verbose, warningsLevel, logger)
if err != nil {
return nil, utils.WrapError(err)
Expand All @@ -79,7 +79,7 @@ func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPa
return objectFiles, nil
}

func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties map[string]string, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
sources, err := findFilesInFolder(sourcePath, extension, recurse)
if err != nil {
return nil, utils.WrapError(err)
Expand Down Expand Up @@ -115,7 +115,7 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str
return sources, nil
}

func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties props.PropertiesMap, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
for _, source := range sources {
objectFile, err := compileFileWithRecipe(sourcePath, source, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
if err != nil {
Expand All @@ -127,8 +127,8 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
return objectFiles, nil
}

func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties props.PropertiesMap, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source
Expand Down Expand Up @@ -255,7 +255,7 @@ func nonEmptyString(s string) bool {
return s != constants.EMPTY_STRING
}

func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties map[string]string, verbose bool, logger i18n.Logger) (string, error) {
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties props.PropertiesMap, verbose bool, logger i18n.Logger) (string, error) {
archiveFilePath := filepath.Join(buildPath, archiveFile)
if _, err := os.Stat(archiveFilePath); err == nil {
err = os.Remove(archiveFilePath)
Expand All @@ -265,7 +265,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
}

for _, objectFile := range objectFiles {
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(archiveFilePath)
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile
Expand All @@ -279,7 +279,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
return archiveFilePath, nil
}

func ExecRecipe(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
if err != nil {
return nil, utils.WrapError(err)
Expand All @@ -300,14 +300,14 @@ func ExecRecipe(properties map[string]string, recipe string, removeUnsetProperti
return bytes, utils.WrapError(err)
}

func PrepareCommandForRecipe(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
pattern := properties[recipe]
if pattern == constants.EMPTY_STRING {
return nil, utils.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe)
}

var err error
commandLine := props.ExpandPropsInString(properties, pattern)
commandLine := properties.ExpandPropsInString(pattern)
if removeUnsetProperties {
commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine)
if err != nil {
Expand All @@ -327,7 +327,7 @@ func PrepareCommandForRecipe(properties map[string]string, recipe string, remove
return command, nil
}

func ExecRecipeCollectStdErr(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
func ExecRecipeCollectStdErr(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
if err != nil {
return "", utils.WrapError(err)
Expand All @@ -339,6 +339,6 @@ func ExecRecipeCollectStdErr(properties map[string]string, recipe string, remove
return string(buffer.Bytes()), nil
}

func RemoveHyphenMDDFlagFromGCCCommandLine(properties map[string]string) {
func RemoveHyphenMDDFlagFromGCCCommandLine(properties props.PropertiesMap) {
properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS] = strings.Replace(properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS], "-MMD", "", -1)
}
7 changes: 4 additions & 3 deletions src/arduino.cc/builder/coan_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func (s *CoanRunner) Run(context map[string]interface{}) error {
return utils.WrapError(err)
}

buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.COAN))
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
properties := buildProperties.Clone()
properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN))
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName

pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
Expand All @@ -70,7 +71,7 @@ func (s *CoanRunner) Run(context map[string]interface{}) error {
}

logger := context[constants.CTX_LOGGER].(i18n.Logger)
commandLine := props.ExpandPropsInString(properties, pattern)
commandLine := properties.ExpandPropsInString(pattern)
command, err := utils.PrepareCommandFilteredArgs(commandLine, filterAllowedArg, logger)

if verbose {
Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/collect_ctags_from_sketch_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
sketchFileNames := collectSketchFileNamesFrom(sketch)

ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
allCtags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
ctagsOfSketch := []*types.CTag{}
for _, ctag := range ctags {
for _, ctag := range allCtags {
if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) {
ctagsOfSketch = append(ctagsOfSketch, ctag)
}
Expand Down
7 changes: 4 additions & 3 deletions src/arduino.cc/builder/container_add_prototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package builder

import (
"arduino.cc/builder/constants"
"arduino.cc/builder/ctags"
"arduino.cc/builder/types"
"arduino.cc/builder/utils"
)
Expand All @@ -42,10 +43,10 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error {
&GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
&ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE},
&CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
&CTagsRunner{},
&CTagsParser{},
&ctags.CTagsRunner{},
&ctags.CTagsParser{},
&CollectCTagsFromSketchFiles{},
&CTagsToPrototypes{},
&ctags.CTagsToPrototypes{},
&PrototypesAdder{},
&SketchSaver{},
}
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
foldersWithSources.Push(types.SourceFolder{Folder: context[constants.CTX_SKETCH_BUILD_PATH].(string), Recurse: true})
if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
for _, library := range context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) {
sourceFolders := utils.LibraryToSourceFolder(library)
sourceFolders := types.LibraryToSourceFolder(library)
for _, sourceFolder := range sourceFolders {
foldersWithSources.Push(sourceFolder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*/

package builder
package ctags

import (
"arduino.cc/builder/constants"
Expand Down Expand Up @@ -67,7 +67,6 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {

skipTagsWhere(tags, tagIsUnknown, context)
skipTagsWhere(tags, tagIsUnhandled, context)
skipTagsWhere(tags, signatureContainsDefaultArg, context)
addPrototypes(tags)
removeDefinedProtypes(tags, context)
removeDuplicate(tags)
Expand All @@ -87,7 +86,7 @@ func addPrototypes(tags []*types.CTag) {
}

func addPrototype(tag *types.CTag) {
if strings.Index(tag.Returntype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
if strings.Index(tag.Prototype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
code := tag.Code
if strings.Contains(code, "{") {
code = code[:strings.Index(code, "{")]
Expand All @@ -98,8 +97,6 @@ func addPrototype(tag *types.CTag) {
return
}

tag.Prototype = tag.Returntype + " " + tag.FunctionName + tag.Signature + ";"

tag.PrototypeModifiers = ""
if strings.Index(tag.Code, STATIC+" ") != -1 {
tag.PrototypeModifiers = tag.PrototypeModifiers + " " + STATIC
Expand Down Expand Up @@ -151,10 +148,6 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
}
}

func signatureContainsDefaultArg(tag *types.CTag) bool {
return strings.Contains(tag.Signature, "=")
}

func prototypeAndCodeDontMatch(tag *types.CTag) bool {
if tag.SkipMe {
return true
Expand Down Expand Up @@ -207,6 +200,8 @@ func parseTag(row string) *types.CTag {

parts = parts[2:]

signature := ""
returntype := ""
for _, part := range parts {
if strings.Contains(part, ":") {
colon := strings.Index(part, ":")
Expand All @@ -222,9 +217,9 @@ func parseTag(row string) *types.CTag {
case "typeref":
tag.Typeref = value
case "signature":
tag.Signature = value
signature = value
case "returntype":
tag.Returntype = value
returntype = value
case "class":
tag.Class = value
case "struct":
Expand All @@ -234,6 +229,7 @@ func parseTag(row string) *types.CTag {
}
}
}
tag.Prototype = returntype + " " + tag.FunctionName + signature + ";"

if strings.Contains(row, "/^") && strings.Contains(row, "$/;") {
tag.Code = row[strings.Index(row, "/^")+2 : strings.Index(row, "$/;")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*/

package builder
package ctags

import (
"arduino.cc/builder/constants"
Expand All @@ -40,19 +40,20 @@ import (
type CTagsRunner struct{}

func (s *CTagsRunner) Run(context map[string]interface{}) error {
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string)
logger := context[constants.CTX_LOGGER].(i18n.Logger)

properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.CTAGS))
properties := buildProperties.Clone()
properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS))
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = ctagsTargetFilePath

pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
if pattern == constants.EMPTY_STRING {
return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.CTAGS)
}

commandLine := props.ExpandPropsInString(properties, pattern)
commandLine := properties.ExpandPropsInString(pattern)
command, err := utils.PrepareCommand(commandLine, logger)
if err != nil {
return utils.WrapError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*/

package builder
package ctags

import (
"arduino.cc/builder/constants"
Expand Down Expand Up @@ -108,6 +108,9 @@ func firstFunctionAtLine(tags []*types.CTag) int {
func toPrototypes(tags []*types.CTag) []*types.Prototype {
prototypes := []*types.Prototype{}
for _, tag := range tags {
if strings.TrimSpace(tag.Prototype) == "" {
continue
}
if !tag.SkipMe {
prototype := &types.Prototype{
FunctionName: tag.FunctionName,
Expand Down
3 changes: 2 additions & 1 deletion src/arduino.cc/builder/dump_build_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package builder

import (
"arduino.cc/builder/constants"
"arduino.cc/builder/props"
"arduino.cc/builder/utils"
"fmt"
"sort"
Expand All @@ -39,7 +40,7 @@ import (
type DumpBuildProperties struct{}

func (s *DumpBuildProperties) Run(context map[string]interface{}) error {
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)

keys := utils.KeysOfMapOfString(buildProperties)
sort.Strings(keys)
Expand Down
9 changes: 6 additions & 3 deletions src/arduino.cc/builder/gcc_preproc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"arduino.cc/builder/builder_utils"
"arduino.cc/builder/constants"
"arduino.cc/builder/i18n"
"arduino.cc/builder/props"
"arduino.cc/builder/types"
"arduino.cc/builder/utils"
"path/filepath"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac
return nil
}

func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (map[string]string, string, error) {
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) {
if targetFilePath != utils.NULLFile() {
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
err := utils.EnsureFolderExists(preprocPath)
Expand All @@ -96,8 +97,10 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFil
targetFilePath = filepath.Join(preprocPath, targetFilePath)
}

buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
properties := make(props.PropertiesMap)
if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok {
properties = p.(props.PropertiesMap).Clone()
}

properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath
properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath
Expand Down
Loading