Skip to content

Commit 71ab21d

Browse files
committed
Read additional BuildProperties from optional ./platform.sketch.txt file
1 parent 29cf4c8 commit 71ab21d

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2018 Piotr Henryk Dabrowski <[email protected]>
28+
*/
29+
30+
package builder
31+
32+
import (
33+
"path/filepath"
34+
35+
"github.com/arduino/arduino-builder/constants"
36+
"github.com/arduino/arduino-builder/i18n"
37+
"github.com/arduino/arduino-builder/types"
38+
"github.com/arduino/arduino-builder/utils"
39+
properties "github.com/arduino/go-properties-map"
40+
)
41+
42+
type AddBuildPropertiesFromPlatformSketchTxtFile struct{}
43+
44+
func (s *AddBuildPropertiesFromPlatformSketchTxtFile) Run(ctx *types.Context) error {
45+
path := filepath.Join(filepath.Dir(ctx.Sketch.MainFile.Name), constants.FILE_PLATFORM_SKETCH_TXT)
46+
if !utils.IsFileReadable(path) {
47+
return nil
48+
}
49+
if ctx.Verbose {
50+
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_SKETCH_BUILD_PROPERTIES, path)
51+
}
52+
53+
newBuildProperties := ctx.BuildProperties.Clone()
54+
sketchPlatformProperties, err := properties.SafeLoad(path)
55+
if err != nil {
56+
return i18n.WrapError(err)
57+
}
58+
newBuildProperties.Merge(sketchPlatformProperties)
59+
ctx.BuildProperties = newBuildProperties
60+
61+
return nil
62+
}

constants/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp"
8787
const FILE_GCC_PREPROC_TARGET = "gcc_preproc_target.cpp"
8888
const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt"
8989
const FILE_PLATFORM_LOCAL_TXT = "platform.local.txt"
90+
const FILE_PLATFORM_SKETCH_TXT = "platform.sketch.txt"
9091
const FILE_PLATFORM_TXT = "platform.txt"
9192
const FILE_PROGRAMMERS_TXT = "programmers.txt"
9293
const FILE_INCLUDES_CACHE = "includes.cache"
@@ -198,6 +199,7 @@ const MSG_USING_BOARD = "Using board '{0}' from platform in folder: {1}"
198199
const MSG_USING_CORE = "Using core '{0}' from platform in folder: {1}"
199200
const MSG_USING_PREVIOUS_COMPILED_FILE = "Using previously compiled file: {0}"
200201
const MSG_USING_CACHED_INCLUDES = "Using cached library dependencies for file: {0}"
202+
const MSG_USING_SKETCH_BUILD_PROPERTIES = "Using sketch build properties from file: {0}"
201203
const MSG_WARNING_LIB_INVALID_CATEGORY = "WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}'"
202204
const MSG_WARNING_PLATFORM_MISSING_VALUE = "Warning: platform.txt from core '{0}' misses property '{1}', using default value '{2}'. Consider upgrading this core."
203205
const MSG_WARNING_PLATFORM_OLD_VALUES = "Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core."

container_setup.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
5050
&LibrariesLoader{},
5151
&SketchLoader{},
5252
&SetupBuildProperties{},
53+
&AddBuildPropertiesFromPlatformSketchTxtFile{},
5354
&LoadVIDPIDSpecificProperties{},
5455
&SetCustomBuildProperties{},
5556
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},

utils/utils.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,26 @@ func FindFilesInFolder(files *[]string, folder string, extensions CheckExtension
448448
return nil
449449
}
450450

451-
// See if the file is readable by opening it
452-
currentFile, err := os.Open(path)
453-
if err != nil {
451+
if !IsFileReadable(path) {
454452
return nil
455453
}
456-
currentFile.Close()
457454

458455
*files = append(*files, path)
459456
return nil
460457
}
461458
return gohasissues.Walk(folder, walkFunc)
462459
}
463460

461+
func IsFileReadable(path string) bool {
462+
// See if the file is readable by opening it
463+
file, err := os.Open(path)
464+
if err != nil {
465+
return false
466+
}
467+
file.Close()
468+
return true
469+
}
470+
464471
func GetParentFolder(basefolder string, n int) string {
465472
tempFolder := basefolder
466473
i := 0

0 commit comments

Comments
 (0)