Example #1
0
 public Parser(CommandLineConfiguration configuration)
 {
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
        internal static TokenizeResult Tokenize(
            this IReadOnlyList <string> args,
            CommandLineConfiguration configuration)
        {
            var tokenList = new List <Token>();
            var errorList = new List <TokenizeError>();

            ICommand?currentCommand       = null;
            var      foundEndOfArguments  = false;
            var      foundEndOfDirectives = !configuration.EnableDirectives;
            var      argList = NormalizeRootCommand(configuration, args);

            var argumentDelimiters = configuration.ArgumentDelimitersInternal.ToArray();

            var knownTokens = configuration.RootCommand.ValidTokens();

            for (var i = 0; i < argList.Count; i++)
            {
                var arg = argList[i];

                if (foundEndOfArguments)
                {
                    tokenList.Add(Operand(arg));
                    continue;
                }

                if (arg == "--")
                {
                    tokenList.Add(EndOfArguments());
                    foundEndOfArguments = true;
                    continue;
                }

                if (!foundEndOfDirectives)
                {
                    if (arg.StartsWith("[") &&
                        arg.EndsWith("]") &&
                        arg[1] != ']' &&
                        arg[1] != ':')
                    {
                        tokenList.Add(Directive(arg));
                        continue;
                    }

                    if (!configuration.RootCommand.HasAlias(arg))
                    {
                        foundEndOfDirectives = true;
                    }
                }

                if (configuration.ResponseFileHandling != ResponseFileHandling.Disabled &&
                    arg.GetResponseFileReference() is { } filePath)
                {
                    ReadResponseFile(filePath, i);
                    continue;
                }

                if (configuration.EnablePosixBundling &&
                    CanBeUnbundled(arg, out IReadOnlyCollection <string>?replacement))
                {
                    argList.InsertRange(i + 1, replacement);
                    argList.RemoveAt(i);
                    arg = argList[i];
                }

                if (arg.TrySplitIntoSubtokens(argumentDelimiters,
                                              out var first,
                                              out var rest))
                {
                    if (knownTokens.TryGetValue(first !, out var token) &&
                        token.Type == TokenType.Option)
                    {
                        tokenList.Add(Option(first !));

                        // trim outer quotes in case of, e.g., -x="why"
                        var secondPartWithOuterQuotesRemoved = rest !.Trim('"');
                        tokenList.Add(Argument(secondPartWithOuterQuotesRemoved));
                    }
Example #3
0
        internal static TokenizeResult Tokenize(
            this IReadOnlyList <string> args,
            CommandLineConfiguration configuration,
            bool inferRootCommand = true)
        {
            var errorList = new List <string>();

            var currentCommand       = configuration.RootCommand;
            var foundDoubleDash      = false;
            var foundEndOfDirectives = !configuration.EnableDirectives;

            var argList = NormalizeRootCommand(args, configuration.RootCommand, inferRootCommand);

            var tokenList = new List <Token>(argList.Count);

            var knownTokens = configuration.RootCommand.ValidTokens();

            for (var i = 0; i < argList.Count; i++)
            {
                var arg = argList[i];

                if (foundDoubleDash)
                {
                    tokenList.Add(CommandArgument(arg, currentCommand !));

                    continue;
                }

                if (!foundDoubleDash &&
                    arg == "--")
                {
                    tokenList.Add(DoubleDash());
                    foundDoubleDash = true;
                    continue;
                }

                if (!foundEndOfDirectives)
                {
                    if (arg.Length > 2 &&
                        arg[0] == '[' &&
                        arg[1] != ']' &&
                        arg[1] != ':' &&
                        arg.EndsWith("]", StringComparison.Ordinal))
                    {
                        tokenList.Add(Directive(arg));
                        continue;
                    }

                    if (!configuration.RootCommand.HasAlias(arg))
                    {
                        foundEndOfDirectives = true;
                    }
                }

                if (configuration.EnableTokenReplacement &&
                    configuration.TokenReplacer is { } replacer&&
                    arg.GetReplaceableTokenValue() is { } value)
                {
                    if (replacer(
                            value,
                            out var newTokens,
                            out var error))
                    {
                        argList.InsertRange(i + 1, newTokens ?? Array.Empty <string>());
                        continue;
                    }
Example #4
0
 protected virtual void UpdateConfiguration(CommandLineConfiguration config)
 {
 }
Example #5
0
        private static ICommandLineConfiguration CreateConfiguration(
            IEnumerable <string> sdksToResolve,
            PathTable pathTable,
            AbsolutePath testFolderPath)
        {
            var configFilePath  = testFolderPath.Combine(pathTable, Names.ConfigDsc);
            var packageFilePath = testFolderPath.Combine(pathTable, Names.ModuleConfigBm);

            var sdkPackages = sdksToResolve
                              .SelectMany(folder =>
                                          Directory.EnumerateFiles(folder, Names.PackageConfigDsc, SearchOption.AllDirectories).Concat(
                                              Directory.EnumerateFiles(folder, Names.ModuleConfigBm, SearchOption.AllDirectories).Concat(
                                                  Directory.EnumerateFiles(folder, Names.ModuleConfigDsc, SearchOption.AllDirectories))))
                              .Select(packageFile => AbsolutePath.Create(pathTable, packageFile))
                              .ToList();

            var configuration =
                new CommandLineConfiguration
            {
                // Have to new up the list because we have some bad semantics dealing with the list being null or not.
                Packages = new List <AbsolutePath>
                {
                    packageFilePath,
                },
                Resolvers =
                {
                    new SourceResolverSettings
                    {
                        Kind    = "SourceResolver",
                        Modules = sdkPackages,
                    },
                },
                FrontEnd =
                {
                    MaxFrontEndConcurrency                 =                                                 1, // Single threaded for deterministic evaluation

                    NameResolutionSemantics                = NameResolutionSemantics.ImplicitProjectReferences,

                    // PreserveFullNames = true, Some comment in code as not to turn on, check with folks....
                    UsePartialEvaluation                   = true,
                    UseSpecPublicFacadeAndAstWhenAvailable = false,
                    ConstructAndSaveBindingFingerprint     = false,
                    // Some of the DS tests fail when incremental frontend is not used
                    EnableIncrementalFrontEnd              = true,
                },
                Engine =
                {
                    TrackBuildsInUserFolder = false,
                },
                Layout =
                {
                    OutputDirectory   = testFolderPath.Combine(pathTable, "Out"),
                    ObjectDirectory   = testFolderPath.Combine(pathTable, "Out").Combine(pathTable, "Objects"),
                    PrimaryConfigFile = configFilePath,
                    SourceDirectory   = testFolderPath,
                    TempDirectory     = testFolderPath.Combine(pathTable, "Out").Combine(pathTable, "Temp"),
                },
                Mounts =
                {
                },
                Startup =
                {
                    ConfigFile = configFilePath,
                },
            };

            return(configuration);
        }
Example #6
0
        private GraphReuseResult ReloadPipGraphOnly(
            EngineSerializer serializer,
            LoggingContext loggingContext,
            EngineState engineState,
            InputTracker.InputChanges inputChanges)
        {
            Tuple <PipGraph, EngineContext> t = null;

            try
            {
                t = EngineSchedule.LoadPipGraphAsync(
                    Context,
                    serializer,
                    Configuration,
                    loggingContext,
                    engineState).GetAwaiter().GetResult();
            }
            catch (BuildXLException e)
            {
                Logger.Log.FailedReloadPipGraph(loggingContext, e.ToString());
            }

            if (t == null)
            {
                return(GraphReuseResult.CreateForNoReuse(inputChanges));
            }

            var newContext = t.Item2;

            if (!ShouldReuseReloadedEngineContextGivenHistoricData(loggingContext, newContext.NextHistoricTableSizes))
            {
                return(GraphReuseResult.CreateForNoReuse(inputChanges));
            }

            var newPathTable = newContext.PathTable;
            var pathRemapper = new PathRemapper(Context.PathTable, newPathTable);

            Configuration = new ConfigurationImpl(Configuration, pathRemapper);

            m_initialCommandLineConfiguration = new CommandLineConfiguration(m_initialCommandLineConfiguration, pathRemapper);

            // Invalidate the old context to ensure nothing uses it anymore
            // Update engine state to deserialized state
            Context.Invalidate();
            Context = newContext;

            // Additionally recreate front end controller, because the old one uses the invalidated context.
            //   - to fully initialize the front end, we have to go through all the steps that have already been
            //     executed on the old controller; those steps are (1) InitializeHost, and (2) ParseConfig
            FrontEndController = m_frontEndControllerFactory.Create(Context.PathTable, Context.SymbolTable);
            FrontEndController.InitializeHost(Context.ToFrontEndContext(loggingContext), m_initialCommandLineConfiguration);

            var configurationEngine = new BasicFrontEndEngineAbstraction(Context.PathTable, Context.FileSystem, m_initialCommandLineConfiguration);

            if (!configurationEngine.TryPopulateWithDefaultMountsTable(loggingContext, Context, m_initialCommandLineConfiguration, m_initialCommandLineConfiguration.Startup.Properties))
            {
                Contract.Assert(loggingContext.ErrorWasLogged);
                return(null);
            }

            FrontEndController.ParseConfig(configurationEngine, m_initialCommandLineConfiguration);

            return(GraphReuseResult.CreateForPartialReuse(t.Item1, inputChanges));
        }
Example #7
0
        protected BaseEngineTest(ITestOutputHelper output)
            : base(output)
        {
            m_testOutput     = output;
            m_ignoreWarnings = OperatingSystemHelper.IsUnixOS; // ignoring /bin/sh is being used as a source file

            RegisterEventSource(global::BuildXL.Scheduler.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.FrontEnd.Script.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.FrontEnd.Core.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.Engine.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.Processes.ETWLogger.Log);

            ParseAndEvaluateLogger = Logger.CreateLogger();
            InitializationLogger   = InitializationLogger.CreateLogger();

            var pathTable = new PathTable();

            FileSystem = new PassThroughMutableFileSystem(pathTable);
            Context    = EngineContext.CreateNew(CancellationToken.None, pathTable, FileSystem);
            MainSourceResolverModules = new List <AbsolutePath>();

            var rootPath = AbsolutePath.Create(Context.PathTable, TestRoot);
            var logsPath = Combine(AbsolutePath.Create(Context.PathTable, TemporaryDirectory), "logs");

            Configuration = new CommandLineConfiguration()
            {
                DisableDefaultSourceResolver = true,
                Resolvers = new List <IResolverSettings>
                {
                    new SourceResolverSettings
                    {
                        Kind    = "SourceResolver",
                        Modules = MainSourceResolverModules,
                    },
                    new SourceResolverSettings
                    {
                        Kind    = "SourceResolver",
                        Modules = new List <AbsolutePath>
                        {
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Prelude", "package.config.dsc")),
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Transformers", "package.config.dsc")),
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Deployment", "module.config.dsc")),
                        },
                    },
                },
                Layout =
                {
                    SourceDirectory = rootPath,
                    OutputDirectory = Combine(rootPath,                             "out"),
                    ObjectDirectory = Combine(rootPath,                             "obj"),
                    CacheDirectory  = Combine(AbsolutePath.Create(Context.PathTable, TemporaryDirectory), "cache"),
                },
                Cache =
                {
                    CacheSpecs       = SpecCachingOption.Disabled,
                    CacheLogFilePath = logsPath.Combine(Context.PathTable,PathAtom.Create(Context.StringTable,  "cache.log")),
                },
                Engine =
                {
                    ReuseEngineState        = false,
                    LogStatistics           = false,
                    TrackBuildsInUserFolder = false,
                },
                FrontEnd =
                {
                    MaxFrontEndConcurrency =     1,
                    LogStatistics          = false,
                },
                Schedule =
                {
                    MaxIO        = 1,
                    MaxProcesses = 1,
                },
                Sandbox =
                {
                    FileSystemMode      = FileSystemMode.RealAndMinimalPipGraph,
                    OutputReportingMode = OutputReportingMode.FullOutputOnError,
                },
                Logging =
                {
                    LogsDirectory     = logsPath,
                    LogStats          = false,
                    LogExecution      = false,
                    LogCounters       = false,
                    LogMemory         = false,
                    StoreFingerprints = false,
                    NoWarnings        =
                    {
                        909,     // Disable warnings about experimental feature
                    },
                }
            };

            AbsolutePath Combine(AbsolutePath parent, string name)
            {
                return(parent.Combine(Context.PathTable, PathAtom.Create(Context.StringTable, name)));
            }
        }
Example #8
0
        private static void ShowUsage(CommandLineConfiguration configuration, string parseResult = "")
        {
            Usage usage = new UsageComposer(configuration).Compose();

            if (String.IsNullOrEmpty(parseResult))
            {
                var build = ((AssemblyInformationalVersionAttribute)Assembly
                             .GetAssembly(typeof(Program))
                             .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
                            .InformationalVersion;
                Console.WriteLine(@"
 ██▓███  ▓█████  ██▀███   ▄████▄   ██▓ ██▓███        ██▓ ▒█████  
▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒▒██▀ ▀█  ▓██▒▓██░  ██▒     ▓██▒▒██▒  ██▒
▓██░ ██▓▒▒███   ▓██ ░▄█ ▒▒▓█    ▄ ▒██▒▓██░ ██▓▒     ▒██▒▒██░  ██▒
▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄  ▒▓▓▄ ▄██▒░██░▒██▄█▓▒ ▒     ░██░▒██   ██░
▒██▒ ░  ░░▒████▒░██▓ ▒██▒▒ ▓███▀ ░░██░▒██▒ ░  ░ ██▓ ░██░░ ████▓▒░
▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░░ ░▒ ▒  ░░▓  ▒▓▒░ ░  ░ ▒▓▒ ░▓  ░ ▒░▒░▒░ 
░▒ ░      ░ ░  ░  ░▒ ░ ▒░  ░  ▒    ▒ ░░▒ ░      ░▒   ▒ ░  ░ ▒ ▒░ 
░░          ░     ░░   ░ ░         ▒ ░░░        ░    ▒ ░░ ░ ░ ▒  
            ░  ░   ░     ░ ░       ░             ░   ░      ░ ░  
                         ░                       ░               
Percip.io {0} - The working time logger by antic_eye ;)

Use this tool to track your productivity. MyLock generates an
encrypted database file that contains timestamps and ""in""
or ""out"".

When you call myLock with ""lock"" it tracks:
01.01.2016T08: 15 Max.Mustermann Out

When you call without args it tracks:
01.01.2016T08: 19 Max.Mustermann In

When you want to show your times, call it with ""--query"".It will
read the db and calculate your working time beginning with the
first ""in"" per day, ending with the last ""out"".

To automate the tracking, use ""--init"" and myLock will generate
Windows Scheduled tasks for screen lock/unlock and session
login/-out. You will need administrative permissions for this
task. Open an elevated command prompt.

", build);
                Console.WriteLine("Usage: percip.io.exe {0}", usage.Arguments);
                Console.WriteLine();
                Console.WriteLine(usage.Options);
                Console.WriteLine("Exit codes:");

                foreach (var e in Enum.GetValues(typeof(ExitCode)))
                {
                    Console.WriteLine(string.Format("{0,4}\t{1}",
                                                    (int)e,
                                                    e.ToString()));
                }
            }
            else
            {
                Console.WriteLine(parseResult);
                Console.WriteLine();
            }
        }
        internal static TokenizeResult Tokenize(
            this IReadOnlyList <string> args,
            CommandLineConfiguration configuration)
        {
            var tokenList = new List <Token>();
            var errorList = new List <TokenizeError>();

            ICommand currentCommand       = null;
            var      foundEndOfArguments  = false;
            var      foundEndOfDirectives = !configuration.EnableDirectives;
            var      argList = NormalizeRootCommand(configuration, args);

            var argumentDelimiters = configuration.ArgumentDelimiters.ToArray();

            var knownTokens        = new HashSet <Token>(configuration.Symbols.SelectMany(ValidTokens));
            var knownTokensStrings = new HashSet <string>(knownTokens.Select(t => t.Value));

            for (var i = 0; i < argList.Count; i++)
            {
                var arg = argList[i];

                if (foundEndOfArguments)
                {
                    tokenList.Add(Operand(arg));
                    continue;
                }

                if (arg == "--")
                {
                    tokenList.Add(EndOfArguments());
                    foundEndOfArguments = true;
                    continue;
                }

                if (!foundEndOfDirectives)
                {
                    if (arg.StartsWith("[") &&
                        arg.EndsWith("]") &&
                        arg[1] != ']' &&
                        arg[1] != ':')
                    {
                        tokenList.Add(Directive(arg));
                        continue;
                    }

                    if (!configuration.RootCommand.HasRawAlias(arg))
                    {
                        foundEndOfDirectives = true;
                    }
                }

                if (configuration.ResponseFileHandling != ResponseFileHandling.Disabled &&
                    arg.GetResponseFileReference() is { } filePath)
                {
                    ReadResponseFile(filePath, i);
                    continue;
                }

                if (configuration.EnablePosixBundling &&
                    CanBeUnbundled(arg, out var replacement))
                {
                    argList.InsertRange(i + 1, replacement);
                    argList.RemoveAt(i);
                    arg = argList[i];
                }

                if (arg.SplitByDelimiters(argumentDelimiters) is { } subtokens&&
                    subtokens.Length > 1)
                {
                    if (knownTokensStrings.Contains(subtokens[0]))
                    {
                        tokenList.Add(Option(subtokens[0]));

                        if (subtokens.Length > 1)
                        {
                            // trim outer quotes in case of, e.g., -x="why"
                            var secondPartWithOuterQuotesRemoved = subtokens[1].Trim('"');
                            tokenList.Add(Argument(secondPartWithOuterQuotesRemoved));
                        }
                    }
                    else
                    {
                        tokenList.Add(Argument(arg));
                    }
                }
Example #10
0
        protected BaseEngineTest(ITestOutputHelper output)
            : base(output)
        {
            TestOutput       = output;
            m_ignoreWarnings = OperatingSystemHelper.IsUnixOS; // ignoring /bin/sh is being used as a source file

            RegisterEventSource(global::BuildXL.Scheduler.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.Pips.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.FrontEnd.Script.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.FrontEnd.Core.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.Engine.ETWLogger.Log);
            RegisterEventSource(global::BuildXL.Processes.ETWLogger.Log);

            ParseAndEvaluateLogger = Logger.CreateLoggerWithTracking();
            InitializationLogger   = InitializationLogger.CreateLogger();

            var pathTable = new PathTable();

            FileSystem = new PassThroughMutableFileSystem(pathTable);
            Context    = EngineContext.CreateNew(CancellationToken.None, pathTable, FileSystem);
            MainSourceResolverModules = new List <AbsolutePath>();

            var rootPath = AbsolutePath.Create(Context.PathTable, TestRoot);
            var logsPath = Combine(AbsolutePath.Create(Context.PathTable, TemporaryDirectory), "logs");

            Configuration = new CommandLineConfiguration()
            {
                DisableDefaultSourceResolver = true,
                Resolvers = new List <IResolverSettings>
                {
                    new SourceResolverSettings
                    {
                        Kind    = "SourceResolver",
                        Modules = MainSourceResolverModules,
                    },
                    new SourceResolverSettings
                    {
                        Kind    = "SourceResolver",
                        Modules = new List <AbsolutePath>
                        {
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Prelude", "package.config.dsc")),
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Transformers", "package.config.dsc")),
                            AbsolutePath.Create(Context.PathTable, Path.Combine(GetTestExecutionLocation(), "Sdk", "Deployment", "module.config.dsc")),
                        },
                    },
                },
                Layout =
                {
                    SourceDirectory = rootPath,
                    OutputDirectory = Combine(rootPath,                             "out"),
                    ObjectDirectory = Combine(rootPath,                             "obj"),
                    CacheDirectory  = Combine(AbsolutePath.Create(Context.PathTable, TemporaryDirectory), "cache"),
                },
                Cache =
                {
                    CacheSpecs       = SpecCachingOption.Disabled,
                    CacheLogFilePath = logsPath.Combine(Context.PathTable,PathAtom.Create(Context.StringTable,  "cache.log")),
                },
                Engine =
                {
                    ReuseEngineState        = false,
                    LogStatistics           = false,
                    TrackBuildsInUserFolder = false,
                },
                FrontEnd =
                {
                    MaxFrontEndConcurrency =     1,
                    LogStatistics          = false,
                },
                Schedule =
                {
                    MaxIO        = 1,
                    MaxProcesses = 1,
                },
                Sandbox =
                {
                    FileSystemMode      = FileSystemMode.RealAndMinimalPipGraph,
                    OutputReportingMode = OutputReportingMode.FullOutputOnError,
                },
                Logging =
                {
                    LogsDirectory     = logsPath,
                    LogStats          = false,
                    LogExecution      = false,
                    LogCounters       = false,
                    LogMemory         = false,
                    StoreFingerprints = false,
                    NoWarnings        =
                    {
                        909,     // Disable warnings about experimental feature
                    },
                }
            };

            if (TryGetSubstSourceAndTarget(out string substSource, out string substTarget))
            {
                // Directory translation is needed here particularly when the test temporary directory
                // is inside a directory that is actually a junction to another place.
                // For example, the temporary directory is D:\src\BuildXL\Out\Object\abc\t_1, but
                // the path D:\src\BuildXL\Out or D:\src\BuildXL\Out\Object is a junction to K:\Out.
                // Some tool, like cmd, can access the path in K:\Out, and thus the test will have a DFA
                // if there's no directory translation.
                // This problem does not occur when only substs are involved, but no junctions. The method
                // TryGetSubstSourceAndTarget works to get translations due to substs or junctions.
                AbsolutePath substSourcePath = AbsolutePath.Create(Context.PathTable, substSource);
                AbsolutePath substTargetPath = AbsolutePath.Create(Context.PathTable, substTarget);
                Configuration.Engine.DirectoriesToTranslate.Add(
                    new TranslateDirectoryData(I($"{substSource}<{substTarget}"), substSourcePath, substTargetPath));
            }
        }
Example #11
0
 public ConfigurationConverterTests()
 {
     m_context     = FrontEndContext.CreateInstanceForTesting();
     m_defaultConf = new CommandLineConfiguration();
 }
Example #12
0
        /// <nodoc />
        public Args(string[] args, Func <AnalyzerKind, Analyzer> analyzerFactory, PathTable pathTable)
            : base(args)
        {
            m_pathTable       = pathTable;
            CommandLineConfig = new CommandLineConfiguration();
            Analyzers         = new List <Analyzer>();
            Analyzer currentAnalyzer = null;

            foreach (Option opt in Options)
            {
                if (opt.Name.Equals("filter", StringComparison.OrdinalIgnoreCase) ||
                    opt.Name.Equals("f", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.Filter = opt.Value;
                }
                else if (opt.Name.Equals("config", StringComparison.OrdinalIgnoreCase) ||
                         opt.Name.Equals("c", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.Startup.ConfigFile = AbsolutePath.Create(m_pathTable, opt.Value);
                }
                else if (opt.Name.Equals("property", StringComparison.OrdinalIgnoreCase) || opt.Name.Equals("p", StringComparison.OrdinalIgnoreCase))
                {
                    ParsePropertyOption(opt, CommandLineConfig.Startup.Properties);
                }
                else if (opt.Name.Equals("InCloudBuild", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.InCloudBuild = ParseBooleanOption(opt);
                }
                else if (opt.Name.Equals("objectDirectory", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.Layout.ObjectDirectory = AbsolutePath.Create(m_pathTable, GetFullPath(opt.Value, opt));
                }
                else if (opt.Name.Equals("outputDirectory", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.Layout.OutputDirectory = AbsolutePath.Create(m_pathTable, GetFullPath(opt.Value, opt));
                }
                else if (opt.Name.Equals("RedirectedUserProfileJunctionRoot", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLineConfig.Layout.RedirectedUserProfileJunctionRoot = AbsolutePath.Create(m_pathTable, GetFullPath(opt.Value, opt));
                }
                else if (opt.Name.Equals("fix", StringComparison.OrdinalIgnoreCase))
                {
                    Fix = ParseBooleanOption(opt);
                }
                else if (opt.Name.Equals("analyzer", StringComparison.OrdinalIgnoreCase) ||
                         opt.Name.Equals("a", StringComparison.OrdinalIgnoreCase))
                {
                    var analyzerType = ParseEnumOption <AnalyzerKind>(opt);
                    var newAnalyzer  = analyzerFactory(analyzerType);
                    if (newAnalyzer == null)
                    {
                        throw Error(I($"Unsupported Analyzer type '{analyzerType}'. Supported types are: {string.Join(", ", Enum.GetValues(typeof(AnalyzerKind)).Cast<string>())}"));
                    }

                    currentAnalyzer = newAnalyzer;
                    Analyzers.Add(currentAnalyzer);
                }
                else if (s_helpStrings.Any(s => opt.Name.Equals(s, StringComparison.OrdinalIgnoreCase)))
                {
                    Help = true;
                    WriteHelp(analyzerFactory);
                }
                else
                {
                    if (currentAnalyzer == null)
                    {
                        throw Error(I($"Unsupported option: {opt.Name}."));
                    }
                    else
                    {
                        if (!currentAnalyzer.HandleOption(opt))
                        {
                            throw new InvalidOperationException(I($"Unsupported option '{opt.Name}'. This option is not supported by analyzer {currentAnalyzer.Kind}."));
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(CommandLineConfig.Filter) && !CommandLineConfig.Startup.ConfigFile.IsValid)
            {
                throw Error("Must specify at least /Config -or- /Filter argument.");
            }

            if (Analyzers.Count == 0)
            {
                throw Error("Must specify at least one Analyzer.");
            }
        }
Example #13
0
        /// <summary>
        /// Runs the scheduler allowing various options to be specifically set
        /// </summary>
        public ScheduleRunResult RunSchedulerSpecific(
            PipGraph graph,
            SchedulerTestHooks testHooks  = null,
            SchedulerState schedulerState = null,
            RootFilter filter             = null,
            TempCleaner tempCleaner       = null)
        {
            var config = new CommandLineConfiguration(Configuration);

            // Populating the configuration may modify the configuration, so it should occur first.
            BuildXLEngine.PopulateLoggingAndLayoutConfiguration(config, Context.PathTable, bxlExeLocation: null, inTestMode: true);
            BuildXLEngine.PopulateAndValidateConfiguration(config, config, Context.PathTable, LoggingContext);

            FileAccessWhitelist whitelist = new FileAccessWhitelist(Context);

            whitelist.Initialize(config);

            IReadOnlyList <string> junctionRoots = Configuration.Engine.DirectoriesToTranslate?.Select(a => a.ToPath.ToString(Context.PathTable)).ToList();

            var map = VolumeMap.TryCreateMapOfAllLocalVolumes(LoggingContext, junctionRoots);
            var optionalAccessor = TryGetJournalAccessor(map);

            // Although scan change journal is enabled, but if we cannot create an enabled journal accessor, then create a disabled one.
            m_journalState = map == null || !optionalAccessor.IsValid
                ? JournalState.DisabledJournal
                : JournalState.CreateEnabledJournal(map, optionalAccessor.Value);

            if (config.Schedule.IncrementalScheduling)
            {
                // Ensure that we can scan the journal when incremental scheduling is enabled.
                XAssert.IsTrue(m_journalState.IsEnabled, "Incremental scheduling requires that journal is enabled");
            }

            // Seal the translator if not sealed
            DirectoryTranslator.Seal();

            // .....................................................................................
            // some dummy setup in order to get a PreserveOutputsSalt.txt file and an actual salt
            // .....................................................................................
            string dummyCacheDir = Path.Combine(TemporaryDirectory, "Out", "Cache");

            Directory.CreateDirectory(dummyCacheDir); // EngineSchedule tries to put the PreserveOutputsSalt.txt here
            ContentHash?previousOutputsSalt =
                EngineSchedule.PreparePreviousOutputsSalt(LoggingContext, Context.PathTable, config);

            Contract.Assert(previousOutputsSalt.HasValue);
            // .....................................................................................

            testHooks = testHooks ?? new SchedulerTestHooks();
            Contract.Assert(!(config.Engine.CleanTempDirectories && tempCleaner == null));

            using (var queue = new PipQueue(config.Schedule))
                using (var testQueue = new TestPipQueue(queue, LoggingContext, initiallyPaused: false))
                    using (var testScheduler = new TestScheduler(
                               graph: graph,
                               pipQueue: testQueue,
                               context: Context,
                               fileContentTable: FileContentTable,
                               loggingContext: LoggingContext,
                               cache: Cache,
                               configuration: config,
                               journalState: m_journalState,
                               fileAccessWhitelist: whitelist,
                               fingerprintSalt: Configuration.Cache.CacheSalt,
                               directoryMembershipFingerprinterRules: new DirectoryMembershipFingerprinterRuleSet(Configuration, Context.StringTable),
                               tempCleaner: tempCleaner,
                               previousInputsSalt: previousOutputsSalt.Value,
                               successfulPips: null,
                               failedPips: null,
                               ipcProvider: null,
                               directoryTranslator: DirectoryTranslator,
                               testHooks: testHooks))
                    {
                        if (filter == null)
                        {
                            EngineSchedule.TryGetPipFilter(LoggingContext, Context, config, config, Expander.TryGetRootByMountName, out filter);
                        }

                        XAssert.IsTrue(testScheduler.InitForMaster(LoggingContext, filter, schedulerState), "Failed to initialized test scheduler");

                        testScheduler.Start(LoggingContext);

                        bool success = testScheduler.WhenDone().GetAwaiter().GetResult();
                        testScheduler.SaveFileChangeTrackerAsync(LoggingContext).Wait();

                        if (ShouldLogSchedulerStats)
                        {
                            // Logs are not written out normally during these tests, but LogStats depends on the existence of the logs directory
                            // to write out the stats perf JSON file
                            var logsDir = config.Logging.LogsDirectory.ToString(Context.PathTable);
                            Directory.CreateDirectory(logsDir);
                            testScheduler.LogStats(LoggingContext);
                        }

                        return(new ScheduleRunResult
                        {
                            Graph = graph,
                            Config = config,
                            Success = success,
                            PipResults = testScheduler.PipResults,
                            PipExecutorCounters = testScheduler.PipExecutionCounters,
                            PathSets = testScheduler.PathSets,
                            ProcessPipCountersByFilter = testScheduler.ProcessPipCountersByFilter,
                            ProcessPipCountersByTelemetryTag = testScheduler.ProcessPipCountersByTelemetryTag,
                            SchedulerState = new SchedulerState(testScheduler)
                        });
                    }
        }
Example #14
0
        protected string[] ExtractRelevantTokens(
            CommandLineConfiguration cmdLineConfig,
            string[] args)
        {
            var readOnly  = new ReadOnlyCollection <string>(args);
            var tokenized = readOnly.Tokenize(cmdLineConfig);

            if (tokenized.Errors.Count > 0)
            {
                throw new InvalidOperationException(
                          $"Couldn't parse command line arguments for command '{Command.Name}'");
            }

            // first token appears to contain the command we're tokenizing for
            var cmdName = tokenized.Tokens.First().Value;

            var retVal = new List <string>();

            var extract   = false;
            var completed = false;

            // scan all the tokens but only extract them for parsing when
            // they relate to our command. There are two ways that is signified.
            // For RootCommands there will be a Command type token whose value
            // matches cmdName (it appears to always be the first token).
            // For regular Commands there will be an Argument type token whose
            // value matches cmdName. Note that for regular Commands we skip
            // the first token because it's not relevant
            foreach (var token in tokenized.Tokens.Skip(ObjectBinder.Command is RootCommand ? 0 : 1))
            {
                switch (token.Type)
                {
                case TokenType.Argument:
                    // if we're already extracting the token is related to
                    // an option that should have already been captured
                    if (extract)
                    {
                        retVal.Add(token.Value);
                    }
                    else
                    {
                        // if the argument value matches the cmdName start extracting
                        if (token.Value.Equals(cmdName, StringComparison.OrdinalIgnoreCase))
                        {
                            extract = true;
                            retVal.Add(token.Value);
                        }
                    }

                    break;

                case TokenType.Command:
                    if (token.Value.Equals(Command.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        extract = true;
                        retVal.Add(token.Value);
                    }
                    else
                    {
                        completed = true;
                    }

                    break;

                case TokenType.Option:
                case TokenType.Operand:
                    if (extract)
                    {
                        retVal.Add(token.Value);
                    }

                    break;

                case TokenType.Directive:
                    // no op; we don't handle directives yet so ignore them
                    break;

                case TokenType.EndOfArguments:
                    extract   = false;
                    completed = true;

                    break;
                }

                if (completed)
                {
                    break;
                }
            }

            return(retVal.ToArray());
        }
Example #15
0
        private static void ShowUsage(CommandLineConfiguration configuration, string parseResult = "")
        {
            Usage usage = new UsageComposer(configuration).Compose();

            if (String.IsNullOrEmpty(parseResult))
            {
                var build = ((AssemblyInformationalVersionAttribute)Assembly
                              .GetAssembly(typeof(Program))
                              .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
                              .InformationalVersion;
                Console.WriteLine(@"
 ██▓███  ▓█████  ██▀███   ▄████▄   ██▓ ██▓███        ██▓ ▒█████  
▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒▒██▀ ▀█  ▓██▒▓██░  ██▒     ▓██▒▒██▒  ██▒
▓██░ ██▓▒▒███   ▓██ ░▄█ ▒▒▓█    ▄ ▒██▒▓██░ ██▓▒     ▒██▒▒██░  ██▒
▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄  ▒▓▓▄ ▄██▒░██░▒██▄█▓▒ ▒     ░██░▒██   ██░
▒██▒ ░  ░░▒████▒░██▓ ▒██▒▒ ▓███▀ ░░██░▒██▒ ░  ░ ██▓ ░██░░ ████▓▒░
▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░░ ░▒ ▒  ░░▓  ▒▓▒░ ░  ░ ▒▓▒ ░▓  ░ ▒░▒░▒░ 
░▒ ░      ░ ░  ░  ░▒ ░ ▒░  ░  ▒    ▒ ░░▒ ░      ░▒   ▒ ░  ░ ▒ ▒░ 
░░          ░     ░░   ░ ░         ▒ ░░░        ░    ▒ ░░ ░ ░ ▒  
            ░  ░   ░     ░ ░       ░             ░   ░      ░ ░  
                         ░                       ░               
Percip.io {0} - The working time logger by antic_eye ;)

Use this tool to track your productivity. MyLock generates an
encrypted database file that contains timestamps and ""in""
or ""out"".

When you call myLock with ""lock"" it tracks:
01.01.2016T08: 15 Max.Mustermann Out

When you call without args it tracks:
01.01.2016T08: 19 Max.Mustermann In

When you want to show your times, call it with ""--query"".It will
read the db and calculate your working time beginning with the
first ""in"" per day, ending with the last ""out"".

To automate the tracking, use ""--init"" and myLock will generate
Windows Scheduled tasks for screen lock/unlock and session
login/-out. You will need administrative permissions for this
task. Open an elevated command prompt.

", build);
                Console.WriteLine("Usage: percip.io.exe {0}", usage.Arguments);
                Console.WriteLine();
                Console.WriteLine(usage.Options);
                Console.WriteLine("Exit codes:");

                foreach (var e in Enum.GetValues(typeof(ExitCode)))
                    Console.WriteLine(string.Format("{0,4}\t{1}",
                        (int)e,
                        e.ToString()));
            }
            else
            {
                Console.WriteLine(parseResult);
                Console.WriteLine();
            }
        }
Example #16
0
        internal static TokenizeResult Tokenize(
            this IReadOnlyList <string> args,
            CommandLineConfiguration configuration)
        {
            var errorList = new List <TokenizeError>();

            Command?currentCommand       = null;
            var     foundDoubleDash      = false;
            var     foundEndOfDirectives = !configuration.EnableDirectives;
            var     argList   = NormalizeRootCommand(configuration, args);
            var     tokenList = new List <Token>(argList.Count);

            var knownTokens = configuration.RootCommand.ValidTokens();

            for (var i = 0; i < argList.Count; i++)
            {
                var arg = argList[i];

                if (foundDoubleDash)
                {
                    if (configuration.EnableLegacyDoubleDashBehavior)
                    {
                        tokenList.Add(Unparsed(arg));
                    }
                    else
                    {
                        tokenList.Add(Argument(arg));
                    }
                    continue;
                }

                if (!foundDoubleDash &&
                    arg == "--")
                {
                    tokenList.Add(DoubleDash());
                    foundDoubleDash = true;
                    continue;
                }

                if (!foundEndOfDirectives)
                {
                    if (arg.Length > 2 &&
                        arg[0] == '[' &&
                        arg[1] != ']' &&
                        arg[1] != ':' &&
                        arg.EndsWith("]", StringComparison.Ordinal))
                    {
                        tokenList.Add(Directive(arg));
                        continue;
                    }

                    if (!configuration.RootCommand.HasAlias(arg))
                    {
                        foundEndOfDirectives = true;
                    }
                }

                if (configuration.ResponseFileHandling != ResponseFileHandling.Disabled &&
                    arg.GetResponseFileReference() is { } filePath)
                {
                    ReadResponseFile(filePath, i);
                    continue;
                }

                if (knownTokens.TryGetValue(arg, out var token))
                {
                    if (PreviousTokenIsAnOptionExpectingAnArgument())
                    {
                        tokenList.Add(Argument(arg));
                    }
                    else
                    {
                        switch (token.Type)
                        {
                        case TokenType.Option:
                            tokenList.Add(Option(arg, (Option)token.Symbol !));
                            break;

                        case TokenType.Command:
                            Command cmd = (Command)token.Symbol !;
                            if (cmd != currentCommand)
                            {
                                if (!(currentCommand is null && cmd == configuration.RootCommand))
                                {
                                    knownTokens = cmd.ValidTokens();
                                }
                                currentCommand = cmd;
                                tokenList.Add(Command(arg, cmd));
                            }
                            else
                            {
                                tokenList.Add(Argument(arg));
                            }

                            break;
                        }
                    }
                }
                else if (arg.TrySplitIntoSubtokens(out var first, out var rest) &&
                         knownTokens.TryGetValue(first, out var subtoken) && subtoken.Type == TokenType.Option)
                {
                    tokenList.Add(Option(first, (Option)subtoken.Symbol !));

                    if (rest is { })
        private static void WriteUsageToConsole(CommandLineConfiguration commandLineConfiguration, ParseResult parseResult)
        {
            Usage usage = new UsageComposer(commandLineConfiguration).Compose();

            Console.WriteLine(parseResult.Message);
            Console.WriteLine("usage:" + usage.Arguments);
            Console.WriteLine("options");
            Console.WriteLine(usage.Options.IndentBy(4));
            Console.WriteLine();
        }
Example #18
0
 public ParseOperation(TokenizeResult tokenizeResult, CommandLineConfiguration configuration)
 {
     _tokenizeResult = tokenizeResult;
     _configuration  = configuration;
 }