Skip to content

Commit 6dbb5c5

Browse files
committed
Go: Refactor Autobuild to use pairs of scripts and tools from a reusable array
1 parent e2c6734 commit 6dbb5c5

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

go/extractor/autobuilder/autobuilder.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,33 @@ func tryBuild(cmd string, args ...string) bool {
7070
return res && (!CheckExtracted || checkExtractorRun())
7171
}
7272

73-
// Autobuild attempts to detect build system and run the corresponding command.
73+
// If a project is accompanied by a build script (such as a makefile), then we try executing such
74+
// build scripts to build the project. This type represents pairs of script names to check for
75+
// and the names of corresponding build tools to invoke if those scripts exist.
76+
type BuildScript struct {
77+
Tool string // The name of the command to execute if the build script exists
78+
Filename string // The name of the build script to check for
79+
}
80+
81+
// An array of build scripts to check for and corresponding commands that we can execute
82+
// if they exist.
83+
var BuildScripts = []BuildScript{
84+
{Tool: "make", Filename: "Makefile"},
85+
{Tool: "make", Filename: "makefile"},
86+
{Tool: "make", Filename: "GNUmakefile"},
87+
{Tool: "ninja", Filename: "build.ninja"},
88+
{Tool: "./build", Filename: "build"},
89+
{Tool: "./build.sh", Filename: "build.sh"},
90+
}
91+
92+
// Autobuild attempts to detect build systems based on the presence of build scripts from the
93+
// list in `BuildScripts` and run the corresponding command. This may invoke zero or more
94+
// build scripts in the order given by `BuildScripts`.
7495
func Autobuild() bool {
75-
return tryBuildIfExists("Makefile", "make") ||
76-
tryBuildIfExists("makefile", "make") ||
77-
tryBuildIfExists("GNUmakefile", "make") ||
78-
tryBuildIfExists("build.ninja", "ninja") ||
79-
tryBuildIfExists("build", "./build") ||
80-
tryBuildIfExists("build.sh", "./build.sh")
96+
for _, script := range BuildScripts {
97+
if tryBuildIfExists(script.Filename, script.Tool) {
98+
return true
99+
}
100+
}
101+
return false
81102
}

0 commit comments

Comments
 (0)