using System; using System.Collections.Generic; using Semmle.Util; namespace Semmle.Extraction.CSharp { public sealed class Options : CommonOptions { /// /// The compiler exe, or null if unspecified. /// public string? CompilerName { get; set; } /// /// Specified .Net Framework dir, or null if unspecified. /// public string? Framework { get; set; } /// /// All other arguments passed to the compilation. /// public IList CompilerArguments { get; } = new List(); /// /// Holds if the extractor was launched from the CLR tracer. /// public bool ClrTracer { get; private set; } = false; /// /// Holds if assembly information should be prefixed to TRAP labels. /// public bool AssemblySensitiveTrap { get; private set; } = false; public static Options CreateWithEnvironment(string[] arguments) { var options = new Options(); var extractionOptions = Environment.GetEnvironmentVariable("SEMMLE_EXTRACTOR_OPTIONS") ?? Environment.GetEnvironmentVariable("LGTM_INDEX_EXTRACTOR"); var argsList = new List(arguments); if (!string.IsNullOrEmpty(extractionOptions)) argsList.AddRange(extractionOptions.Split(' ')); options.ParseArguments(argsList); return options; } public override bool HandleArgument(string argument) { CompilerArguments.Add(argument); return true; } public override void InvalidArgument(string argument) { // Unrecognised arguments are passed to the compiler. CompilerArguments.Add(argument); } public override bool HandleOption(string key, string value) { switch (key) { case "compiler": CompilerName = value; return true; case "framework": Framework = value; return true; default: return base.HandleOption(key, value); } } public override bool HandleFlag(string flag, bool value) { switch (flag) { case "clrtracer": ClrTracer = value; return true; case "assemblysensitivetrap": AssemblySensitiveTrap = value; return true; default: return base.HandleFlag(flag, value); } } private Options() { } } }