Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Read additional BuildProperties from optional ./platform.sketch.txt file
  • Loading branch information
phd committed Jul 26, 2018
commit 71ab21d1be0d32d8700d9ca575f10f9b96612c0e
62 changes: 62 additions & 0 deletions add_build_properties_from_platform_sketch_txt_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of Arduino Builder.
*
* Arduino Builder is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2018 Piotr Henryk Dabrowski <phd@phd.re>
*/

package builder

import (
"path/filepath"

"github.com/arduino/arduino-builder/constants"
"github.com/arduino/arduino-builder/i18n"
"github.com/arduino/arduino-builder/types"
"github.com/arduino/arduino-builder/utils"
properties "github.com/arduino/go-properties-map"
)

type AddBuildPropertiesFromPlatformSketchTxtFile struct{}

func (s *AddBuildPropertiesFromPlatformSketchTxtFile) Run(ctx *types.Context) error {
path := filepath.Join(filepath.Dir(ctx.Sketch.MainFile.Name), constants.FILE_PLATFORM_SKETCH_TXT)
if !utils.IsFileReadable(path) {
return nil
}
if ctx.Verbose {
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_SKETCH_BUILD_PROPERTIES, path)
}

newBuildProperties := ctx.BuildProperties.Clone()
sketchPlatformProperties, err := properties.SafeLoad(path)
if err != nil {
return i18n.WrapError(err)
}
newBuildProperties.Merge(sketchPlatformProperties)
ctx.BuildProperties = newBuildProperties

return nil
}
2 changes: 2 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp"
const FILE_GCC_PREPROC_TARGET = "gcc_preproc_target.cpp"
const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt"
const FILE_PLATFORM_LOCAL_TXT = "platform.local.txt"
const FILE_PLATFORM_SKETCH_TXT = "platform.sketch.txt"
const FILE_PLATFORM_TXT = "platform.txt"
const FILE_PROGRAMMERS_TXT = "programmers.txt"
const FILE_INCLUDES_CACHE = "includes.cache"
Expand Down Expand Up @@ -198,6 +199,7 @@ const MSG_USING_BOARD = "Using board '{0}' from platform in folder: {1}"
const MSG_USING_CORE = "Using core '{0}' from platform in folder: {1}"
const MSG_USING_PREVIOUS_COMPILED_FILE = "Using previously compiled file: {0}"
const MSG_USING_CACHED_INCLUDES = "Using cached library dependencies for file: {0}"
const MSG_USING_SKETCH_BUILD_PROPERTIES = "Using sketch build properties from file: {0}"
const MSG_WARNING_LIB_INVALID_CATEGORY = "WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}'"
const MSG_WARNING_PLATFORM_MISSING_VALUE = "Warning: platform.txt from core '{0}' misses property '{1}', using default value '{2}'. Consider upgrading this core."
const MSG_WARNING_PLATFORM_OLD_VALUES = "Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core."
Expand Down
1 change: 1 addition & 0 deletions container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
&LibrariesLoader{},
&SketchLoader{},
&SetupBuildProperties{},
&AddBuildPropertiesFromPlatformSketchTxtFile{},
&LoadVIDPIDSpecificProperties{},
&SetCustomBuildProperties{},
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},
Expand Down
15 changes: 11 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,26 @@ func FindFilesInFolder(files *[]string, folder string, extensions CheckExtension
return nil
}

// See if the file is readable by opening it
currentFile, err := os.Open(path)
if err != nil {
if !IsFileReadable(path) {
return nil
}
currentFile.Close()

*files = append(*files, path)
return nil
}
return gohasissues.Walk(folder, walkFunc)
}

func IsFileReadable(path string) bool {
// See if the file is readable by opening it
file, err := os.Open(path)
if err != nil {
return false
}
file.Close()
return true
}

func GetParentFolder(basefolder string, n int) string {
tempFolder := basefolder
i := 0
Expand Down