зеркало из https://github.com/github/codeql.git
Go: Modify `Autobuild` to return an array of scripts that were run
This commit is contained in:
Родитель
bbc359ebde
Коммит
1b9e8ae86f
|
@ -54,13 +54,15 @@ func checkExtractorRun() bool {
|
|||
}
|
||||
|
||||
// tryBuildIfExists tries to run the command `cmd args...` if the file `buildFile` exists and is not
|
||||
// a directory. Returns true if the command was successful and false if not.
|
||||
func tryBuildIfExists(buildFile, cmd string, args ...string) bool {
|
||||
if util.FileExists(buildFile) {
|
||||
// a directory. Returns values indicating whether the script succeeded as well as whether the script was found.
|
||||
func tryBuildIfExists(buildFile, cmd string, args ...string) (scriptSuccess bool, scriptFound bool) {
|
||||
scriptSuccess = false
|
||||
scriptFound = util.FileExists(buildFile)
|
||||
if scriptFound {
|
||||
log.Printf("%s found.\n", buildFile)
|
||||
return tryBuild(cmd, args...)
|
||||
scriptSuccess = tryBuild(cmd, args...)
|
||||
}
|
||||
return false
|
||||
return
|
||||
}
|
||||
|
||||
// tryBuild tries to run `cmd args...`, returning true if successful and false if not.
|
||||
|
@ -92,11 +94,23 @@ var BuildScripts = []BuildScript{
|
|||
// Autobuild attempts to detect build systems based on the presence of build scripts from the
|
||||
// list in `BuildScripts` and run the corresponding command. This may invoke zero or more
|
||||
// build scripts in the order given by `BuildScripts`.
|
||||
func Autobuild() bool {
|
||||
func Autobuild() (scriptSuccess bool, scriptsExecuted []string) {
|
||||
scriptSuccess = false
|
||||
scriptsExecuted = []string{}
|
||||
|
||||
for _, script := range BuildScripts {
|
||||
if tryBuildIfExists(script.Filename, script.Tool) {
|
||||
return true
|
||||
// Try to run the build script
|
||||
success, scriptFound := tryBuildIfExists(script.Filename, script.Tool)
|
||||
|
||||
// If it was found, we attempted to run it: add it to the array.
|
||||
if scriptFound {
|
||||
scriptsExecuted = append(scriptsExecuted, script.Filename)
|
||||
}
|
||||
// If it was successfully executed, we stop here.
|
||||
if success {
|
||||
scriptSuccess = true
|
||||
return
|
||||
}
|
||||
}
|
||||
return false
|
||||
return
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ func setGopath(root string) {
|
|||
func buildWithoutCustomCommands(modMode project.ModMode) (shouldInstallDependencies bool) {
|
||||
shouldInstallDependencies = false
|
||||
// try to run a build script
|
||||
scriptSucceeded := autobuilder.Autobuild()
|
||||
scriptSucceeded, _ := autobuilder.Autobuild()
|
||||
|
||||
// If there is no build script we could invoke successfully or there are still dependency errors;
|
||||
// we'll try to install dependencies ourselves in the normal Go way.
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/github/codeql-go/extractor/util"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/github/codeql-go/extractor/util"
|
||||
|
||||
"github.com/github/codeql-go/extractor/autobuilder"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// check if a build command has successfully extracted something
|
||||
autobuilder.CheckExtracted = true
|
||||
if autobuilder.Autobuild() {
|
||||
scriptSuccess, _ := autobuilder.Autobuild()
|
||||
if scriptSuccess {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче