Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
c8ae01ab
Commit
c8ae01ab
authored
Jul 16, 2018
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added LibraryLocation field to Libraries
parent
b8b3b790
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
175 additions
and
43 deletions
+175
-43
Gopkg.lock
Gopkg.lock
+1
-1
arduino/libraries/libraries.go
arduino/libraries/libraries.go
+1
-0
arduino/libraries/libraries_location.go
arduino/libraries/libraries_location.go
+98
-0
arduino/libraries/librariesmanager/librariesmanager.go
arduino/libraries/librariesmanager/librariesmanager.go
+38
-3
arduino/libraries/loader.go
arduino/libraries/loader.go
+10
-8
commands/lib/lib.go
commands/lib/lib.go
+9
-0
commands/lib/list.go
commands/lib/list.go
+1
-9
vendor/github.com/arduino/arduino-builder/libraries_loader.go
...or/github.com/arduino/arduino-builder/libraries_loader.go
+12
-16
vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go
...b.com/arduino/arduino-builder/phases/libraries_builder.go
+5
-5
vendor/github.com/arduino/arduino-builder/types/context.go
vendor/github.com/arduino/arduino-builder/types/context.go
+0
-1
No files found.
Gopkg.lock
View file @
c8ae01ab
...
...
@@ -15,7 +15,7 @@
"types",
"utils"
]
revision = "
fd8b7dcea92845ba26eb0252aae29ccaef635a4
e"
revision = "
4722d661a3ceb9adff5f9a26ea558d6c110ace6
e"
source = "github.com/bcmi-labs/arduino-builder"
[[projects]]
...
...
arduino/libraries/libraries.go
View file @
c8ae01ab
...
...
@@ -64,6 +64,7 @@ type Library struct {
Folder
*
paths
.
Path
SrcFolder
*
paths
.
Path
UtilityFolder
*
paths
.
Path
Location
LibraryLocation
Layout
LibraryLayout
RealName
string
DotALinkage
bool
...
...
arduino/libraries/libraries_location.go
0 → 100644
View file @
c8ae01ab
/*
* This file is part of arduino-cli.
*
* Copyright 2018 ARDUINO AG (http://www.arduino.cc/)
*
* arduino-cli 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.
*/
package
libraries
import
(
"encoding/json"
"fmt"
)
// LibraryLocation represents where the library is installed
type
LibraryLocation
int
// The enumeration is listed in ascending order of priority
const
(
// IDEBuiltIn are libraries bundled in the IDE
IDEBuiltIn
=
1
<<
iota
// PlatformBuiltIn are libraries bundled in a PlatformRelease
PlatformBuiltIn
// ReferencedPlatformBuiltIn are libraries bundled in a PlatformRelease referenced for build
ReferencedPlatformBuiltIn
// Sketchbook are user installed libraries
Sketchbook
)
func
(
d
*
LibraryLocation
)
String
()
string
{
switch
*
d
{
case
IDEBuiltIn
:
return
"ide"
case
PlatformBuiltIn
:
return
"platform"
case
ReferencedPlatformBuiltIn
:
return
"ref-platform"
case
Sketchbook
:
return
"sketchbook"
}
panic
(
fmt
.
Sprintf
(
"invalid LibraryLocation value %d"
,
*
d
))
}
// MarshalJSON implements the json.Marshaler interface
func
(
d
*
LibraryLocation
)
MarshalJSON
()
([]
byte
,
error
)
{
switch
*
d
{
case
IDEBuiltIn
:
return
json
.
Marshal
(
"ide"
)
case
PlatformBuiltIn
:
return
json
.
Marshal
(
"platform"
)
case
ReferencedPlatformBuiltIn
:
return
json
.
Marshal
(
"ref-platform"
)
case
Sketchbook
:
return
json
.
Marshal
(
"sketchbook"
)
}
return
nil
,
fmt
.
Errorf
(
"invalid library location value: %d"
,
*
d
)
}
// UnmarshalJSON implements the json.Unmarshaler interface
func
(
d
*
LibraryLocation
)
UnmarshalJSON
(
b
[]
byte
)
error
{
var
s
string
if
err
:=
json
.
Unmarshal
(
b
,
&
s
);
err
!=
nil
{
return
err
}
switch
s
{
case
"ide"
:
*
d
=
IDEBuiltIn
case
"platform"
:
*
d
=
PlatformBuiltIn
case
"ref-platform"
:
*
d
=
ReferencedPlatformBuiltIn
case
"sketchbook"
:
*
d
=
Sketchbook
}
return
fmt
.
Errorf
(
"invalid library location: %s"
,
s
)
}
arduino/libraries/librariesmanager/librariesmanager.go
View file @
c8ae01ab
...
...
@@ -44,6 +44,14 @@ import (
type
LibrariesManager
struct
{
Libraries
map
[
string
]
*
LibraryAlternatives
`json:"libraries"`
Index
*
librariesindex
.
Index
librariesDir
[]
*
LibrariesDir
}
// LibrariesDir is a directory containing libraries
type
LibrariesDir
struct
{
Path
*
paths
.
Path
Location
libraries
.
LibraryLocation
}
// LibraryAlternatives is a list of different versions of the same library
...
...
@@ -93,17 +101,44 @@ func (sc *LibrariesManager) LoadIndex() error {
return
err
}
// AddLibrariesDir adds allPaths to the list of directories
// to scan when searching for libraries. If a path is already
// in the list it is ignored.
func
(
sc
*
LibrariesManager
)
AddLibrariesDir
(
location
libraries
.
LibraryLocation
,
allPaths
...*
paths
.
Path
)
{
for
_
,
path
:=
range
allPaths
{
for
_
,
dir
:=
range
sc
.
librariesDir
{
if
dir
.
Path
.
EquivalentTo
(
path
)
{
return
}
}
sc
.
librariesDir
=
append
(
sc
.
librariesDir
,
&
LibrariesDir
{
Path
:
path
,
Location
:
location
,
})
}
}
// RescanLibraries reload all installed libraries in the system.
func
(
sc
*
LibrariesManager
)
RescanLibraries
()
error
{
for
_
,
dir
:=
range
sc
.
librariesDir
{
if
err
:=
sc
.
LoadLibrariesFromDir
(
dir
);
err
!=
nil
{
return
fmt
.
Errorf
(
"loading libs from %s: %s"
,
dir
.
Path
,
err
)
}
}
return
nil
}
// LoadLibrariesFromDir loads all libraries in the given folder
func
(
sc
*
LibrariesManager
)
LoadLibrariesFromDir
(
librariesDir
*
LibrariesDir
)
error
{
subFolders
,
err
:=
librariesDir
.
ReadDir
()
subFolders
,
err
:=
librariesDir
.
Path
.
ReadDir
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"reading dir %s: %s"
,
librariesDir
,
err
)
return
fmt
.
Errorf
(
"reading dir %s: %s"
,
librariesDir
.
Path
,
err
)
}
subFolders
.
FilterDirs
()
subFolders
.
FilterOutHiddenFiles
()
for
_
,
subFolder
:=
range
subFolders
{
library
,
err
:=
libraries
.
Load
(
subFolder
)
library
,
err
:=
libraries
.
Load
(
subFolder
,
librariesDir
.
Location
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"loading library from %s: %s"
,
subFolder
,
err
)
}
...
...
arduino/libraries/loader.go
View file @
c8ae01ab
...
...
@@ -38,11 +38,11 @@ import (
)
// Load loads a library from the given folder
func
Load
(
libDir
*
paths
.
Path
)
(
*
Library
,
error
)
{
func
Load
(
libDir
*
paths
.
Path
,
location
LibraryLocation
)
(
*
Library
,
error
)
{
if
exist
,
_
:=
libDir
.
Join
(
"library.properties"
)
.
Exist
();
exist
{
return
makeNewLibrary
(
libDir
)
return
makeNewLibrary
(
libDir
,
location
)
}
return
makeLegacyLibrary
(
libDir
)
return
makeLegacyLibrary
(
libDir
,
location
)
}
func
addUtilityFolder
(
library
*
Library
)
{
...
...
@@ -52,7 +52,7 @@ func addUtilityFolder(library *Library) {
}
}
func
makeNewLibrary
(
libraryFolder
*
paths
.
Path
)
(
*
Library
,
error
)
{
func
makeNewLibrary
(
libraryFolder
*
paths
.
Path
,
location
LibraryLocation
)
(
*
Library
,
error
)
{
libProperties
,
err
:=
properties
.
Load
(
libraryFolder
.
Join
(
"library.properties"
)
.
String
())
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"loading library.properties: %s"
,
err
)
...
...
@@ -69,6 +69,7 @@ func makeNewLibrary(libraryFolder *paths.Path) (*Library, error) {
}
library
:=
&
Library
{}
library
.
Location
=
location
library
.
Folder
=
libraryFolder
if
exist
,
_
:=
libraryFolder
.
Join
(
"src"
)
.
Exist
();
exist
{
library
.
Layout
=
RecursiveLayout
...
...
@@ -115,12 +116,13 @@ func makeNewLibrary(libraryFolder *paths.Path) (*Library, error) {
return
library
,
nil
}
func
makeLegacyLibrary
(
libraryFolder
*
paths
.
Path
)
(
*
Library
,
error
)
{
func
makeLegacyLibrary
(
path
*
paths
.
Path
,
location
LibraryLocation
)
(
*
Library
,
error
)
{
library
:=
&
Library
{
Folder
:
libraryFolder
,
SrcFolder
:
libraryFolder
,
Folder
:
path
,
Location
:
location
,
SrcFolder
:
path
,
Layout
:
FlatLayout
,
Name
:
libraryFolder
.
Base
(),
Name
:
path
.
Base
(),
Architectures
:
[]
string
{
"*"
},
IsLegacy
:
true
,
}
...
...
commands/lib/lib.go
View file @
c8ae01ab
...
...
@@ -33,9 +33,12 @@ import (
"os"
"strings"
paths
"github.com/arduino/go-paths-helper"
"github.com/bcmi-labs/arduino-cli/commands"
"github.com/bcmi-labs/arduino-cli/common/formatter"
"github.com/bcmi-labs/arduino-cli/configs"
"github.com/bcmi-labs/arduino-cli/arduino/libraries"
"github.com/bcmi-labs/arduino-cli/arduino/libraries/librariesmanager"
"github.com/bcmi-labs/arduino-cli/common/formatter/output"
"github.com/sirupsen/logrus"
...
...
@@ -79,6 +82,12 @@ func resultFromFileName(file os.FileInfo, libs *output.LibProcessResults) {
func
getLibraryManager
()
*
librariesmanager
.
LibrariesManager
{
logrus
.
Info
(
"Starting libraries manager"
)
lm
:=
librariesmanager
.
NewLibraryManager
()
if
libHome
,
err
:=
configs
.
LibrariesFolder
.
Get
();
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Cannot get libraries folder."
)
os
.
Exit
(
commands
.
ErrCoreConfig
)
}
else
{
lm
.
AddLibrariesDir
(
libraries
.
Sketchbook
,
paths
.
New
(
libHome
))
}
if
err
:=
lm
.
LoadIndex
();
err
!=
nil
{
logrus
.
WithError
(
err
)
.
Warn
(
"Error during libraries index loading, try to download it again"
)
updateIndex
()
...
...
commands/lib/list.go
View file @
c8ae01ab
...
...
@@ -32,11 +32,9 @@ package lib
import
(
"os"
paths
"github.com/arduino/go-paths-helper"
"github.com/bcmi-labs/arduino-cli/commands"
"github.com/bcmi-labs/arduino-cli/common/formatter"
"github.com/bcmi-labs/arduino-cli/common/formatter/output"
"github.com/bcmi-labs/arduino-cli/configs"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
...
...
@@ -57,14 +55,8 @@ func initListCommand() *cobra.Command {
}
func
runListCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
libHome
,
err
:=
configs
.
LibrariesFolder
.
Get
()
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Cannot get libraries folder."
)
os
.
Exit
(
commands
.
ErrCoreConfig
)
}
lm
:=
getLibraryManager
()
if
err
:=
lm
.
LoadLibrariesFromDir
(
paths
.
New
(
libHome
)
);
err
!=
nil
{
if
err
:=
lm
.
RescanLibraries
(
);
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error loading libraries."
)
os
.
Exit
(
commands
.
ErrCoreConfig
)
}
...
...
vendor/github.com/arduino/arduino-builder/libraries_loader.go
View file @
c8ae01ab
...
...
@@ -42,41 +42,39 @@ import (
type
LibrariesLoader
struct
{}
func
(
s
*
LibrariesLoader
)
Run
(
ctx
*
types
.
Context
)
error
{
lm
:=
librariesmanager
.
NewLibraryManager
()
ctx
.
LibrariesManager
=
lm
builtInLibrariesFolders
:=
ctx
.
BuiltInLibrariesFolders
if
err
:=
builtInLibrariesFolders
.
ToAbs
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
sortedLibrariesFolders
:=
builtInLibrariesFolders
.
Clone
(
)
lm
.
AddLibrariesDir
(
libraries
.
IDEBuiltIn
,
builtInLibrariesFolders
...
)
actualPlatform
:=
ctx
.
ActualPlatform
platform
:=
ctx
.
TargetPlatform
debugLevel
:=
ctx
.
DebugLevel
logger
:=
ctx
.
GetLogger
()
actualPlatform
:=
ctx
.
ActualPlatform
platform
:=
ctx
.
TargetPlatform
if
actualPlatform
!=
platform
{
if
dir
:=
actualPlatform
.
GetLibrariesDir
();
dir
!=
nil
{
sortedLibrariesFolders
.
Add
(
dir
)
lm
.
AddLibrariesDir
(
libraries
.
ReferencedPlatformBuiltIn
,
dir
)
}
}
if
dir
:=
platform
.
GetLibrariesDir
();
dir
!=
nil
{
sortedLibrariesFolders
.
Add
(
dir
)
lm
.
AddLibrariesDir
(
libraries
.
PlatformBuiltIn
,
dir
)
}
librariesFolders
:=
ctx
.
OtherLibrariesFolders
if
err
:=
librariesFolders
.
ToAbs
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
sortedLibrariesFolders
.
AddAllMissing
(
librariesFolders
)
lm
.
AddLibrariesDir
(
libraries
.
Sketchbook
,
librariesFolders
...
)
ctx
.
LibrariesFolders
=
sortedLibrariesFolders
lm
:=
librariesmanager
.
NewLibraryManager
()
for
_
,
libraryFolder
:=
range
sortedLibrariesFolders
{
if
err
:=
lm
.
LoadLibrariesFromDir
(
libraryFolder
);
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
if
err
:=
lm
.
RescanLibraries
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
if
debugLevel
>
0
{
for
_
,
lib
:=
range
lm
.
Libraries
{
for
_
,
libAlt
:=
range
lib
.
Alternatives
{
...
...
@@ -91,8 +89,6 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
}
}
ctx
.
LibrariesManager
=
lm
headerToLibraries
:=
make
(
map
[
string
][]
*
libraries
.
Library
)
for
_
,
lib
:=
range
lm
.
Libraries
{
for
_
,
library
:=
range
lib
.
Alternatives
{
...
...
vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go
View file @
c8ae01ab
...
...
@@ -52,13 +52,13 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
librariesBuildPath
:=
ctx
.
LibrariesBuildPath
buildProperties
:=
ctx
.
BuildProperties
includes
:=
utils
.
Map
(
ctx
.
IncludeFolders
.
AsStrings
(),
utils
.
WrapWithHyphenI
)
lib
rarie
s
:=
ctx
.
ImportedLibraries
libs
:=
ctx
.
ImportedLibraries
if
err
:=
librariesBuildPath
.
MkdirAll
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
objectFiles
,
err
:=
compileLibraries
(
ctx
,
lib
rarie
s
,
librariesBuildPath
,
buildProperties
,
includes
)
objectFiles
,
err
:=
compileLibraries
(
ctx
,
libs
,
librariesBuildPath
,
buildProperties
,
includes
)
if
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
}
...
...
@@ -66,14 +66,14 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
ctx
.
LibrariesObjectFiles
=
objectFiles
// Search for precompiled libraries
fixLDFLAGforPrecompiledLibraries
(
ctx
,
lib
rarie
s
)
fixLDFLAGforPrecompiledLibraries
(
ctx
,
libs
)
return
nil
}
func
fixLDFLAGforPrecompiledLibraries
(
ctx
*
types
.
Context
,
lib
rarie
s
[]
*
libraries
.
Library
)
error
{
func
fixLDFLAGforPrecompiledLibraries
(
ctx
*
types
.
Context
,
libs
[]
*
libraries
.
Library
)
error
{
for
_
,
library
:=
range
lib
rarie
s
{
for
_
,
library
:=
range
libs
{
if
library
.
Precompiled
{
// add library src path to compiler.c.elf.extra_flags
// use library.Name as lib name and srcPath/{mcpu} as location
...
...
vendor/github.com/arduino/arduino-builder/types/context.go
View file @
c8ae01ab
...
...
@@ -25,7 +25,6 @@ type Context struct {
HardwareFolders
paths
.
PathList
ToolsFolders
paths
.
PathList
BuiltInToolsFolders
paths
.
PathList
LibrariesFolders
paths
.
PathList
BuiltInLibrariesFolders
paths
.
PathList
OtherLibrariesFolders
paths
.
PathList
SketchLocation
*
paths
.
Path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment