From 3337e70afdb263e24bacf18b5d38d5bca1f57c07 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 11 Dec 2020 10:31:09 -0800 Subject: [PATCH] Don't do project discovery when explicitly defined Previously, the project path discovery and type detection were done even when the user's settings explicitely defined these things. When the contents of the given path did not contain something slightly resembling a project of the given type, the process exited. That behavior is the only one possible when a project is not explicitely defined by the user, but in the case of an explicit definition, this is an unnecessary short circuiting of the process. The checks can still be run. This will result in the same exit status as before, but the check results may provide the user with helpful information about why their project is invalid. --- project/project.go | 34 ++++++++++++++++++++++++++++------ project/project_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/project/project.go b/project/project.go index 3f3f5be8a..b93f9a4fa 100644 --- a/project/project.go +++ b/project/project.go @@ -57,8 +57,18 @@ func findProjects(targetPath *paths.Path) ([]Type, error) { // If targetPath is a file, targetPath itself is the project, so it's only necessary to determine/verify the type. if targetPath.IsNotDir() { logrus.Debug("Projects path is file") - // The filename provides additional information about the project type. So rather than using isProject(), which doesn't make use this information, use a specialized function that does. - isProject, projectType := isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter()) + var isProject bool + var projectType projecttype.Type + if configuration.SuperprojectTypeFilter() == projecttype.All { + // Project type detection is required. + // The filename provides additional information about the project type. So rather than using isProject(), which doesn't make use this information, use a specialized function that does. + isProject, projectType = isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter()) + } else { + // Project was explicitly defined by user. + isProject = true + projectType = configuration.SuperprojectTypeFilter() + } + if isProject { var projectPath *paths.Path if projectType == projecttype.PackageIndex { @@ -81,10 +91,22 @@ func findProjects(targetPath *paths.Path) ([]Type, error) { return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath) } - foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive()) - for _, foundParentProject := range foundParentProjects { - foundProjects = append(foundProjects, foundParentProject) - foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...) + if configuration.SuperprojectTypeFilter() == projecttype.All || configuration.Recursive() { + // Project discovery and/or type detection is required. + foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive()) + for _, foundParentProject := range foundParentProjects { + foundProjects = append(foundProjects, foundParentProject) + foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...) + } + } else { + // Project was explicitly defined by user. + foundProjects = append(foundProjects, + Type{ + Path: targetPath, + ProjectType: configuration.SuperprojectTypeFilter(), + SuperprojectType: configuration.SuperprojectTypeFilter(), + }, + ) } if foundProjects == nil { diff --git a/project/project_test.go b/project/project_test.go index eb622e3f6..50d410461 100644 --- a/project/project_test.go +++ b/project/project_test.go @@ -130,6 +130,20 @@ func TestFindProjects(t *testing.T) { }, }, }, + { + "Explicit file", + "sketch", + "", + []string{libraryPath.Join("Library.h").String()}, + assert.NoError, + []Type{ + { + Path: libraryPath, + ProjectType: projecttype.Sketch, + SuperprojectType: projecttype.Sketch, + }, + }, + }, { "Sketch folder", "all", @@ -201,6 +215,20 @@ func TestFindProjects(t *testing.T) { }, }, }, + { + "Explicit folder", + "sketch", + "false", + []string{libraryPath.String()}, + assert.NoError, + []Type{ + { + Path: libraryPath, + ProjectType: projecttype.Sketch, + SuperprojectType: projecttype.Sketch, + }, + }, + }, { "Projects folder, recursive", "all",