Beispiel #1
0
            private void validateCopy()
            {
                if (_jobName == null)
                {
                    _syntaxResult.ReportError("Must have --job <name> for copy.");
                }

                if (_number == 0 && !_lastSuccessful && _commit == null)
                {
                    _syntaxResult.ReportError("Must have --number <num>, --last_successful, or --commit <commit> for copy.");
                }

                if (Convert.ToInt32(_number != 0) + Convert.ToInt32(_lastSuccessful) + Convert.ToInt32(_commit != null) > 1)
                {
                    _syntaxResult.ReportError("Must have only one of --number <num>, --last_successful, and --commit <commit> for copy.");
                }

                if (_outputPath == null)
                {
                    _syntaxResult.ReportError("Must have --output <path> for copy.");
                }
                if (_contentPath == null)
                {
                    _contentPath = "artifact/bin/Product/*zip*/Product.zip";
                }
            }
Beispiel #2
0
            private void validate()
            {
                if (_basePath == null)
                {
                    _syntaxResult.ReportError("Base path (--base) is required.");
                }

                if (_diffPath == null)
                {
                    _syntaxResult.ReportError("Diff path (--diff) is required.");
                }
            }
Beispiel #3
0
        // Validate arguments
        //
        // Pass a single tool as --corerun. Optionally specify a jit for corerun to use.
        //
        private void Validate()
        {
            if (_corerunExe == null)
            {
                _syntaxResult.ReportError("Specify --corerun.");
            }

            if ((_fileName == null) && (_assemblyList.Count == 0))
            {
                _syntaxResult.ReportError("No input: Specify --file <arg> or list input assemblies.");
            }

            // Check that we can find the corerunExe
            if (_corerunExe != null)
            {
                if (!File.Exists(_corerunExe))
                {
                    _syntaxResult.ReportError("Can't find --corerun tool.");
                }
                else
                {
                    // Set to full path for command resolution logic.
                    string fullCorerunPath = Path.GetFullPath(_corerunExe);
                    _corerunExe = fullCorerunPath;
                }
            }

            // Check that we can find the jit library.
            if (_jitPath != null)
            {
                if (!File.Exists(_jitPath))
                {
                    _syntaxResult.ReportError("Can't find --jit library.");
                }
                else
                {
                    // Set to full path for command resolution logic.
                    string fullJitPath = Path.GetFullPath(_jitPath);
                    _jitPath = fullJitPath;
                }
            }

            if (_fileName != null)
            {
                if (!File.Exists(_fileName))
                {
                    var message = String.Format("Error reading input file {0}, file not found.", _fileName);
                    _syntaxResult.ReportError(message);
                }
            }
        }
Beispiel #4
0
 void ValidateOptions(ArgumentSyntax syntax)
 {
     if (string.IsNullOrWhiteSpace(PhotoRoot))
     {
         syntax.ReportError("Please specify the local path containing the photos to process");
     }
 }
Beispiel #5
0
 protected override void Define(ArgumentSyntax syntax, Settings settings)
 {
     if (!syntax.DefineParameter("assembly", ref settings.Assembly, "The assembly to load by name.").IsSpecified)
     {
         syntax.ReportError("an assembly name must be specified.");
     }
 }
Beispiel #6
0
        public async Task <object> Execute(ArgumentSyntax syntax)
        {
            var serverUriParam = syntax.GetActiveArguments()
                                 .Where(p => p.Name == ParamServer)
                                 .OfType <Argument <Uri> >()
                                 .First();

            if (!serverUriParam.IsSpecified)
            {
                syntax.ReportError(string.Format(Strings.ErrorOptionMissing, ParamServer));
            }

            var ctx = contextFactory.Invoke(serverUriParam.Value, null);

            logger.Debug("Loading directory from '{0}'", serverUriParam.Value);
            var directory = await ctx.GetDirectory();

            await userSettings.SetDefaultServer(serverUriParam.Value);

            return(new
            {
                location = serverUriParam.Value,
                resource = directory,
            });
        }
Beispiel #7
0
            private void validateCopy()
            {
                if (_jobName == null)
                {
                    _syntaxResult.ReportError("Must have --job <name> for copy.");
                }

                if (_number == 0 && !_lastSuccessful)
                {
                    _syntaxResult.ReportError("Must have --number <num> or --last_successful for copy.");
                }

                if (_outputPath == null)
                {
                    _syntaxResult.ReportError("Must have --output <path> for copy.");
                }
            }
Beispiel #8
0
 protected override void Define(ArgumentSyntax syntax, Settings settings)
 {
     syntax.DefineOption("i|ignore-known-packages", ref settings.IgnoreKnownPackages, "Ignores (does not add) packages for known themes.");
     if (!syntax.DefineParameter("theme", ref settings.Theme, "The theme to use.").IsSpecified)
     {
         syntax.ReportError("a theme must be specified.");
     }
 }
