Skip to content

Commit e028b70

Browse files
committed
Define supported and valid library examples folder names in the library package
1 parent 290f0a8 commit e028b70

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

project/library/library.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,25 @@ func IsMetadataFile(filePath *paths.Path) bool {
3636
}
3737
return false
3838
}
39+
40+
// See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-examples
41+
var examplesFolderValidNames = map[string]struct{}{
42+
"examples": empty,
43+
}
44+
45+
// Only "examples" is specification-compliant, but apparently "example" is also supported
46+
// See: https://github.com/arduino/arduino-cli/blob/0.13.0/arduino/libraries/loader.go#L153
47+
var examplesFolderSupportedNames = map[string]struct{}{
48+
"examples": empty,
49+
"example": empty,
50+
}
51+
52+
// ExamplesFolderNames returns a slice of supported examples folder names
53+
func ExamplesFolderSupportedNames() []string {
54+
folderNames := make([]string, 0, len(examplesFolderSupportedNames))
55+
for folderName := range examplesFolderSupportedNames {
56+
folderNames = append(folderNames, folderName)
57+
}
58+
59+
return folderNames
60+
}

project/project.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
103103
// Sketches don't have subprojects
104104
return nil
105105
case projecttype.Library:
106-
subprojectPath := superproject.Path.Join("examples")
107-
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, projecttype.Sketch, true)...)
108-
// Apparently there is some level of official support for "example" in addition to the specification-compliant "examples".
109-
// see: https://github.com/arduino/arduino-cli/blob/0.13.0/arduino/libraries/loader.go#L153
110-
subprojectPath = superproject.Path.Join("example")
111-
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, projecttype.Sketch, true)...)
106+
for _, subprojectFolderName := range library.ExamplesFolderSupportedNames() {
107+
subprojectPath := superproject.Path.Join(subprojectFolderName)
108+
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, projecttype.Sketch, true)...)
109+
}
112110
case projecttype.Platform:
113111
subprojectPath := superproject.Path.Join("libraries")
114112
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, projecttype.Library, false)...)

0 commit comments

Comments
 (0)