mirror of
https://github.com/github/codeql.git
synced 2026-04-21 23:14:03 +02:00
Merge branch 'main' into workflow/coverage/update
This commit is contained in:
@@ -1844,9 +1844,6 @@ class TranslatedAssignExpr extends TranslatedNonConstantExpr {
|
||||
child = this.getRightOperand() and
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
or
|
||||
child = this.getRightOperand() and
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
or
|
||||
kind instanceof GotoEdge and
|
||||
child = this.getLeftOperand() and
|
||||
result = this.getInstruction(AssignmentStoreTag())
|
||||
|
||||
@@ -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,25 @@ 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 {
|
||||
// Returns `scriptSuccess` which indicates whether a build script was successfully executed.
|
||||
// Returns `scriptsExecuted` which contains the names of all build scripts that were executed.
|
||||
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
|
||||
}
|
||||
|
||||
@@ -320,21 +320,26 @@ func setGopath(root string) {
|
||||
log.Printf("GOPATH set to %s.\n", newGopath)
|
||||
}
|
||||
|
||||
// Try to build the project without custom commands. If that fails, return a boolean indicating
|
||||
// that we should install dependencies ourselves.
|
||||
// Try to build the project with a build script. If that fails, return a boolean indicating
|
||||
// that we should install dependencies in the normal way.
|
||||
func buildWithoutCustomCommands(modMode project.ModMode) bool {
|
||||
shouldInstallDependencies := false
|
||||
// try to build the project
|
||||
buildSucceeded := autobuilder.Autobuild()
|
||||
// try to run a build script
|
||||
scriptSucceeded, scriptsExecuted := autobuilder.Autobuild()
|
||||
scriptCount := len(scriptsExecuted)
|
||||
|
||||
// Build failed or there are still dependency errors; we'll try to install dependencies
|
||||
// ourselves
|
||||
if !buildSucceeded {
|
||||
log.Println("Build failed, continuing to install dependencies.")
|
||||
// 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.
|
||||
if !scriptSucceeded {
|
||||
if scriptCount > 0 {
|
||||
log.Printf("Unsuccessfully ran %d build scripts(s), continuing to install dependencies in the normal way.\n", scriptCount)
|
||||
} else {
|
||||
log.Println("Unable to find any build scripts, continuing to install dependencies in the normal way.")
|
||||
}
|
||||
|
||||
shouldInstallDependencies = true
|
||||
} else if toolchain.DepErrors("./...", modMode.ArgsForGoVersion(toolchain.GetEnvGoSemVer())...) {
|
||||
log.Println("Dependencies are still not resolving after the build, continuing to install dependencies.")
|
||||
log.Printf("Dependencies are still not resolving after executing %d build script(s), continuing to install dependencies in the normal way.\n", scriptCount)
|
||||
|
||||
shouldInstallDependencies = true
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import os
|
||||
from create_database_utils import *
|
||||
from diagnostics_test_utils import *
|
||||
from resolve_environment_utils import *
|
||||
|
||||
def go_integration_test(source = "src", db = "db", runFunction = runSuccessfully):
|
||||
def go_integration_test(toolchain=None, source = "src", db = "db", runFunction = runSuccessfully):
|
||||
# Set up a GOPATH relative to this test's root directory;
|
||||
# we set os.environ instead of using extra_env because we
|
||||
# need it to be set for the call to "go clean -modcache" later
|
||||
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
|
||||
os.environ['GOPATH'] = goPath
|
||||
|
||||
extra_env = None
|
||||
|
||||
if toolchain != None:
|
||||
extra_env = { 'GOTOOLCHAIN': toolchain }
|
||||
|
||||
try:
|
||||
run_codeql_resolve_build_environment(lang="go", source=source, extra_env=extra_env)
|
||||
run_codeql_database_create([], lang="go", source=source, db=db, runFunction=runFunction)
|
||||
|
||||
check_diagnostics()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : {
|
||||
"version" : "1.22"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"location": {
|
||||
"file": "go.mod"
|
||||
},
|
||||
"markdownMessage": "As of Go 1.21, toolchain versions [must use the 1.N.P syntax](https://go.dev/doc/toolchain#version).\n\n`1.22` in `go.mod` does not match this syntax and there is no additional `toolchain` directive, which may cause some `go` commands to fail.",
|
||||
"severity": "warning",
|
||||
"source": {
|
||||
"extractorName": "go",
|
||||
"id": "go/autobuilder/invalid-go-toolchain-version",
|
||||
"name": "Invalid Go toolchain version"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": true,
|
||||
"statusPage": true,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
{
|
||||
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
|
||||
"severity": "note",
|
||||
"source": {
|
||||
"extractorName": "go",
|
||||
"id": "go/autobuilder/single-root-go-mod-found",
|
||||
"name": "A single `go.mod` file was found in the root"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": false,
|
||||
"statusPage": false,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
go 1.22
|
||||
|
||||
module main
|
||||
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
func Main() {}
|
||||
@@ -0,0 +1,3 @@
|
||||
from go_integration_test import *
|
||||
|
||||
go_integration_test(toolchain="go1.21.0")
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"configuration" : {
|
||||
"go" : { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user