Skip to content

Commit c347f64

Browse files
author
Federico Fissore
committed
Moved some library consistency checks into FailIfImportedLibraryIsWrong, which
loops on imported libs only (not on all libs). Fixes #62 Signed-off-by: Federico Fissore <[email protected]>
1 parent 487837d commit c347f64

File tree

8 files changed

+87
-14
lines changed

8 files changed

+87
-14
lines changed

src/arduino.cc/builder/container_find_includes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
8282
}
8383
}
8484

85+
err = runCommand(context, &FailIfImportedLibraryIsWrong{})
86+
if err != nil {
87+
return utils.WrapError(err)
88+
}
89+
8590
return nil
8691
}
8792

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
"path/filepath"
39+
)
40+
41+
type FailIfImportedLibraryIsWrong struct{}
42+
43+
func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}) error {
44+
if !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
45+
return nil
46+
}
47+
48+
logger := context[constants.CTX_LOGGER].(i18n.Logger)
49+
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
50+
51+
for _, library := range importedLibraries {
52+
if !library.IsLegacy {
53+
if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() {
54+
return utils.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED)
55+
}
56+
for _, propName := range LIBRARY_MANDATORY_PROPERTIES {
57+
if _, ok := library.Properties[propName]; !ok {
58+
return utils.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, library.Folder)
59+
}
60+
}
61+
if library.Layout == types.LIBRARY_RECURSIVE {
62+
if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_UTILITY)); err == nil && stat.IsDir() {
63+
return utils.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, library.Folder)
64+
}
65+
}
66+
}
67+
}
68+
69+
return nil
70+
}

src/arduino.cc/builder/libraries_loader.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
129129
properties[constants.LIBRARY_MAINTAINER] = properties[constants.LIBRARY_EMAIL]
130130
}
131131

132-
if stat, err := os.Stat(filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() {
133-
return nil, utils.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED)
134-
}
135-
136-
for _, propName := range LIBRARY_MANDATORY_PROPERTIES {
137-
if _, ok := properties[propName]; !ok {
138-
return nil, utils.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, libraryFolder)
139-
}
140-
}
141132
for _, propName := range LIBRARY_NOT_SO_MANDATORY_PROPERTIES {
142133
if properties[propName] == constants.EMPTY_STRING {
143134
properties[propName] = "-"
@@ -148,9 +139,6 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
148139
if stat, err := os.Stat(filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_SRC)); err == nil && stat.IsDir() {
149140
library.Layout = types.LIBRARY_RECURSIVE
150141
library.SrcFolder = filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_SRC)
151-
if stat, err := os.Stat(filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_UTILITY)); err == nil && stat.IsDir() {
152-
return nil, utils.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, libraryFolder)
153-
}
154142
} else {
155143
library.Layout = types.LIBRARY_FLAT
156144
library.SrcFolder = libraryFolder
@@ -199,6 +187,7 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
199187
library.URL = strings.TrimSpace(properties[constants.LIBRARY_URL])
200188
library.IsLegacy = false
201189
library.DotALinkage = strings.TrimSpace(properties[constants.LIBRARY_DOT_A_LINKAGE]) == "true"
190+
library.Properties = properties
202191

203192
return library, nil
204193
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name=wronglib
2+
version=1.0
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=sentence
6+
paragraph=paragraph
7+
url=url
8+
architectures=*

src/arduino.cc/builder/test/libraries/wronglib/src/.gitkeep

Whitespace-only changes.

src/arduino.cc/builder/test/libraries/wronglib/utility/.gitkeep

Whitespace-only changes.

src/arduino.cc/builder/test/libraries_loader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestLoadLibrariesAVR(t *testing.T) {
6969
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])
7070

7171
libraries := context[constants.CTX_LIBRARIES].([]*types.Library)
72-
require.Equal(t, 17, len(libraries))
72+
require.Equal(t, 18, len(libraries))
7373

7474
sort.Sort(ByLibraryName(libraries))
7575

@@ -175,7 +175,7 @@ func TestLoadLibrariesSAM(t *testing.T) {
175175
require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2])
176176

177177
libraries := context[constants.CTX_LIBRARIES].([]*types.Library)
178-
require.Equal(t, 15, len(libraries))
178+
require.Equal(t, 16, len(libraries))
179179

180180
sort.Sort(ByLibraryName(libraries))
181181

src/arduino.cc/builder/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type Library struct {
112112
URL string
113113
Category string
114114
License string
115+
Properties map[string]string
115116
}
116117

117118
func (library *Library) String() string {

0 commit comments

Comments
 (0)