Ejemplo n.º 1
0
        private bool ProcessFilter(string filterText, FileStream stream, StreamWriter writer)
        {
            var parser = new FilterParser(CachedGraph.Context, CachedGraph.MountPathExpander.TryGetRootByMountName, filterText, canonicalize: true);

            if (!parser.TryParse(out var rootFilter, out var error))
            {
                Console.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                                "Error at position {1} of command line pip filter {0}. {3} {2}",
                                                filterText,
                                                error.Position,
                                                error.FormatFilterPointingToPosition(filterText),
                                                error.Message));
                return(false);
            }

            var outputs = PipGraph.FilterOutputs(rootFilter);
            var pips    = new List <PipId>();

            if (PipGraph.FilterNodesToBuild(Events.StaticContext, rootFilter, out var nodes))
            {
                foreach (var node in nodes)
                {
                    pips.Add(node.ToPipId());
                }
            }

            writer.WriteLine(I($"Filter: {filterText}"));
            writer.WriteLine(I($"Pips: {pips.Count}"));
            Console.WriteLine(I($"Pips: {pips.Count}"));
            foreach (var pip in pips)
            {
                writer.WriteLine(GetDescription(GetPip(pip)));
            }

            writer.WriteLine();
            Console.WriteLine(I($"Outputs: {outputs.Count}"));
            writer.WriteLine(I($"Outputs: {outputs.Count}"));
            foreach (var output in outputs)
            {
                var kind = output.IsDirectory ? "D" : "F";
                writer.WriteLine(I($"{kind}: {output.Path.ToString(PathTable)} ({GetDescription(GetPip(PipGraph.GetProducer(output)))})"));
            }

            writer.WriteLine();
            writer.WriteLine();
            writer.Flush();
            stream.Flush();

            return(true);
        }