Beispiel #9
0
        protected override void ParseOptions(ArgumentSyntax syntax)
        {
            syntax.DefineOption("w|watch", ref _watch, "Watches the input folder for any changes.");
            _preview = syntax.DefineOption("p|preview", ref _previewPort, false, "Start the preview web server on the specified port (default is " + _previewPort + ").").IsSpecified;
            if (syntax.DefineOption("force-ext", ref _previewForceExtension, "Force the use of extensions in the preview web server (by default, extensionless URLs may be used).").IsSpecified&& !_preview)
            {
                syntax.ReportError("force-ext can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("preview-root", ref _previewRoot, DirectoryPath.FromString, "The path to the root of the preview server, if not the output folder.").IsSpecified&& !_preview)
            {
                syntax.ReportError("preview-root can only be specified if the preview server is running.");
            }
            syntax.DefineOptionList("i|input", ref _configOptions.InputPaths, DirectoryPath.FromString, "The path(s) of input files, can be absolute or relative to the current folder.");
            syntax.DefineOption("o|output", ref _configOptions.OutputPath, DirectoryPath.FromString, "The path to output files, can be absolute or relative to the current folder.");
            syntax.DefineOption("c|config", ref _configOptions.ConfigFilePath, FilePath.FromString, "Configuration file (by default, config.wyam is used).");
            syntax.DefineOption("u|update-packages", ref _configOptions.UpdatePackages, "Check the NuGet server for more recent versions of each package and update them if applicable.");
            syntax.DefineOption("use-local-packages", ref _configOptions.UseLocalPackages, "Toggles the use of a local NuGet packages folder.");
            syntax.DefineOption("use-global-sources", ref _configOptions.UseGlobalSources, "Toggles the use of the global NuGet sources (default is false).");
            syntax.DefineOption("packages-path", ref _configOptions.PackagesPath, DirectoryPath.FromString, "The packages path to use (only if use-local is true).");
            syntax.DefineOption("output-script", ref _configOptions.OutputScript, "Outputs the config script after it's been processed for further debugging.");
            syntax.DefineOption("verify-config", ref _verifyConfig, false, "Compile the configuration but do not execute.");
            syntax.DefineOption("noclean", ref _configOptions.NoClean, "Prevents cleaning of the output path on each execution.");
            syntax.DefineOption("nocache", ref _configOptions.NoCache, "Prevents caching information during execution (less memory usage but slower execution).");

            _logFilePath = $"wyam-{DateTime.Now:yyyyMMddHHmmssfff}.txt";
            if (!syntax.DefineOption("l|log", ref _logFilePath, FilePath.FromString, false, "Log all trace messages to the specified log file (by default, wyam-[datetime].txt).").IsSpecified)
            {
                _logFilePath = null;
            }

            // Metadata
            IReadOnlyList <string> globalMetadata = null;

            if (syntax.DefineOptionList("g|global", ref globalMetadata, "Specifies global metadata as a sequence of key=value pairs. Use the syntax [x,y] to specify array values.").IsSpecified)
            {
                _configOptions.GlobalMetadata = MetadataParser.Parse(globalMetadata);
            }
            IReadOnlyList <string> initialMetadata = null;

            if (syntax.DefineOptionList("initial", ref initialMetadata, "Specifies initial document metadata as a sequence of key=value pairs. Use the syntax [x,y] to specify array values.").IsSpecified)
            {
                _configOptions.InitialMetadata = MetadataParser.Parse(initialMetadata);
            }
        }
Beispiel #10
0
            private void ValidateDiff()
            {
                if (_platformPath == null)
                {
                    _syntaxResult.ReportError("Specifiy --core_root <path>");
                }

                if ((_corlibOnly == false) &&
                    (_frameworksOnly == false) && (_testPath == null))
                {
                    _syntaxResult.ReportError("Specify --test_root <path>");
                }

                if (_outputPath == null)
                {
                    _syntaxResult.ReportError("Specify --output <path>");
                }

                if (!Directory.Exists(_outputPath))
                {
                    _syntaxResult.ReportError("Can't find --output path.");
                }

                if ((_basePath == null) && (_diffPath == null))
                {
                    _syntaxResult.ReportError("--base <path> or --diff <path> or both must be specified.");
                }

                if (_basePath != null && !Directory.Exists(_basePath))
                {
                    _syntaxResult.ReportError("Can't find --base directory.");
                }

                if (_diffPath != null && !Directory.Exists(_diffPath))
                {
                    _syntaxResult.ReportError("Can't find --diff directory.");
                }

                if (_crossgenExe != null && !File.Exists(_crossgenExe))
                {
                    _syntaxResult.ReportError("Can't find --crossgen executable.");
                }
            }
Beispiel #11
0
        protected override void ParseOptions(ArgumentSyntax syntax)
        {
            syntax.DefineOption("w|watch", ref _watch, "Watches the input folder for any changes.");
            _preview = syntax.DefineOption("p|preview", ref _previewPort, false, "Start the preview web server on the specified port (default is " + _previewPort + ").").IsSpecified;
            if (syntax.DefineOption("force-ext", ref _previewForceExtension, "Force the use of extensions in the preview web server (by default, extensionless URLs may be used).").IsSpecified && !_preview)
            {
                syntax.ReportError("force-ext can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("preview-root", ref _previewRoot, DirectoryPath.FromString, "The path to the root of the preview server, if not the output folder.").IsSpecified && !_preview)
            {
                syntax.ReportError("preview-root can only be specified if the preview server is running.");
            }
            syntax.DefineOptionList("i|input", ref _configOptions.InputPaths, DirectoryPath.FromString, "The path(s) of input files, can be absolute or relative to the current folder.");
            syntax.DefineOption("o|output", ref _configOptions.OutputPath, DirectoryPath.FromString, "The path to output files, can be absolute or relative to the current folder.");
            syntax.DefineOption("c|config", ref _configOptions.ConfigFilePath, FilePath.FromString, "Configuration file (by default, config.wyam is used).");
            syntax.DefineOption("u|update-packages", ref _configOptions.UpdatePackages, "Check the NuGet server for more recent versions of each package and update them if applicable.");
            syntax.DefineOption("use-local-packages", ref _configOptions.UseLocalPackages, "Toggles the use of a local NuGet packages folder.");
            syntax.DefineOption("use-global-sources", ref _configOptions.UseGlobalSources, "Toggles the use of the global NuGet sources (default is false).");
            syntax.DefineOption("packages-path", ref _configOptions.PackagesPath, DirectoryPath.FromString, "The packages path to use (only if use-local is true).");
            syntax.DefineOption("output-script", ref _configOptions.OutputScript, "Outputs the config script after it's been processed for further debugging.");
            syntax.DefineOption("verify-config", ref _verifyConfig, false, "Compile the configuration but do not execute.");
            syntax.DefineOption("noclean", ref _configOptions.NoClean, "Prevents cleaning of the output path on each execution.");
            syntax.DefineOption("nocache", ref _configOptions.NoCache, "Prevents caching information during execution (less memory usage but slower execution).");

            _logFilePath = $"wyam-{DateTime.Now:yyyyMMddHHmmssfff}.txt";
            if (!syntax.DefineOption("l|log", ref _logFilePath, FilePath.FromString, false, "Log all trace messages to the specified log file (by default, wyam-[datetime].txt).").IsSpecified)
            {
                _logFilePath = null;
            }

            // Metadata
            IReadOnlyList<string> globalMetadata = null;
            if (syntax.DefineOptionList("g|global", ref globalMetadata, "Specifies global metadata as a sequence of key=value pairs.").IsSpecified)
            {
                _configOptions.GlobalMetadata = MetadataParser.Parse(globalMetadata);
            }
            IReadOnlyList<string> initialMetadata = null;
            if (syntax.DefineOptionList("initial", ref initialMetadata, "Specifies initial document metadata as a sequence of key=value pairs.").IsSpecified)
            {
                _configOptions.InitialMetadata = MetadataParser.Parse(initialMetadata);
            }
        }
Beispiel #12
0
 protected override void Define(ArgumentSyntax syntax, Settings settings)
 {
     syntax.DefineOption("p|prerelease", ref settings.Prerelease, "Specifies that prerelease packages are allowed.");
     syntax.DefineOption("u|unlisted", ref settings.Unlisted, "Specifies that unlisted packages are allowed.");
     syntax.DefineOption("v|version", ref settings.VersionRange, "Specifies the version range of the package to use.");
     if (syntax.DefineOption("l|latest", ref settings.Latest, "Specifies that the latest available version of the package should be used (this will always trigger a request to the sources).").IsSpecified &&
         !string.IsNullOrEmpty(settings.VersionRange))
     {
         syntax.ReportError("latest cannot be specified if a version range is specified.");
     }
     syntax.DefineOptionList("s|source", ref settings.Sources, "Specifies the package source(s) to get the package from.");
     if (syntax.DefineOption("e|exclusive", ref settings.Exclusive, "Indicates that only the specified package source(s) should be used to find the package.").IsSpecified &&
         settings.Sources == null)
     {
         syntax.ReportError("exclusive can only be used if sources are specified.");
     }
     if (!syntax.DefineParameter("package", ref settings.Package, "The package to install.").IsSpecified)
     {
         syntax.ReportError("a package must be specified.");
     }
 }
Beispiel #13
0
            private void validate()
            {
                if (_basePath == null)
                {
                    _syntaxResult.ReportError("Base path (--base) is required.");
                }

                if (_diffPath == null)
                {
                    _syntaxResult.ReportError("Diff path (--diff) is required.");
                }

                if (_metric == null)
                {
                    _metric = "CodeSize";
                }

                if (!MetricCollection.ValidateMetric(_metric))
                {
                    _syntaxResult.ReportError($"Unknown metric '{_metric}'. Available metrics: {MetricCollection.ListMetrics()}");
                }
            }
Beispiel #14
0
 public static void AddContentTypes(IReadOnlyList <string> contentTypes, IDictionary <string, string> contentTypeDictionary, ArgumentSyntax syntax)
 {
     foreach (string contentType in contentTypes)
     {
         string[] splitContentType = contentType.Split('=');
         if (splitContentType.Length != 2)
         {
             syntax.ReportError($"Invalid content type {contentType} specified.");
             continue;
         }
         contentTypeDictionary[splitContentType[0].Trim().Trim('\"')] = splitContentType[1].Trim().Trim('\"');
     }
 }
Beispiel #15
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override void ValidateArguments(ArgumentSyntax arguments)
        {
            if (string.IsNullOrEmpty(_sourceFolderPath))
            {
                arguments.ReportError("microservice folder must be specified");
            }

            _sourceFolderPath = Path.GetFullPath(_sourceFolderPath);

            if (!Directory.Exists(_sourceFolderPath))
            {
                arguments.ReportError($"folder does not exist: {_sourceFolderPath}");
            }

            if (string.IsNullOrEmpty(_publishFolderPath))
            {
                _publishFolderPath = Path.Combine(_sourceFolderPath, DefaultPulishSubFolder);
            }

            _publishFolderPath = Path.GetFullPath(_publishFolderPath);

            if (!Directory.Exists(_publishFolderPath))
            {
                Directory.CreateDirectory(_publishFolderPath);
            }

            if (string.IsNullOrEmpty(_environmentFilePath))
            {
                _environmentFilePath = Path.Combine(_sourceFolderPath, BootConfiguration.EnvironmentConfigFileName);
            }

            _environmentFilePath = Path.GetFullPath(_environmentFilePath);

            if (!File.Exists(_environmentFilePath))
            {
                arguments.ReportError($"environment file does not exist: {_environmentFilePath}");
            }
        }
        public static T GetParameter<T>(this ArgumentSyntax syntax, string name, bool isRequired = false)
        {
            var firstName = name.Split('|').First();
            var values = syntax.GetActiveArguments()
                .OfType<Argument<T>>()
                .Where(a => firstName.Equals(a.Name, StringComparison.Ordinal))
                .Select(a => a.Value);

            if (isRequired && values.All(v => Equals(v, default(T))))
            {
                syntax.ReportError(string.Format(Strings.ErrorParameterMissing, name));
            }

            return values.FirstOrDefault();
        }
Beispiel #17
0
        // Validate supported scenarios
        //
        //    Scenario 1:  --base and --diff
        //       Pass two tools in and generate a set of disassembly with each.  Result directories
        //       will be tagged with "base" and "diff" in the output dir.
        //
        //    Scenario 2:  --base or --diff with --tag
        //       Pass single tool as either --base or --diff and tag the result directory with a user
        //       supplied tag.
        //
        private void validate()
        {
            if ((_baseExe == null) && (_diffExe == null))
            {
                _syntaxResult.ReportError("Specify --base and/or --diff.");
            }

            if ((_tag != null) && (_diffExe != null) && (_baseExe != null))
            {
                _syntaxResult.ReportError("Multiple compilers with the same tag: Specify --diff OR --base seperatly with --tag (one compiler for one tag).");
            }

            if ((_fileName == null) && (_assemblyList.Count == 0))
            {
                _syntaxResult.ReportError("No input: Specify --file <arg> or list input assemblies.");
            }

            // Check that we can find the baseExe.
            if (_baseExe != null)
            {
                if (!File.Exists(_baseExe))
                {
                    _syntaxResult.ReportError("Can't find --base tool.");
                }
                else
                {
                    // Set to full path for the command resolution logic.
                    string fullBasePath = Path.GetFullPath(_baseExe);
                    _baseExe = fullBasePath;
                }
            }

            // Check that we can find the diffExe.
            if (_diffExe != null)
            {
                if (!File.Exists(_diffExe))
                {
                    _syntaxResult.ReportError("Can't find --diff tool.");
                }
                else
                {
                    // Set to full path for command resolution logic.
                    string fullDiffPath = Path.GetFullPath(_diffExe);
                    _diffExe = fullDiffPath;
                }
            }

            if (_fileName != null)
            {
                if (!File.Exists(_fileName))
                {
                    var message = String.Format("Error reading input file {0}, file not found.", _fileName);
                    _syntaxResult.ReportError(message);
                }
            }
        }
Beispiel #18
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private static ICommand FindActiveCommand(ArgumentSyntax arguments)
        {
            ICommand activeCommand = null;

            if (arguments.ActiveCommand != null)
            {
                activeCommand = _s_commands
                                .FirstOrDefault(
                    c => string.Equals(c.Name, arguments.ActiveCommand.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (activeCommand == null)
            {
                arguments.ReportError("Command not understood.");
            }

            return(activeCommand);
        }
Beispiel #19
0
 // Used by both build and new
 protected static void ParseRootPathParameter(ArgumentSyntax syntax, ConfigOptions configOptions)
 {
     if (syntax.DefineParameter("root", ref configOptions.RootPath, DirectoryPathFromArg, "The folder (or config file) to use.").IsSpecified)
     {
         // If a root folder was defined, but it actually points to a file, set the root folder to the directory
         // and use the specified file as the config file (if a config file was already specified, it's an error)
         FilePath rootDirectoryPathAsConfigFile = new DirectoryPath(Environment.CurrentDirectory).CombineFile(configOptions.RootPath.FullPath);
         if (System.IO.File.Exists(rootDirectoryPathAsConfigFile.FullPath))
         {
             // The specified root actually points to a file...
             if (configOptions.ConfigFilePath != null)
             {
                 syntax.ReportError("A config file was both explicitly specified and specified in the root folder.");
             }
             else
             {
                 configOptions.ConfigFilePath = rootDirectoryPathAsConfigFile.FileName;
                 configOptions.RootPath       = rootDirectoryPathAsConfigFile.Directory;
             }
         }
     }
 }
Beispiel #20
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override void ValidateArguments(ArgumentSyntax arguments)
        {
            if (string.IsNullOrEmpty(_microserviceFolderPath))
            {
                arguments.ReportError("microservice folder must be specified");
            }

            _microserviceFolderPath = Path.GetFullPath(_microserviceFolderPath);

            if (!Directory.Exists(_microserviceFolderPath))
            {
                arguments.ReportError($"folder does not exist: {_microserviceFolderPath}");
            }

            if (string.IsNullOrEmpty(_microserviceFilePath))
            {
                _microserviceFilePath = Path.Combine(_microserviceFolderPath, BootConfiguration.MicroserviceConfigFileName);
            }

            if (!File.Exists(_microserviceFilePath))
            {
                arguments.ReportError($"file does not exist: {_microserviceFilePath}");
            }

            if (string.IsNullOrEmpty(_environmentFilePath))
            {
                _environmentFilePath = Path.Combine(_microserviceFolderPath, BootConfiguration.EnvironmentConfigFileName);
            }

            if (!File.Exists(_environmentFilePath))
            {
                arguments.ReportError($"file does not exist: {_environmentFilePath}");
            }

            if (!DetermineFolderType(out _microserviceFolderType))
            {
                arguments.ReportError("specified microservice folder is neither source nor publish");
            }

            if (_noPublish && _microserviceFolderType != MicroserviceFolderType.Source)
            {
                arguments.ReportError("--no-publish cannot be used with a published microservice");
            }
        }
Beispiel #21
0
            private void ValidateDiff()
            {
                if (_platformPath == null)
                {
                    _syntaxResult.ReportError("Specifiy --core_root <path>");
                }

                if ((_corlibOnly == false) &&
                    (_frameworksOnly == false) && (_testPath == null))
                {
                    _syntaxResult.ReportError("Specify --test_root <path>");
                }

                if (_outputPath == null)
                {
                    _syntaxResult.ReportError("Specify --output <path>");
                }

                if ((_baseExe == null) && (_diffExe == null))
                {
                    _syntaxResult.ReportError("--base <path> or --diff <path> or both must be specified.");
                }
            }
Beispiel #22
0
            private void validate()
            {
                if (_arch == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Defaulting architecture to x64.");
                    }
                    _arch = "x64";
                }

                if (_build == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Defaulting build to Debug.");
                    }

                    _build = "Debug";
                }

                if (_os == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Discovering operating system.");
                    }

                    SetPlatform();

                    if (_verbose)
                    {
                        Console.WriteLine("Operating system is {0}", _os);
                    }
                }

                if (_srcDirectory == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Formatting jit directory.");
                    }
                    _srcDirectory = "jit";
                }

                if (_projects.Count == 0 && _verbose)
                {
                    Console.WriteLine("Formatting dll project.");
                }

                if (!_untidy && ((_arch == null) || (_os == null) || (_build == null)))
                {
                    _syntaxResult.ReportError("Specify --arch, --os, and --build for clang-tidy run.");
                }

                if (_rootPath == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Discovering --coreclr.");
                    }
                    _rootPath = Utility.GetRepoRoot(_verbose);
                    _rootPath = Path.Combine(_rootPath, "src", "coreclr");
                    if (_rootPath == null)
                    {
                        _syntaxResult.ReportError("Specify --coreclr");
                    }
                    else
                    {
                        Console.WriteLine("Using --coreclr={0}", _rootPath);
                    }
                }

                if (!Directory.Exists(_rootPath))
                {
                    // If _rootPath doesn't exist, it is an invalid path
                    _syntaxResult.ReportError("Invalid path to coreclr directory. Specify with --coreclr");
                }
                else if (!File.Exists(Path.Combine(_rootPath, "build-runtime.cmd")) || !File.Exists(Path.Combine(_rootPath, "build-runtime.sh")) || !File.Exists(Path.Combine(_rootPath, "clr.featuredefines.props")))
                {
                    // Doesn't look like the coreclr directory.
                    _syntaxResult.ReportError("Invalid path to coreclr directory. Specify with --coreclr");
                }

                // Check that we can find compile_commands.json on windows
                if (_os.ToLower() == "windows")
                {
                    // If the user didn't specify a compile_commands.json, we need to see if one exists, and if not, create it.
                    if (!_untidy && _compileCommands == null)
                    {
                        // Check both the nmakeobj and obj paths for back-compat with the old Ninja/NMake output dir.
                        string[] nmakeObjCompileCommandsPathSegments = { _rootPath, "..", "..", "artifacts", "nmakeobj", _os + "." + _arch + "." + _build, "compile_commands.json" };
                        string[] compileCommandsPathSegments         = { _rootPath, "..", "..", "artifacts", "obj", "coreclr", _os + "." + _arch + "." + _build, "compile_commands.json" };
                        string   nmakeObjCompileCommands             = Path.Combine(nmakeObjCompileCommandsPathSegments);
                        string   compileCommandsPath = Path.Combine(compileCommandsPathSegments);
                        _rewriteCompileCommands = true;

                        if (File.Exists(compileCommandsPath))
                        {
                            _compileCommands = compileCommandsPath;
                        }
                        else if (File.Exists(nmakeObjCompileCommands))
                        {
                            _compileCommands = nmakeObjCompileCommands;
                        }
                        else
                        {
                            // We haven't done a build, so we need to do one.
                            if (_verbose)
                            {
                                Console.WriteLine("Neither compile_commands.json exists, nor is there a build log. Running CMake to generate compile_commands.json.");
                            }

                            string[] commandArgs = { _arch, _build, "-configureonly", "-ninja" };
                            string   buildPath   = Path.Combine(_rootPath, "build-runtime.cmd");

                            if (_verbose)
                            {
                                Console.WriteLine("Running: {0} {1}", buildPath, String.Join(" ", commandArgs));
                            }

                            ProcessResult result = Utility.ExecuteProcess(buildPath, commandArgs, !_verbose, _rootPath);

                            if (result.ExitCode != 0)
                            {
                                Console.WriteLine("There was an error running CMake to generate compile_commands.json. Please do a full build to generate a build log.");
                                Environment.Exit(-1);
                            }

                            if (File.Exists(compileCommandsPath))
                            {
                                _compileCommands = compileCommandsPath;
                            }
                            else if (File.Exists(nmakeObjCompileCommands))
                            {
                                _compileCommands = nmakeObjCompileCommands;
                            }
                            else
                            {
                                Console.WriteLine("CMake ran successfully, but no compile_commmands.json was generated.");
                                Environment.Exit(-1);
                            }
                        }
                    }
                }

                // Check that we can find the compile_commands.json file on other platforms
                else
                {
                    // If the user didn't specify a compile_commands.json, we need to see if one exists, and if not, create it.
                    if (!_untidy && _compileCommands == null)
                    {
                        string[] compileCommandsPath = { _rootPath, "..", "..", "artifacts", "obj", "coreclr", _os + "." + _arch + "." + _build, "compile_commands.json" };
                        _compileCommands        = Path.Combine(compileCommandsPath);
                        _rewriteCompileCommands = true;

                        if (!File.Exists(Path.Combine(compileCommandsPath)))
                        {
                            Console.WriteLine("Can't find compile_commands.json file. Running configure.");
                            string[] commandArgs = { _arch, _build, "configureonly", "-cmakeargs", "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" };
                            string   buildPath   = Path.Combine(_rootPath, "build-runtime.sh");

                            if (_verbose)
                            {
                                Console.WriteLine("Running: {0} {1}", buildPath, String.Join(" ", commandArgs));
                            }

                            ProcessResult result = Utility.ExecuteProcess(buildPath, commandArgs, true, _rootPath);

                            if (result.ExitCode != 0)
                            {
                                Console.WriteLine("There was an error running CMake to generate compile_commands.json. Please run build-runtime.sh configureonly");
                                Environment.Exit(-1);
                            }
                        }
                    }
                }
            }
Beispiel #23
0
 protected override void ParseParameters(ArgumentSyntax syntax)
 {
     // Root
     if (syntax.DefineParameter("root", ref _configOptions.RootPath, DirectoryPath.FromString, "The folder (or config file) to use.").IsSpecified)
     {
         // If a root folder was defined, but it actually points to a file, set the root folder to the directory
         // and use the specified file as the config file (if a config file was already specified, it's an error)
         FilePath rootDirectoryPathAsConfigFile = new DirectoryPath(Environment.CurrentDirectory).CombineFile(_configOptions.RootPath.FullPath);
         if (File.Exists(rootDirectoryPathAsConfigFile.FullPath))
         {
             // The specified root actually points to a file...
             if (_configOptions.ConfigFilePath != null)
             {
                 syntax.ReportError("A config file was both explicitly specified and specified in the root folder.");
             }
             else
             {
                 _configOptions.ConfigFilePath = rootDirectoryPathAsConfigFile.FileName;
                 _configOptions.RootPath = rootDirectoryPathAsConfigFile.Directory;
             }
         }
     }
 }
Beispiel #24
0
            private void validate()
            {
                if (_arch == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Defaulting architecture to x64.");
                    }
                    _arch = "x64";
                }

                if (_build == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Defaulting build to Debug.");
                    }

                    _build = "Debug";
                }

                if (_os == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Discovering operating system.");
                    }

                    SetPlatform();

                    if (_verbose)
                    {
                        Console.WriteLine("Operating system is {0}", _os);
                    }
                }

                if (_os == "Windows")
                {
                    _os = "Windows_NT";
                }

                if (_srcDirectory == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Formatting jit directory.");
                    }
                    _srcDirectory = "jit";
                }

                if (_projects.Count == 0 && _verbose)
                {
                    Console.WriteLine("Formatting dll project.");
                }

                if (!_untidy && ((_arch == null) || (_os == null) || (_build == null)))
                {
                    _syntaxResult.ReportError("Specify --arch, --plaform, and --build for clang-tidy run.");
                }

                if (_rootPath == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Discovering --coreclr.");
                    }
                    _rootPath = Utility.GetRepoRoot(_verbose);
                    if (_rootPath == null)
                    {
                        _syntaxResult.ReportError("Specify --coreclr");
                    }
                    else
                    {
                        Console.WriteLine("Using --coreclr={0}", _rootPath);
                    }
                }

                if (!Directory.Exists(_rootPath))
                {
                    // If _rootPath doesn't exist, it is an invalid path
                    _syntaxResult.ReportError("Invalid path to coreclr directory. Specify with --coreclr");
                }
                else if (!File.Exists(Path.Combine(_rootPath, "build.cmd")) || !File.Exists(Path.Combine(_rootPath, "build.sh")))
                {
                    // If _rootPath\build.cmd or _rootPath\build.sh do not exist, it is an invalid path to a coreclr repo
                    _syntaxResult.ReportError("Invalid path to coreclr directory. Specify with --coreclr");
                }

                // Check that we can find compile_commands.json on windows
                if (_os == "Windows_NT")
                {
                    // If the user didn't specify a compile_commands.json, we need to see if one exists, and if not, create it.
                    if (!_untidy && _compileCommands == null)
                    {
                        string[] compileCommandsPath = { _rootPath, "bin", "nmakeobj", "Windows_NT." + _arch + "." + _build, "compile_commands.json" };
                        _compileCommands        = Path.Combine(compileCommandsPath);
                        _rewriteCompileCommands = true;

                        if (!File.Exists(_compileCommands))
                        {
                            // We haven't done a build, so we need to do one.
                            if (_verbose)
                            {
                                Console.WriteLine("Neither compile_commands.json exists, nor is there a build log. Running CMake to generate compile_commands.json.");
                            }

                            string[]      commandArgs = { _arch, _build, "usenmakemakefiles" };
                            string        buildPath   = Path.Combine(_rootPath, "build.cmd");
                            CommandResult result      = Utility.TryCommand(buildPath, commandArgs, !_verbose, _rootPath);

                            if (result.ExitCode != 0)
                            {
                                Console.WriteLine("There was an error running CMake to generate compile_commands.json. Please do a full build to generate a build log.");
                                Environment.Exit(-1);
                            }
                        }
                    }
                }

                // Check that we can find the compile_commands.json file on other platforms
                else
                {
                    // If the user didn't specify a compile_commands.json, we need to see if one exists, and if not, create it.
                    if (!_untidy && _compileCommands == null)
                    {
                        string[] compileCommandsPath = { _rootPath, "bin", "obj", _os + "." + _arch + "." + _build, "compile_commands.json" };
                        _compileCommands        = Path.Combine(compileCommandsPath);
                        _rewriteCompileCommands = true;

                        if (!File.Exists(Path.Combine(compileCommandsPath)))
                        {
                            Console.WriteLine("Can't find compile_commands.json file. Running configure.");
                            string[]      commandArgs = { _arch, _build, "configureonly" };
                            string        buildPath   = Path.Combine(_rootPath, "build.sh");
                            CommandResult result      = Utility.TryCommand(buildPath, commandArgs, true, _rootPath);

                            if (result.ExitCode != 0)
                            {
                                Console.WriteLine("There was an error running CMake to generate compile_commands.json. Please run build.sh configureonly");
                                Environment.Exit(-1);
                            }
                        }
                    }
                }
            }
