Ejemplo n.º 1
0
        /// <summary>
        /// Logs detailed information about this invocation,
        /// in the event that errors were detected.
        /// </summary>
        /// <param name="roslynArgs">The arguments passed to Roslyn.</param>
        public void LogDiagnostics(string[] roslynArgs)
        {
            Logger.Log(Severity.Info, "  Extractor: {0}", Environment.GetCommandLineArgs().First());
            if (extractor != null)
            {
                Logger.Log(Severity.Info, "  Extractor version: {0}", extractor.Version);
            }

            Logger.Log(Severity.Info, "  Current working directory: {0}", Directory.GetCurrentDirectory());

            if (roslynArgs != null)
            {
                Logger.Log(Severity.Info, $"  Arguments to Roslyn: {string.Join(' ', roslynArgs)}");

                // Create a new file in the log folder.
                var argsFile = Path.Combine(Extractor.GetCSharpLogDirectory(), $"csharp.{Path.GetRandomFileName()}.txt");

                if (roslynArgs.ArchiveCommandLine(argsFile))
                {
                    Logger.Log(Severity.Info, $"  Arguments have been written to {argsFile}");
                }
            }

            foreach (var error in FilteredDiagnostics)
            {
                Logger.Log(Severity.Error, "  Compilation error: {0}", error);
            }

            if (FilteredDiagnostics.Any())
            {
                foreach (var reference in compilation.References)
                {
                    Logger.Log(Severity.Info, "  Resolved reference {0}", reference.Display);
                }
            }
        }
Ejemplo n.º 2
0
        public static int Main(string[] args)
        {
            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 <string>();
                        if (cil)
                        {
                            argsList.Add("--cil");
                        }
                        argsList.Add("--compiler");
                        argsList.Add(args[i]);
                        if (i + 1 < args.Length)
                        {
                            argsList.AddRange(args[(i + 1)..]);