Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 85c9225

Browse files
author
Sauyon Lee
committed
Add a new binary for tracing
1 parent de0582a commit 85c9225

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ CODEQL_PLATFORM = osx64
1414
endif
1515
endif
1616

17-
CODEQL_TOOLS = $(addprefix codeql-tools/,autobuild.cmd autobuild.sh index.cmd index.sh)
17+
CODEQL_TOOLS = $(addprefix codeql-tools/,autobuild.cmd autobuild.sh index.cmd index.sh linux64 osx64 win64)
1818

1919
EXTRACTOR_PACK_OUT = build/codeql-extractor-go
2020

21-
BINARIES = go-extractor go-tokenizer go-autobuilder go-bootstrap go-gen-dbscheme
21+
BINARIES = go-extractor go-tokenizer go-autobuilder go-build-runner go-bootstrap go-gen-dbscheme
2222

2323
.PHONY: tools tools-codeql tools-codeql-full clean autoformat \
2424
tools-linux64 tools-osx64 tools-win64 check-formatting

codeql-tools/autobuild.cmd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ SETLOCAL EnableDelayedExpansion
44
rem Some legacy environment variables for the autobuilder.
55
set LGTM_SRC=%CD%
66

7-
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-autobuilder.exe"
7+
if "%CODEQL_EXTRACTOR_GO_BUILD_TRACING%"=="on" (
8+
echo "Tracing enabled"
9+
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-build-runner.exe"
10+
) else (
11+
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-autobuilder.exe"
12+
)
813
exit /b %ERRORLEVEL%
914

1015
ENDLOCAL

codeql-tools/autobuild.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ fi
1111
LGTM_SRC="$(pwd)"
1212
export LGTM_SRC
1313

14-
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-autobuilder"
14+
if [ "${CODEQL_EXTRACTOR_GO_BUILD_TRACING:-}" == "on" ]; then
15+
echo "Tracing enabled"
16+
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-build-runner"
17+
else
18+
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-autobuilder"
19+
fi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/go-autobuilder:
2+
order compiler
3+
trace no
4+
**/go:
5+
invoke ${config_dir}/go-extractor
6+
prepend --mimic
7+
prepend "${compiler}"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/go-autobuilder:
2+
order compiler
3+
trace no
4+
**/go:
5+
invoke ${config_dir}/go-extractor
6+
prepend --mimic
7+
prepend "${compiler}"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/go-autobuilder.exe:
2+
order compiler
3+
trace no
4+
**/go.exe:
5+
invoke ${config_dir}/go-extractor.exe
6+
prepend --mimic
7+
prepend "${compiler}"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"github.com/github/codeql-go/extractor/util"
5+
"log"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"runtime"
10+
11+
"github.com/github/codeql-go/extractor/autobuilder"
12+
)
13+
14+
func main() {
15+
// check if a build command has successfully extracted something
16+
autobuilder.CheckExtracted = true
17+
if autobuilder.Autobuild() {
18+
return
19+
}
20+
21+
// if the autobuilder fails, invoke the extractor manually
22+
// we cannot simply call `go build` here, because the tracer is not able to trace calls made by
23+
// this binary
24+
log.Printf("No build commands succeeded, falling back to go build ./...")
25+
26+
mypath, err := os.Executable()
27+
if err != nil {
28+
log.Fatalf("Could not determine path of extractor: %v.\n", err)
29+
}
30+
extractor := filepath.Join(filepath.Dir(mypath), "go-extractor")
31+
if runtime.GOOS == "windows" {
32+
extractor = extractor + ".exe"
33+
}
34+
35+
util.RunCmd(exec.Command(extractor, "./..."))
36+
}

0 commit comments

Comments
 (0)