Beispiel #25
0
        // Validate arguments
        //
        // Pass a single tool as --crossgen. Optionally specify a jit for crossgen to use.
        //
        private void Validate()
        {
            if (_crossgenExe == null)
            {
                _syntaxResult.ReportError("Specify --crossgen.");
            }

            if ((_fileName == null) && (_assemblyList.Count == 0))
            {
                _syntaxResult.ReportError("No input: Specify --file <arg> or list input assemblies.");
            }

            // Check that we can find the crossgenExe
            if (_crossgenExe != null)
            {
                if (!File.Exists(_crossgenExe))
                {
                    _syntaxResult.ReportError("Can't find --crossgen tool.");
                }
                else
                {
                    // Set to full path for command resolution logic.
                    string fullCrossgenPath = Path.GetFullPath(_crossgenExe);
                    _crossgenExe = fullCrossgenPath;

                    switch (Path.GetFileNameWithoutExtension(fullCrossgenPath).ToLower())
                    {
                    case "crossgen":
                        _codeGenerator = CodeGenerator.Crossgen;
                        break;

                    case "crossgen2":
                        _codeGenerator = CodeGenerator.Crossgen2;
                        break;

                    default:
                        _syntaxResult.ReportError("--crossgen tool should be crossgen or crossgen2.");
                        break;
                    }
                }
            }

            // Check that we can find the jit library.
            if (_jitPath != null)
            {
                if (!File.Exists(_jitPath))
                {
                    _syntaxResult.ReportError("Can't find --jit library.");
                }
                else
                {
                    // Set to full path for command resolution logic.
                    string fullJitPath = Path.GetFullPath(_jitPath);
                    _jitPath = fullJitPath;
                }
            }

            if (_fileName != null)
            {
                if (!File.Exists(_fileName))
                {
                    var message = String.Format("Error reading input file {0}, file not found.", _fileName);
                    _syntaxResult.ReportError(message);
                }
            }
        }
