Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/codeql-extractor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ column_kind: "utf8"
build_modes:
- autobuild
- manual
- none
default_queries:
- codeql/go-queries
github_api_languages:
Expand Down
6 changes: 3 additions & 3 deletions go/codeql-tools/autobuild.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ SETLOCAL EnableDelayedExpansion
rem Some legacy environment variables for the autobuilder.
set LGTM_SRC=%CD%

if "%CODEQL_EXTRACTOR_GO_BUILD_TRACING%"=="on" (
if "%CODEQL_EXTRACTOR_GO_BUILD_TRACING%"=="on" if not "%CODEQL_EXTRACTOR_GO_BUILD_MODE%"=="none" (
echo "Tracing enabled"
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-build-runner.exe"
) else (
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-autobuilder.exe"
exit /b !ERRORLEVEL!
)
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-autobuilder.exe"
exit /b %ERRORLEVEL%

ENDLOCAL
2 changes: 1 addition & 1 deletion go/codeql-tools/autobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
LGTM_SRC="$(pwd)"
export LGTM_SRC

if [ "${CODEQL_EXTRACTOR_GO_BUILD_TRACING:-}" = "on" ]; then
if [ "${CODEQL_EXTRACTOR_GO_BUILD_TRACING:-}" = "on" ] && [ "${CODEQL_EXTRACTOR_GO_BUILD_MODE:-}" != "none" ]; then
echo "Tracing enabled"
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-build-runner"
else
Expand Down
10 changes: 9 additions & 1 deletion go/extractor/cli/go-autobuilder/go-autobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Options:

Build behavior:

When the build mode is 'none', the script resolves dependencies and invokes the extractor
without running project build scripts or custom build commands.

When LGTM_SRC is not set, the script installs dependencies as described below, and then invokes the
extractor in the working directory.

Expand Down Expand Up @@ -587,7 +590,12 @@ func installDependenciesAndBuild() {

// check whether an explicit dependency installation command was provided
inst := util.Getenv("CODEQL_EXTRACTOR_GO_BUILD_COMMAND", "LGTM_INDEX_BUILD_COMMAND")
if inst == "" {
if os.Getenv("CODEQL_EXTRACTOR_GO_BUILD_MODE") == "none" {
log.Println("Build mode is 'none'; skipping project build scripts and custom build commands.")
for i := range workspaces {
workspaces[i].ShouldInstallDependencies = true
}
} else if inst == "" {
buildWithoutCustomCommands(workspaces)
} else {
buildWithCustomCommands(inst)
Expand Down
7 changes: 5 additions & 2 deletions go/ql/integration-tests/mixed-layout/test.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
def test(codeql, go):
codeql.database.create(source_root="src")
import pytest

@pytest.mark.parametrize("build_mode", ["autobuild", "none"])
def test(codeql, go, build_mode):
codeql.database.create(source_root="src", build_mode=build_mode)
22 changes: 22 additions & 0 deletions go/ql/integration-tests/test-extraction/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
from pathlib import Path

import pytest

def test_traced(codeql, go):
codeql.database.create(source_root="src", command="go test -c ./...")
Expand All @@ -14,3 +17,22 @@ def test_autobuild_traced(codeql, go):
extractor_option = ["extract_tests=true"],
_env={"CODEQL_EXTRACTOR_GO_BUILD_TRACING": "on"},
)

@pytest.mark.parametrize("env", [
{},
{
"CODEQL_EXTRACTOR_GO_BUILD_COMMAND": "echo built > custom-build-ran",
"LGTM_INDEX_BUILD_COMMAND": "echo built > legacy-build-ran",
"CODEQL_EXTRACTOR_GO_BUILD_TRACING": "on",
},
Comment on lines +23 to +27
])
def test_no_build(codeql, go, env):
Path("src/Makefile").write_text("all:\n\techo built > project-build-ran\n")
codeql.database.create(
source_root="src",
build_mode="none",
extractor_option=["extract_tests=true"],
_env=env,
)
for marker in ["project-build-ran", "custom-build-ran", "legacy-build-ran"]:
assert not Path("src", marker).exists()
Loading