// publicly accessible routines /// <summary> /// Builds the compilation for the Q# code or Q# snippet and referenced assemblies defined by the given options. /// Returns a suitable error code if one of the compilation or generation steps fails. /// Throws an ArgumentNullException if any of the given arguments is null. /// </summary> public static int Run(BuildOptions options, ConsoleLogger logger) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (!BuildOptions.IncorporateResponseFiles(options, out options)) { logger.Log(ErrorCode.InvalidCommandLineArgsInResponseFiles, new string[0]); return(ReturnCode.INVALID_ARGUMENTS); } var usesPlugins = options.Plugins != null && options.Plugins.Any(); if (!options.ParseAssemblyProperties(out var assemblyConstants)) { logger.Log(WarningCode.InvalidAssemblyProperties, new string[0]); } var loadOptions = new CompilationLoader.Configuration { ProjectName = options.ProjectName, AssemblyConstants = assemblyConstants, TargetPackageAssembly = options.GetTargetPackageAssemblyPath(logger), GenerateFunctorSupport = true, SkipSyntaxTreeTrimming = options.TrimLevel == 0, ConvertClassicalControl = options.TrimLevel >= 2, AttemptFullPreEvaluation = options.TrimLevel > 2, DocumentationOutputFolder = options.DocFolder, BuildOutputFolder = options.OutputFolder ?? (usesPlugins ? "." : null), DllOutputPath = options.EmitDll ? " " : null, // set to e.g. an empty space to generate the dll in the same location as the .bson file RewriteSteps = options.Plugins?.Select(step => (step, (string)null)) ?? ImmutableArray <(string, string)> .Empty, EnableAdditionalChecks = false // todo: enable debug mode? }; if (options.PerfFolder != null) { CompilationLoader.CompilationTaskEvent += CompilationTracker.OnCompilationTaskEvent; } var loaded = new CompilationLoader(options.LoadSourcesOrSnippet(logger), options.References, loadOptions, logger); if (options.PerfFolder != null) { try { CompilationTracker.PublishResults(options.PerfFolder); } catch (Exception ex) { logger.Log(ErrorCode.PublishingPerfResultsFailed, new string[] { options.PerfFolder }); logger.Log(ex); } } return(ReturnCode.Status(loaded)); } }