diff --git a/csharp/extractor/Semmle.Extraction.CSharp.Driver/Driver.cs b/csharp/extractor/Semmle.Extraction.CSharp.Driver/Driver.cs index e8a42b3f5a0..047a8ddb8ae 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.Driver/Driver.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.Driver/Driver.cs @@ -1,3 +1,7 @@ +using System; +using System.Text.RegularExpressions; +using System.Collections.Generic; + namespace Semmle.Extraction.CSharp { /// @@ -9,6 +13,31 @@ namespace Semmle.Extraction.CSharp { Extractor.SetInvariantCulture(); + Console.WriteLine($"Semmle.Extraction.CSharp.Driver: called with {string.Join(", ", args)}"); + + if (args.Length > 0 && args[0] == "--dotnetexec") + { + var compilerRegEx = new Regex(@"csc\.exe|mcs\.exe|csc\.dll", RegexOptions.Compiled); + var cil = args.Length > 1 && args[1] == "--cil"; + for (var i = cil ? 2 : 1; i < args.Length; i++) + { + if (compilerRegEx.IsMatch(args[i])) + { + var argsList = new List(); + if (cil) + argsList.Add("--cil"); + argsList.Add("--compiler"); + argsList.Add(args[i]); + if (i + 1 < args.Length) + argsList.AddRange(args[(i + 1)..]); + return (int)Extractor.Run(argsList.ToArray()); + } + } + + Console.WriteLine($"Semmle.Extraction.CSharp.Driver: not a compiler invocation"); + return 0; + } + return (int)Extractor.Run(args); } } diff --git a/csharp/tools/linux64/compiler-tracing.spec b/csharp/tools/linux64/compiler-tracing.spec index ede7ead1093..659170b7ceb 100644 --- a/csharp/tools/linux64/compiler-tracing.spec +++ b/csharp/tools/linux64/compiler-tracing.spec @@ -6,7 +6,9 @@ prepend --cil **/mono*: **/dotnet: - invoke ${config_dir}/extract-csharp.sh + invoke ${config_dir}/Semmle.Extraction.CSharp.Driver + prepend --dotnetexec + prepend --cil **/msbuild: **/xbuild: replace yes diff --git a/csharp/tools/linux64/extract-csharp.sh b/csharp/tools/linux64/extract-csharp.sh deleted file mode 100755 index ec7013bf03e..00000000000 --- a/csharp/tools/linux64/extract-csharp.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -echo extract-csharp.sh: Called with arguments: "$@" - -extractor="$CODEQL_EXTRACTOR_CSHARP_ROOT/tools/$CODEQL_PLATFORM/Semmle.Extraction.CSharp.Driver" - -for i in "$@" -do - shift - if [[ `basename -- "$i"` =~ csc.exe|mcs.exe|csc.dll ]] - then - echo extract-csharp.sh: exec $extractor --cil $@ - exec "$extractor" --compiler $i --cil $@ - fi -done - -echo extract-csharp.sh: Not a compiler invocation diff --git a/csharp/tools/osx64/compiler-tracing.spec b/csharp/tools/osx64/compiler-tracing.spec index 76b328a5d27..13146e09557 100644 --- a/csharp/tools/osx64/compiler-tracing.spec +++ b/csharp/tools/osx64/compiler-tracing.spec @@ -6,7 +6,9 @@ prepend --cil **/mono*: **/dotnet: - invoke ${config_dir}/extract-csharp.sh + invoke ${config_dir}/Semmle.Extraction.CSharp.Driver + prepend --dotnetexec + prepend --cil **/msbuild: **/xbuild: replace yes diff --git a/csharp/tools/osx64/extract-csharp.sh b/csharp/tools/osx64/extract-csharp.sh deleted file mode 100755 index ec7013bf03e..00000000000 --- a/csharp/tools/osx64/extract-csharp.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -echo extract-csharp.sh: Called with arguments: "$@" - -extractor="$CODEQL_EXTRACTOR_CSHARP_ROOT/tools/$CODEQL_PLATFORM/Semmle.Extraction.CSharp.Driver" - -for i in "$@" -do - shift - if [[ `basename -- "$i"` =~ csc.exe|mcs.exe|csc.dll ]] - then - echo extract-csharp.sh: exec $extractor --cil $@ - exec "$extractor" --compiler $i --cil $@ - fi -done - -echo extract-csharp.sh: Not a compiler invocation diff --git a/csharp/tools/win64/compiler-tracing.spec b/csharp/tools/win64/compiler-tracing.spec index 72ef54a8cab..ca1d544e884 100644 --- a/csharp/tools/win64/compiler-tracing.spec +++ b/csharp/tools/win64/compiler-tracing.spec @@ -7,3 +7,7 @@ prepend --compiler prepend "${compiler}" prepend --cil +**\dotnet.exe: + invoke ${config_dir}\Semmle.Extraction.CSharp.Driver.exe + prepend --dotnetexec + prepend --cil