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

Commit f5d8fe6

Browse files
author
Sauyon Lee
committed
Add go-build binary for tracing
1 parent 91dce02 commit f5d8fe6

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CODEQL_TOOLS = $(addprefix codeql-tools/,autobuild.cmd autobuild.sh index.cmd in
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 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ 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_GO_TRACE% = "" (
8+
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-build"
9+
) else (
10+
type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-autobuilder.exe"
11+
)
812
exit /b %ERRORLEVEL%
913

1014
ENDLOCAL

codeql-tools/autobuild.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ 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_TRACE:-}" == "on" ]; then
15+
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-build"
16+
else
17+
"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-autobuilder"
18+
fi

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

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 autobuilder: %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)