Skip to content

Make multiple libraries warning more consistent #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *Builder) Run(ctx *types.Context) error {
mainErr := runCommands(ctx, commands, true)

commands = []types.Command{
&PrintUsedAndNotUsedLibraries{},
&PrintUsedAndNotUsedLibraries{ SketchError: mainErr != nil },

&PrintUsedLibrariesIfVerbose{},
}
Expand Down
16 changes: 1 addition & 15 deletions src/arduino.cc/builder/includes_to_include_folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library

reverse(libraries)

librariesInPlatforms := librariesInSomePlatform(libraries, platforms)

var library *types.Library

for _, platform := range platforms {
Expand All @@ -149,8 +147,7 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library

library = useAlreadyImportedLibraryWithSameNameIfExists(library, markImportedLibrary)

isLibraryFromPlatform := findLibraryIn(librariesInPlatforms, library) != nil
libraryResolutionResults[header] = types.LibraryResolutionResult{Library: library, IsLibraryFromPlatform: isLibraryFromPlatform, NotUsedLibraries: filterOutLibraryFrom(libraries, library)}
libraryResolutionResults[header] = types.LibraryResolutionResult{Library: library, NotUsedLibraries: filterOutLibraryFrom(libraries, library)}

markImportedLibrary[library] = true
}
Expand All @@ -162,17 +159,6 @@ func reverse(data []*types.Library) {
}
}

func librariesInSomePlatform(libraries []*types.Library, platforms []*types.Platform) []*types.Library {
librariesInPlatforms := []*types.Library{}
for _, platform := range platforms {
if platform != nil {
librariesWithinSpecifiedPlatform := librariesWithinPlatform(libraries, platform)
librariesInPlatforms = append(librariesInPlatforms, librariesWithinSpecifiedPlatform...)
}
}
return librariesInPlatforms
}

func markImportedLibraryContainsOneOfCandidates(markImportedLibrary map[*types.Library]bool, libraries []*types.Library) bool {
for markedLibrary, _ := range markImportedLibrary {
for _, library := range libraries {
Expand Down
24 changes: 16 additions & 8 deletions src/arduino.cc/builder/print_used_and_not_used_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,31 @@ import (
"time"
)

type PrintUsedAndNotUsedLibraries struct{}
type PrintUsedAndNotUsedLibraries struct {
// Was there an error while compiling the sketch?
SketchError bool
}

func (s *PrintUsedAndNotUsedLibraries) Run(ctx *types.Context) error {
if ctx.DebugLevel < 0 {
var logLevel string
// Print this message as warning when the sketch didn't compile,
// as info when we're verbose and not all otherwise
if s.SketchError {
logLevel = constants.LOG_LEVEL_WARN
} else if ctx.Verbose {
logLevel = constants.LOG_LEVEL_INFO
} else {
return nil
}

logger := ctx.GetLogger()
libraryResolutionResults := ctx.LibrariesResolutionResults

for header, libResResult := range libraryResolutionResults {
if !libResResult.IsLibraryFromPlatform {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
}
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
}
}

Expand Down
29 changes: 0 additions & 29 deletions src/arduino.cc/builder/test/includes_to_include_folders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func TestIncludesToIncludeFolders(t *testing.T) {
importedLibraries := ctx.ImportedLibraries
require.Equal(t, 1, len(importedLibraries))
require.Equal(t, "Bridge", importedLibraries[0].Name)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.False(t, libraryResolutionResults["Bridge.h"].IsLibraryFromPlatform)
}

func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
Expand Down Expand Up @@ -112,9 +108,6 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {

importedLibraries := ctx.ImportedLibraries
require.Equal(t, 0, len(importedLibraries))

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
}

func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
Expand Down Expand Up @@ -153,11 +146,6 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
require.Equal(t, 2, len(importedLibraries))
require.Equal(t, "Bridge", importedLibraries[0].Name)
require.Equal(t, "IRremote", importedLibraries[1].Name)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.False(t, libraryResolutionResults["Bridge.h"].IsLibraryFromPlatform)
require.False(t, libraryResolutionResults["IRremote.h"].IsLibraryFromPlatform)
}

func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
Expand Down Expand Up @@ -196,11 +184,6 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
require.Equal(t, 2, len(importedLibraries))
require.Equal(t, "ANewLibrary-master", importedLibraries[0].Name)
require.Equal(t, "IRremote", importedLibraries[1].Name)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.False(t, libraryResolutionResults["anewlibrary.h"].IsLibraryFromPlatform)
require.False(t, libraryResolutionResults["IRremote.h"].IsLibraryFromPlatform)
}

func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
Expand Down Expand Up @@ -238,10 +221,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
require.Equal(t, 1, len(importedLibraries))
require.Equal(t, "SPI", importedLibraries[0].Name)
require.Equal(t, Abs(t, filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI")), importedLibraries[0].SrcFolder)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.True(t, libraryResolutionResults["SPI.h"].IsLibraryFromPlatform)
}

func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform(t *testing.T) {
Expand Down Expand Up @@ -280,10 +259,6 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo
require.Equal(t, 1, len(importedLibraries))
require.Equal(t, "SPI", importedLibraries[0].Name)
require.Equal(t, Abs(t, filepath.Join("libraries", "SPI")), importedLibraries[0].SrcFolder)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.False(t, libraryResolutionResults["SPI.h"].IsLibraryFromPlatform)
}

func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
Expand Down Expand Up @@ -322,8 +297,4 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
require.Equal(t, 1, len(importedLibraries))
require.Equal(t, "USBHost", importedLibraries[0].Name)
require.Equal(t, Abs(t, filepath.Join("libraries", "USBHost", "src")), importedLibraries[0].SrcFolder)

libraryResolutionResults := ctx.LibrariesResolutionResults
require.NotNil(t, libraryResolutionResults)
require.False(t, libraryResolutionResults["Usb.h"].IsLibraryFromPlatform)
}
1 change: 0 additions & 1 deletion src/arduino.cc/builder/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ type SourceFolder struct {

type LibraryResolutionResult struct {
Library *Library
IsLibraryFromPlatform bool
NotUsedLibraries []*Library
}

Expand Down