Beispiel #26
0
            private void validate()
            {
                if (!Uri.IsWellFormedUriString(_server, UriKind.Absolute))
                {
                    _syntaxResult.ReportError($"Invalid uri: {_server}.");
                }
                switch (_command)
                {
                case Command.List:
                {
                    validateList();
                }
                break;

                case Command.Copy:
                {
                    validateCopy();
                }
                break;
                }
            }
Beispiel #27
0
        protected override void ParseOptions(ArgumentSyntax syntax)
        {
            syntax.DefineOption("w|watch", ref _watch, "Watches the input folder for any changes.");
            _preview = syntax.DefineOption("p|preview", ref _previewPort, false, "Start the preview web server on the specified port (default is " + _previewPort + ").").IsSpecified;
            if (syntax.DefineOption("force-ext", ref _previewForceExtension, "Force the use of extensions in the preview web server (by default, extensionless URLs may be used).").IsSpecified&& !_preview)
            {
                syntax.ReportError("force-ext can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("virtual-dir", ref _previewVirtualDirectory, DirectoryPathFromArg, "Serve files in the preview web server under the specified virtual directory.").IsSpecified&& !_preview)
            {
                syntax.ReportError("virtual-dir can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("preview-root", ref _previewRoot, DirectoryPathFromArg, "The path to the root of the preview server, if not the output folder.").IsSpecified&& !_preview)
            {
                syntax.ReportError("preview-root can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("noreload", ref _noReload, "Turns off LiveReload support in the preview server.").IsSpecified&& (!_preview || !_watch))
            {
                syntax.ReportError("noreload can only be specified if both the preview server is running and watching is enabled.");
            }
            IReadOnlyList <string> contentTypes = null;

            if (syntax.DefineOptionList("content-type", ref contentTypes, "Specifies additional supported content types for the preview server as extension=contenttype.").IsSpecified)
            {
                if (!_preview)
                {
                    syntax.ReportError("content-type can only be specified if the preview server is running.");
                }
                else
                {
                    PreviewCommand.AddContentTypes(contentTypes, _contentTypes, syntax);
                }
            }
            syntax.DefineOptionList("i|input", ref _configOptions.InputPaths, DirectoryPathFromArg, "The path(s) of input files, can be absolute or relative to the current folder.");
            syntax.DefineOption("o|output", ref _configOptions.OutputPath, DirectoryPathFromArg, "The path to output files, can be absolute or relative to the current folder.");
            syntax.DefineOption("c|config", ref _configOptions.ConfigFilePath, FilePath.FromString, "Configuration file (by default, config.wyam is used).");
            syntax.DefineOption("u|update-packages", ref _configOptions.UpdatePackages, "Check the NuGet server for more recent versions of each package and update them if applicable.");
            syntax.DefineOption("use-local-packages", ref _configOptions.UseLocalPackages, "Toggles the use of a local NuGet packages folder.");
            syntax.DefineOption("use-global-sources", ref _configOptions.UseGlobalSources, "Toggles the use of the global NuGet sources (default is false).");
            syntax.DefineOption("ignore-default-sources", ref _configOptions.IgnoreDefaultSources, "Ignores default NuGet sources like the NuGet Gallery (default is false).");
            syntax.DefineOption("packages-path", ref _configOptions.PackagesPath, DirectoryPathFromArg, "The packages path to use (only if use-local is true).");

            syntax.DefineOption("no-output-config-assembly", ref _configOptions.NoOutputConfigAssembly, "Disable caching configuration file compulation.");
            syntax.DefineOption("ignore-config-hash", ref _configOptions.IgnoreConfigHash, "Force evaluating the configuration file, even when no changes were detected.");
            syntax.DefineOption("output-script", ref _configOptions.OutputScript, "Outputs the config script after it's been processed for further debugging. The directive --ignore-config-hash is required when using this option.");
            syntax.DefineOption("verify-config", ref _verifyConfig, false, "Compile the configuration but do not execute. The directive --ignore-config-hash is required when using this option.");

            if (_configOptions.OutputScript && !_configOptions.IgnoreConfigHash)
            {
                syntax.ReportError("The directive --output-script can only be specified if --ignore-config-hash is also specified.");
            }
            if (_verifyConfig && !_configOptions.IgnoreConfigHash)
            {
                syntax.ReportError("The directive --verify-config can only be specified if --ignore-config-hash is also specified.");
            }

            syntax.DefineOption("noclean", ref _configOptions.NoClean, "Prevents cleaning of the output path on each execution.");
            syntax.DefineOption("nocache", ref _configOptions.NoCache, "Prevents caching information during execution (less memory usage but slower execution).");

            _logFilePath = $"wyam-{DateTime.Now:yyyyMMddHHmmssfff}.txt";
            if (!syntax.DefineOption("l|log", ref _logFilePath, FilePath.FromString, false, "Log all trace messages to the specified log file (by default, wyam-[datetime].txt).").IsSpecified)
            {
                _logFilePath = null;
            }

            // Metadata
            // TODO: Remove this dictionary and initial/global options
            Dictionary <string, object> settingsDictionary = new Dictionary <string, object>();
            IReadOnlyList <string>      globalMetadata     = null;

            if (syntax.DefineOptionList("g|global", ref globalMetadata, "Deprecated, do not use.").IsSpecified)
            {
                Trace.Warning("-g/--global is deprecated and will be removed in a future version. Please use -s/--setting instead.");
                AddSettings(settingsDictionary, globalMetadata);
            }
            IReadOnlyList <string> initialMetadata = null;

            if (syntax.DefineOptionList("initial", ref initialMetadata, "Deprecated, do not use.").IsSpecified)
            {
                Trace.Warning("--initial is deprecated and will be removed in a future version. Please use -s/--setting instead.");
                AddSettings(settingsDictionary, initialMetadata);
            }
            IReadOnlyList <string> settings = null;

            if (syntax.DefineOptionList("s|setting", ref settings, "Specifies a setting as a key=value pair. Use the syntax [x,y] to specify an array value.").IsSpecified)
            {
                // _configOptions.Settings = MetadataParser.Parse(settings); TODO: Use this when AddSettings() is removed

                AddSettings(settingsDictionary, settings);
            }
            if (settingsDictionary.Count > 0)
            {
                _configOptions.Settings = settingsDictionary;
            }
        }