Skip to content

Commit 2539650

Browse files
authored
Merge branch 'main' into workflow/coverage/update
2 parents c3caafc + 964b3f2 commit 2539650

File tree

37 files changed

+234
-25
lines changed

37 files changed

+234
-25
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,9 +1844,6 @@ class TranslatedAssignExpr extends TranslatedNonConstantExpr {
18441844
child = this.getRightOperand() and
18451845
result = this.getLeftOperand().getFirstInstruction(kind)
18461846
or
1847-
child = this.getRightOperand() and
1848-
result = this.getLeftOperand().getFirstInstruction(kind)
1849-
or
18501847
kind instanceof GotoEdge and
18511848
child = this.getLeftOperand() and
18521849
result = this.getInstruction(AssignmentStoreTag())

go/extractor/autobuilder/autobuilder.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ func checkExtractorRun() bool {
5454
}
5555

5656
// tryBuildIfExists tries to run the command `cmd args...` if the file `buildFile` exists and is not
57-
// a directory. Returns true if the command was successful and false if not.
58-
func tryBuildIfExists(buildFile, cmd string, args ...string) bool {
59-
if util.FileExists(buildFile) {
57+
// a directory. Returns values indicating whether the script succeeded as well as whether the script was found.
58+
func tryBuildIfExists(buildFile, cmd string, args ...string) (scriptSuccess bool, scriptFound bool) {
59+
scriptSuccess = false
60+
scriptFound = util.FileExists(buildFile)
61+
if scriptFound {
6062
log.Printf("%s found.\n", buildFile)
61-
return tryBuild(cmd, args...)
63+
scriptSuccess = tryBuild(cmd, args...)
6264
}
63-
return false
65+
return
6466
}
6567

6668
// tryBuild tries to run `cmd args...`, returning true if successful and false if not.
@@ -92,11 +94,25 @@ var BuildScripts = []BuildScript{
9294
// Autobuild attempts to detect build systems based on the presence of build scripts from the
9395
// list in `BuildScripts` and run the corresponding command. This may invoke zero or more
9496
// build scripts in the order given by `BuildScripts`.
95-
func Autobuild() bool {
97+
// Returns `scriptSuccess` which indicates whether a build script was successfully executed.
98+
// Returns `scriptsExecuted` which contains the names of all build scripts that were executed.
99+
func Autobuild() (scriptSuccess bool, scriptsExecuted []string) {
100+
scriptSuccess = false
101+
scriptsExecuted = []string{}
102+
96103
for _, script := range BuildScripts {
97-
if tryBuildIfExists(script.Filename, script.Tool) {
98-
return true
104+
// Try to run the build script
105+
success, scriptFound := tryBuildIfExists(script.Filename, script.Tool)
106+
107+
// If it was found, we attempted to run it: add it to the array.
108+
if scriptFound {
109+
scriptsExecuted = append(scriptsExecuted, script.Filename)
110+
}
111+
// If it was successfully executed, we stop here.
112+
if success {
113+
scriptSuccess = true
114+
return
99115
}
100116
}
101-
return false
117+
return
102118
}

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,26 @@ func setGopath(root string) {
320320
log.Printf("GOPATH set to %s.\n", newGopath)
321321
}
322322

323-
// Try to build the project without custom commands. If that fails, return a boolean indicating
324-
// that we should install dependencies ourselves.
323+
// Try to build the project with a build script. If that fails, return a boolean indicating
324+
// that we should install dependencies in the normal way.
325325
func buildWithoutCustomCommands(modMode project.ModMode) bool {
326326
shouldInstallDependencies := false
327-
// try to build the project
328-
buildSucceeded := autobuilder.Autobuild()
329-
330-
// Build failed or there are still dependency errors; we'll try to install dependencies
331-
// ourselves
332-
if !buildSucceeded {
333-
log.Println("Build failed, continuing to install dependencies.")
327+
// try to run a build script
328+
scriptSucceeded, scriptsExecuted := autobuilder.Autobuild()
329+
scriptCount := len(scriptsExecuted)
330+
331+
// If there is no build script we could invoke successfully or there are still dependency errors;
332+
// we'll try to install dependencies ourselves in the normal Go way.
333+
if !scriptSucceeded {
334+
if scriptCount > 0 {
335+
log.Printf("Unsuccessfully ran %d build scripts(s), continuing to install dependencies in the normal way.\n", scriptCount)
336+
} else {
337+
log.Println("Unable to find any build scripts, continuing to install dependencies in the normal way.")
338+
}
334339

335340
shouldInstallDependencies = true
336341
} else if toolchain.DepErrors("./...", modMode.ArgsForGoVersion(toolchain.GetEnvGoSemVer())...) {
337-
log.Println("Dependencies are still not resolving after the build, continuing to install dependencies.")
342+
log.Printf("Dependencies are still not resolving after executing %d build script(s), continuing to install dependencies in the normal way.\n", scriptCount)
338343

339344
shouldInstallDependencies = true
340345
}

go/extractor/cli/go-build-runner/go-build-runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package main
22

33
import (
4-
"github.com/github/codeql-go/extractor/util"
54
"log"
65
"os"
76
"os/exec"
87
"path/filepath"
98
"runtime"
109

10+
"github.com/github/codeql-go/extractor/util"
11+
1112
"github.com/github/codeql-go/extractor/autobuilder"
1213
)
1314

1415
func main() {
1516
// check if a build command has successfully extracted something
1617
autobuilder.CheckExtracted = true
17-
if autobuilder.Autobuild() {
18+
scriptSuccess, _ := autobuilder.Autobuild()
19+
if scriptSuccess {
1820
return
1921
}
2022

go/integration-tests-lib/go_integration_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import os
22
from create_database_utils import *
33
from diagnostics_test_utils import *
4+
from resolve_environment_utils import *
45

5-
def go_integration_test(source = "src", db = "db", runFunction = runSuccessfully):
6+
def go_integration_test(toolchain=None, source = "src", db = "db", runFunction = runSuccessfully):
67
# Set up a GOPATH relative to this test's root directory;
78
# we set os.environ instead of using extra_env because we
89
# need it to be set for the call to "go clean -modcache" later
910
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
1011
os.environ['GOPATH'] = goPath
1112

13+
extra_env = None
14+
15+
if toolchain != None:
16+
extra_env = { 'GOTOOLCHAIN': toolchain }
17+
1218
try:
19+
run_codeql_resolve_build_environment(lang="go", source=source, extra_env=extra_env)
1320
run_codeql_database_create([], lang="go", source=source, db=db, runFunction=runFunction)
1421

1522
check_diagnostics()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"configuration" : {
3+
"go" : { }
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"configuration" : {
3+
"go" : { }
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"configuration" : {
3+
"go" : { }
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"configuration" : {
3+
"go" : { }
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"configuration" : {
3+
"go" : { }
4+
}
5+
}

0 commit comments

Comments
 (0)