From 2e550bba7f43a1924c16fe426e6c4641805c453d Mon Sep 17 00:00:00 2001
From: Robert Brignull <robertbrignull@gmail.com>
Date: Fri, 18 Sep 2020 16:52:03 +0100
Subject: [PATCH] Check CODEQL_EXTRACTOR_GO_BUILD_TRACING

Co-authored-by: Max Schaefer <54907921+max-schaefer@users.noreply.github.com>
---
 .github/workflows/integration-testing.yml | 31 +++++++++++++++++++++++
 lib/languages.js                          |  4 ++-
 lib/languages.js.map                      |  2 +-
 src/languages.ts                          |  6 ++++-
 4 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/integration-testing.yml b/.github/workflows/integration-testing.yml
index 8a2a8bc6a..d71c2af55 100644
--- a/.github/workflows/integration-testing.yml
+++ b/.github/workflows/integration-testing.yml
@@ -98,6 +98,37 @@ jobs:
       env:
         TEST_MODE: true
 
+  go-custom-tracing:
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest, windows-latest, macos-latest]
+    runs-on: ${{ matrix.os }}
+    env:
+      CODEQL_EXTRACTOR_GO_BUILD_TRACING: "on"
+
+    steps:
+    - uses: actions/setup-go@v2
+      if: ${{ matrix.os ==  'macos-latest' }}
+      with:
+        go-version: '^1.13.1'
+    - uses: actions/checkout@v2
+    - name: Move codeql-action
+      shell: bash
+      run: |
+        mkdir ../action
+        mv * .github ../action/
+        mv ../action/tests/multi-language-repo/{*,.github} .
+    - uses: ./../action/init
+      with:
+        languages: go
+    - name: Build code
+      shell: bash
+      run: go tool compile main.go
+    - uses: ./../action/analyze
+      env:
+        TEST_MODE: true
+
   multi-language-repo_rubocop:
     runs-on: ubuntu-latest
 
diff --git a/lib/languages.js b/lib/languages.js
index 8bdf3cbe1..696662e39 100644
--- a/lib/languages.js
+++ b/lib/languages.js
@@ -33,7 +33,9 @@ function parseLanguage(language) {
 }
 exports.parseLanguage = parseLanguage;
 function isTracedLanguage(language) {
-    return ["cpp", "java", "csharp"].includes(language);
+    return (["cpp", "java", "csharp"].includes(language) ||
+        (process.env["CODEQL_EXTRACTOR_GO_BUILD_TRACING"] === "on" &&
+            language === Language.go));
 }
 exports.isTracedLanguage = isTracedLanguage;
 function isScannedLanguage(language) {
diff --git a/lib/languages.js.map b/lib/languages.js.map
index b98b19b73..f83135e14 100644
--- a/lib/languages.js.map
+++ b/lib/languages.js.map
@@ -1 +1 @@
-{"version":3,"file":"languages.js","sourceRoot":"","sources":["../src/languages.ts"],"names":[],"mappings":";;AAAA,wCAAwC;AACxC,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,uBAAW,CAAA;IACX,qBAAS,CAAA;IACT,yBAAa,CAAA;IACb,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;AACnB,CAAC,EAPW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAOnB;AAED,iCAAiC;AACjC,MAAM,gBAAgB,GAAiC;IACrD,CAAC,EAAE,QAAQ,CAAC,GAAG;IACf,KAAK,EAAE,QAAQ,CAAC,GAAG;IACnB,IAAI,EAAE,QAAQ,CAAC,MAAM;IACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;CAChC,CAAC;AAEF,gGAAgG;AAChG,SAAgB,aAAa,CAAC,QAAgB;IAC5C,0BAA0B;IAC1B,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAElC,6BAA6B;IAC7B,IAAI,QAAQ,IAAI,QAAQ,EAAE;QACxB,OAAO,QAAoB,CAAC;KAC7B;IAED,yBAAyB;IACzB,IAAI,QAAQ,IAAI,gBAAgB,EAAE;QAChC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;KACnC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAfD,sCAeC;AAED,SAAgB,gBAAgB,CAAC,QAAkB;IACjD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC;AAFD,4CAEC;AAED,SAAgB,iBAAiB,CAAC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AiB,CAAC,QAAkB;IAClD,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAFD,8CAEC"}
\ No newline at end of file
diff --git a/src/languages.ts b/src/languages.ts
index b2975ae42..d935d341d 100644
--- a/src/languages.ts
+++ b/src/languages.ts
@@ -35,7 +35,11 @@ export function parseLanguage(language: string): Language | undefined {
 }
 
 export function isTracedLanguage(language: Language): boolean {
-  return ["cpp", "java", "csharp"].includes(language);
+  return (
+    ["cpp", "java", "csharp"].includes(language) ||
+    (process.env["CODEQL_EXTRACTOR_GO_BUILD_TRACING"] === "on" &&
+      language === Language.go)
+  );
 }
 
 export function isScannedLanguage(language: Language): boolean {