Exemplo n.º 1
0
        // 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 (options?.ResponseFiles != null && options.ResponseFiles.Any())
            {
                options = FromResponseFiles(options.ResponseFiles);
            }
            if (options == null)
            {
                return(ReturnCode.INVALID_ARGUMENTS);
            }

            var usesPlugins = options.Plugins != null && options.Plugins.Any();
            var loadOptions = new CompilationLoader.Configuration
            {
                ProjectName               = options.ProjectName,
                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));
        }
    }
Exemplo n.º 2
0
        // 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, Array.Empty <string>());
                return(ReturnCode.INVALID_ARGUMENTS);
            }

            var usesPlugins = options.Plugins != null && options.Plugins.Any();

            if (!options.ParseAssemblyProperties(out var assemblyConstants))
            {
                logger.Log(WarningCode.InvalidAssemblyProperties, Array.Empty <string>());
            }

            var loadOptions = new CompilationLoader.Configuration
            {
                ProjectName                  = options.ProjectName,
                AssemblyConstants            = assemblyConstants,
                TargetPackageAssemblies      = options.TargetSpecificDecompositions,
                RuntimeCapabilities          = options.RuntimeCapabilites,
                SkipMonomorphization         = options.RuntimeCapabilites == RuntimeCapabilities.Unknown,
                GenerateFunctorSupport       = true,
                SkipSyntaxTreeTrimming       = options.TrimLevel == 0,
                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
                IsExecutable                 = options.MakeExecutable,
                RewriteSteps                 = options.Plugins?.Select(step => (step, (string)null)) ?? ImmutableArray <(string, string)> .Empty,
                EnableAdditionalChecks       = false, // todo: enable debug mode?
                ExposeReferencesViaTestNames = options.ExposeReferencesViaTestNames
            };

            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));
        }
    }