public virtual bool handleFlag(string flag, bool value) { switch (flag) { case "verbose": Verbosity = value ? Verbosity.Debug : Verbosity.Error; return(true); case "console": Console = value; return(true); case "cache": Cache = value; return(true); case "cil": CIL = value; return(true); case "pdb": PDB = value; CIL = true; return(true); case "fast": CIL = !value; Fast = value; return(true); case "brotli": TrapCompression = value ? TrapWriter.CompressionMode.Brotli : TrapWriter.CompressionMode.Gzip; return(true); default: return(false); } }
public virtual bool HandleOption(string key, string value) { switch (key) { case "threads": Threads = int.Parse(value); return(true); case "verbosity": Verbosity = (Verbosity)int.Parse(value); return(true); case "trap_compression": if (Enum.TryParse <TrapWriter.CompressionMode>(value, true, out var mode)) { TrapCompression = mode; return(true); } return(false); default: return(false); } }
/// <summary> /// Main entry point to the CIL extractor. /// Call this to extract a given assembly. /// </summary> /// <param name="layout">The trap layout.</param> /// <param name="assemblyPath">The full path of the assembly to extract.</param> /// <param name="logger">The logger.</param> /// <param name="nocache">True to overwrite existing trap file.</param> /// <param name="extractPdbs">Whether to extract PDBs.</param> /// <param name="trapFile">The path of the trap file.</param> /// <param name="extracted">Whether the file was extracted (false=cached).</param> public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression, out string trapFile, out bool extracted) { trapFile = ""; extracted = false; try { var extractor = new Extractor(false, assemblyPath, logger); var project = layout.LookupProjectOrDefault(assemblyPath); using (var trapWriter = project.CreateTrapWriter(logger, assemblyPath + ".cil", true, trapCompression)) { trapFile = trapWriter.TrapFile; if (nocache || !System.IO.File.Exists(trapFile)) { var cx = extractor.CreateContext(null, trapWriter, null); ExtractCIL(cx, assemblyPath, extractPdbs); extracted = true; } } } catch (Exception ex) // lgtm[cs/catch-of-all-exceptions] { logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex)); } }
static void ExtractAssembly(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression) { string trapFile; bool extracted; var sw = new Stopwatch(); sw.Start(); Entities.Assembly.ExtractCIL(layout, assemblyPath, logger, nocache, extractPdbs, trapCompression, out trapFile, out extracted); sw.Stop(); logger.Log(Severity.Info, " {0} ({1})", assemblyPath, sw.Elapsed); }
/// <summary> /// Main entry point to the CIL extractor. /// Call this to extract a given assembly. /// </summary> /// <param name="layout">The trap layout.</param> /// <param name="assemblyPath">The full path of the assembly to extract.</param> /// <param name="logger">The logger.</param> /// <param name="nocache">True to overwrite existing trap file.</param> /// <param name="extractPdbs">Whether to extract PDBs.</param> /// <param name="trapFile">The path of the trap file.</param> /// <param name="extracted">Whether the file was extracted (false=cached).</param> public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression, out string trapFile, out bool extracted) { trapFile = ""; extracted = false; try { var canonicalPathCache = CanonicalPathCache.Create(logger, 1000); var pathTransformer = new PathTransformer(canonicalPathCache); var extractor = new Extractor(false, assemblyPath, logger, pathTransformer); var transformedAssemblyPath = pathTransformer.Transform(assemblyPath); var project = layout.LookupProjectOrDefault(transformedAssemblyPath); using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true); trapFile = trapWriter.TrapFile; if (nocache || !System.IO.File.Exists(trapFile)) { var cx = extractor.CreateContext(null, trapWriter, null, false); ExtractCIL(cx, assemblyPath, extractPdbs); extracted = true; } } catch (Exception ex) // lgtm[cs/catch-of-all-exceptions] { logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex)); } }
/// <summary> /// Creates a trap writer for this file. /// </summary> /// <returns>A newly created TrapWriter.</returns> public TrapWriter CreateTrapWriter(ILogger logger, TrapWriter.CompressionMode trapCompression, bool discardDuplicates) =>
/// <summary> /// Gets the name of the trap file for this file. /// </summary> /// <returns>The full filepath of the trap file.</returns> public string GetTrapPath(ILogger logger, TrapWriter.CompressionMode trapCompression) => TrapWriter.TrapPath(logger, Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"), this, trapCompression);
public static string TrapPath(ILogger logger, string? folder, string filename, TrapWriter.CompressionMode trapCompression) { filename = $"{Path.GetFullPath(filename)}.trap{TrapExtension(trapCompression)}"; if (string.IsNullOrEmpty(folder)) folder = Directory.GetCurrentDirectory(); return NestPaths(logger, folder, filename, InnerPathComputation.ABSOLUTE); ; }
/// <summary> /// Creates a trap writer for a given source/assembly file. /// </summary> /// <param name="srcFile">The source file.</param> /// <returns>A newly created TrapWriter.</returns> public TrapWriter CreateTrapWriter(ILogger logger, string srcFile, bool discardDuplicates, TrapWriter.CompressionMode trapCompression) => new TrapWriter(logger, srcFile, TRAP_FOLDER, SOURCE_ARCHIVE, discardDuplicates, trapCompression);
/// <summary> /// Gets the name of the trap file for a given source/assembly file. /// </summary> /// <param name="srcFile">The source file.</param> /// <returns>The full filepath of the trap file.</returns> public string GetTrapPath(ILogger logger, string srcFile, TrapWriter.CompressionMode trapCompression) => TrapWriter.TrapPath(logger, TRAP_FOLDER, srcFile, trapCompression);
/// <summary> /// Creates a trap writer for a given source/assembly file. /// </summary> /// <param name="srcFile">The source file.</param> /// <returns>A newly created TrapWriter.</returns> public TrapWriter CreateTrapWriter(ILogger logger, PathTransformer.ITransformedPath srcFile, TrapWriter.CompressionMode trapCompression, bool discardDuplicates) => new TrapWriter(logger, srcFile, TRAP_FOLDER, SOURCE_ARCHIVE, trapCompression, discardDuplicates);
/// <summary> /// Gets the name of the trap file for a given source/assembly file. /// </summary> /// <param name="srcFile">The source file.</param> /// <returns>The full filepath of the trap file.</returns> public string GetTrapPath(ILogger logger, PathTransformer.ITransformedPath srcFile, TrapWriter.CompressionMode trapCompression) => TrapWriter.TrapPath(logger, TRAP_FOLDER, srcFile, trapCompression);
public static string TrapPath(ILogger logger, string?folder, PathTransformer.ITransformedPath path, TrapWriter.CompressionMode trapCompression) { var filename = $"{path.Value}.trap{TrapExtension(trapCompression)}"; if (string.IsNullOrEmpty(folder)) { folder = Directory.GetCurrentDirectory(); } return(NestPaths(logger, folder, filename)); }
private static void ExtractAssembly(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression) { var sw = new Stopwatch(); sw.Start(); Analyser.ExtractCIL(layout, assemblyPath, logger, nocache, extractPdbs, trapCompression, out _, out _); sw.Stop(); logger.Log(Severity.Info, " {0} ({1})", assemblyPath, sw.Elapsed); }