Skip to content

[skip changelog] Use appropriate name for field that stores library folder name #1900

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 1 commit into from
Oct 4, 2022
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 arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Library struct {
Types []string `json:"types,omitempty"`

InstallDir *paths.Path
CanonicalName string
DirName string
SourceDir *paths.Path
UtilityDir *paths.Path
Location LibraryLocation
Expand Down
14 changes: 7 additions & 7 deletions arduino/libraries/librariesresolver/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func computePriority(lib *libraries.Library, header, arch string) int {
header = strings.TrimSuffix(header, filepath.Ext(header))
header = simplify(header)
name := simplify(lib.Name)
canonicalName := simplify(lib.CanonicalName)
dirName := simplify(lib.DirName)

priority := 0

Expand All @@ -185,17 +185,17 @@ func computePriority(lib *libraries.Library, header, arch string) int {
priority += 0
}

if name == header && canonicalName == header {
if name == header && dirName == header {
priority += 600
} else if name == header || canonicalName == header {
} else if name == header || dirName == header {
priority += 500
} else if name == header+"-master" || canonicalName == header+"-master" {
} else if name == header+"-master" || dirName == header+"-master" {
priority += 400
} else if strings.HasPrefix(name, header) || strings.HasPrefix(canonicalName, header) {
} else if strings.HasPrefix(name, header) || strings.HasPrefix(dirName, header) {
priority += 300
} else if strings.HasSuffix(name, header) || strings.HasSuffix(canonicalName, header) {
} else if strings.HasSuffix(name, header) || strings.HasSuffix(dirName, header) {
priority += 200
} else if strings.Contains(name, header) || strings.Contains(canonicalName, header) {
} else if strings.Contains(name, header) || strings.Contains(dirName, header) {
priority += 100
}

Expand Down
12 changes: 6 additions & 6 deletions arduino/libraries/librariesresolver/cpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func TestCppHeaderResolver(t *testing.T) {
func TestCppHeaderResolverWithLibrariesInStrangeDirectoryNames(t *testing.T) {
resolver := NewCppResolver()
librarylist := libraries.List{}
librarylist.Add(&libraries.Library{CanonicalName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"*"}})
librarylist.Add(&libraries.Library{CanonicalName: "onewireng_2_3_4", Name: "OneWireNg", Architectures: []string{"avr"}})
librarylist.Add(&libraries.Library{DirName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"*"}})
librarylist.Add(&libraries.Library{DirName: "onewireng_2_3_4", Name: "OneWireNg", Architectures: []string{"avr"}})
resolver.headers["OneWire.h"] = librarylist
require.Equal(t, "onewire_2_3_4", resolver.ResolveFor("OneWire.h", "avr").CanonicalName)
require.Equal(t, "onewire_2_3_4", resolver.ResolveFor("OneWire.h", "avr").DirName)

librarylist2 := libraries.List{}
librarylist2.Add(&libraries.Library{CanonicalName: "OneWire", Name: "OneWire", Architectures: []string{"*"}})
librarylist2.Add(&libraries.Library{CanonicalName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"avr"}})
librarylist2.Add(&libraries.Library{DirName: "OneWire", Name: "OneWire", Architectures: []string{"*"}})
librarylist2.Add(&libraries.Library{DirName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"avr"}})
resolver.headers["OneWire.h"] = librarylist2
require.Equal(t, "OneWire", resolver.ResolveFor("OneWire.h", "avr").CanonicalName)
require.Equal(t, "OneWire", resolver.ResolveFor("OneWire.h", "avr").DirName)
}
4 changes: 2 additions & 2 deletions arduino/libraries/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
if err := addExamples(library); err != nil {
return nil, errors.Errorf(tr("scanning examples: %s"), err)
}
library.CanonicalName = libraryDir.Base()
library.DirName = libraryDir.Base()
library.Name = strings.TrimSpace(libProperties.Get("name"))
library.Author = strings.TrimSpace(libProperties.Get("author"))
library.Maintainer = strings.TrimSpace(libProperties.Get("maintainer"))
Expand All @@ -132,7 +132,7 @@ func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, er
SourceDir: path,
Layout: FlatLayout,
Name: path.Base(),
CanonicalName: path.Base(),
DirName: path.Base(),
Architectures: []string{"*"},
IsLegacy: true,
Version: semver.MustParse(""),
Expand Down
10 changes: 5 additions & 5 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Here you can find a list of migration guides to handle breaking changes between
In the structure `github.com/arduino/arduino-cli/arduino/libraries.Library` the field:

- `RealName` has been renamed to `Name`
- `Name` has been renamed to `CanonicalName`
- `Name` has been renamed to `DirName`

Now `Name` is the name of the library as it appears in the `library.properties` file and `CanonicalName` it's the name
of the directory containing the library. The `CanonicalName` is usually the name of the library with non-alphanumeric
characters converted to underscore, but it could be actually anything since the directory where the library is installed
can be freely renamed.
Now `Name` is the name of the library as it appears in the `library.properties` file and `DirName` it's the name of the
directory containing the library. The `DirName` is usually the name of the library with non-alphanumeric characters
converted to underscore, but it could be actually anything since the directory where the library is installed can be
freely renamed.

This change improves the overall code base naming coherence since all the structures involving libraries have the `Name`
field that refers to the library name as it appears in the `library.properties` file.
Expand Down
2 changes: 1 addition & 1 deletion internal/integrationtest/lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestLibUpgradeCommand(t *testing.T) {
requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion)
}

func TestLibCommandsUsingNameInsteadOfCanonicalName(t *testing.T) {
func TestLibCommandsUsingNameInsteadOfDirName(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/create_cmake_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
dynamicLibsFromPkgConfig := map[string]bool{}
for _, library := range ctx.ImportedLibraries {
// Copy used libraries in the correct folder
libDir := libBaseFolder.Join(library.CanonicalName)
libDir := libBaseFolder.Join(library.DirName)
mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU)
utils.CopyDir(library.InstallDir.String(), libDir.String(), validExportExtensions)

Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
if ctx.Verbose {
ctx.Info(tr(`Compiling library "%[1]s"`, library.Name))
}
libraryBuildPath := buildPath.Join(library.CanonicalName)
libraryBuildPath := buildPath.Join(library.DirName)

if err := libraryBuildPath.MkdirAll(); err != nil {
return nil, errors.WithStack(err)
Expand Down Expand Up @@ -189,7 +189,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
return nil, errors.WithStack(err)
}
if library.DotALinkage {
archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, libraryBuildPath, paths.New(library.CanonicalName+".a"), libObjectFiles, buildProperties)
archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, libraryBuildPath, paths.New(library.DirName+".a"), libObjectFiles, buildProperties)
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func buildRoot(ctx *Context, origin interface{}) *paths.Path {
case *sketch.Sketch:
return ctx.SketchBuildPath
case *libraries.Library:
return ctx.LibrariesBuildPath.Join(o.CanonicalName)
return ctx.LibrariesBuildPath.Join(o.DirName)
default:
panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
}
Expand Down