Skip to content

Commit c3f43f8

Browse files
author
Federico Fissore
committed
Platform rewrite warnings are now emitted only for the actual selected library.
Fixes #57 Signed-off-by: Federico Fissore <[email protected]>
1 parent 5f39723 commit c3f43f8

File tree

5 files changed

+82
-8
lines changed

5 files changed

+82
-8
lines changed

Diff for: src/arduino.cc/builder/add_additional_entries_to_context.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}) erro
8686
context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources
8787

8888
context[constants.CTX_LIBRARY_RESOLUTION_RESULTS] = make(map[string]types.LibraryResolutionResult)
89+
context[constants.CTX_HARDWARE_REWRITE_RESULTS] = make(map[*types.Platform][]types.PlatforKeyRewrite)
8990

9091
return nil
9192
}

Diff for: src/arduino.cc/builder/builder.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func (s *Builder) Run(context map[string]interface{}) error {
7777

7878
&ContainerBuildOptions{},
7979

80+
&WarnAboutPlatformRewrites{},
81+
8082
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
8183

8284
&ContainerMergeCopySketchFiles{},

Diff for: src/arduino.cc/builder/constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource"
9999
const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput"
100100
const CTX_HARDWARE_FOLDERS = "hardwareFolders"
101101
const CTX_HARDWARE = "hardware"
102+
const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults"
102103
const CTX_HEADER_TO_LIBRARIES = "headerToLibraries"
103104
const CTX_IMPORTED_LIBRARIES = "importedLibraries"
104105
const CTX_INCLUDE_FOLDERS = "includeFolders"

Diff for: src/arduino.cc/builder/rewrite_hardware_keys.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34-
"arduino.cc/builder/i18n"
3534
"arduino.cc/builder/types"
3635
"arduino.cc/builder/utils"
37-
"os"
3836
)
3937

4038
type RewriteHardwareKeys struct{}
@@ -46,19 +44,17 @@ func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error {
4644

4745
packages := context[constants.CTX_HARDWARE].(*types.Packages)
4846
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
49-
logger := context[constants.CTX_LOGGER].(i18n.Logger)
50-
51-
warn := utils.DebugLevel(context) > 0
47+
hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite)
5248

5349
for _, aPackage := range packages.Packages {
5450
for _, platform := range aPackage.Platforms {
5551
if platform.Properties[constants.REWRITING] != constants.REWRITING_DISABLED {
5652
for _, rewrite := range platformKeysRewrite.Rewrites {
5753
if platform.Properties[rewrite.Key] != constants.EMPTY_STRING && platform.Properties[rewrite.Key] == rewrite.OldValue {
5854
platform.Properties[rewrite.Key] = rewrite.NewValue
59-
if warn {
60-
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
61-
}
55+
appliedRewrites := rewritesAppliedToPlatform(platform, hardwareRewriteResults)
56+
appliedRewrites = append(appliedRewrites, rewrite)
57+
hardwareRewriteResults[platform] = appliedRewrites
6258
}
6359
}
6460
}
@@ -67,3 +63,10 @@ func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error {
6763

6864
return nil
6965
}
66+
67+
func rewritesAppliedToPlatform(platform *types.Platform, hardwareRewriteResults map[*types.Platform][]types.PlatforKeyRewrite) []types.PlatforKeyRewrite {
68+
if hardwareRewriteResults[platform] == nil {
69+
hardwareRewriteResults[platform] = []types.PlatforKeyRewrite{}
70+
}
71+
return hardwareRewriteResults[platform]
72+
}
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package builder
31+
32+
import (
33+
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/i18n"
35+
"arduino.cc/builder/types"
36+
"arduino.cc/builder/utils"
37+
"os"
38+
)
39+
40+
type WarnAboutPlatformRewrites struct{}
41+
42+
func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}) error {
43+
warn := utils.DebugLevel(context) > 0
44+
if !warn {
45+
return nil
46+
}
47+
48+
logger := context[constants.CTX_LOGGER].(i18n.Logger)
49+
hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite)
50+
targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform)
51+
actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform)
52+
53+
platforms := []*types.Platform{targetPlatform}
54+
if actualPlatform != targetPlatform {
55+
platforms = append(platforms, actualPlatform)
56+
}
57+
58+
for _, platform := range platforms {
59+
if hardwareRewriteResults[platform] != nil {
60+
for _, rewrite := range hardwareRewriteResults[platform] {
61+
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
62+
}
63+
}
64+
}
65+
66+
return nil
67+
}

0 commit comments

Comments
 (0)