Esempio n. 1
0
        public static void AddBundleLoader(Func <AssetBundle> func, string path, out string warning)
        {
            warning = "";

            if (Bundles.TryGetValue(path, out var lazyList))
            {
                warning = $"Duplicate asset bundle detected! {path}";
                lazyList.Add(Lazy <AssetBundle> .Create(func));
            }
            else
            {
                Bundles.Add(path, new List <Lazy <AssetBundle> >
                {
                    Lazy <AssetBundle> .Create(func)
                });
            }
        }
Esempio n. 2
0
        internal TeamCity(Action <string> messageSink)
        {
            _messageSink = messageSink ?? Console.WriteLine;

            _systemProperties        = Lazy.Create(() => ParseDictionary(EnvironmentInfo.GetVariable <string>("TEAMCITY_BUILD_PROPERTIES_FILE")));
            _configurationProperties = Lazy.Create(() => ParseDictionary(SystemProperties?["teamcity.configuration.properties.file"]));
            _runnerProperties        = Lazy.Create(() => ParseDictionary(SystemProperties?["teamcity.runner.properties.file"]));
            _recentlyFailedTests     = Lazy.Create(() =>
            {
                var file = SystemProperties?["teamcity.tests.recentlyFailedTests.file"];
                return(File.Exists(file)
                    ? TextTasks.ReadAllLines(file).ToImmutableList() as IReadOnlyCollection <string>
                    : new string[0]);
            });

            _restClient = Lazy.Create(() => CreateRestClient <ITeamCityRestClient>());
        }
 /// <nodoc />
 public ConfigurationConversionHelper(
     [CanBeNull] FrontEndEngineAbstraction engine,
     ConfigurationKind kind,
     GlobalConstants constants,
     ModuleRegistry sharedModuleRegistry,
     Logger logger,
     FrontEndHost host,
     FrontEndContext context,
     IConfiguration configuration,
     IFrontEndStatistics statistics = null)
     : base(constants, sharedModuleRegistry, statistics ?? new FrontEndStatistics(), logger, host, context, configuration)
 {
     Engine = engine ?? new SimpleFrontEndEngineAbstraction(context.PathTable, context.FileSystem, configuration);
     Kind   = kind;
     ConversionConfiguration = AstConversionConfiguration.ForConfiguration(FrontEndConfiguration);
     Linter = Lazy.Create(() => CreateLinter(ConversionConfiguration));
 }
Esempio n. 4
0
        /// <nodoc />
        internal DebugLogsAnalyzer(AnalysisInput input, int port, bool enableCaching, bool ensureOrdering, bool preHydrateProcessPips = true)
            : base(input)
        {
            m_port                 = port;
            EnableEvalCaching      = enableCaching;
            EnsureOrdering         = ensureOrdering;
            XlgState               = new XlgDebuggerState(this);
            m_dirData              = new MultiValueDictionary <AbsolutePath, DirectoryMembershipHashedEventData>();
            m_criticalPathAnalyzer = new CriticalPathAnalyzer(input, outputFilePath: null);
            m_lazyCriticalPath     = Lazy.Create(() =>
            {
                m_criticalPathAnalyzer.Analyze();
                return(m_criticalPathAnalyzer.criticalPathData);
            });
            m_state           = new DebuggerState(PathTable, LoggingContext, XlgState.Render, XlgState);
            m_lazyPipPerfDict = new Lazy <Dictionary <PipId, PipExecutionPerformance> >(() =>
            {
                return(m_writeExecutionEntries.ToDictionary(e => e.PipId, e => e.ExecutionPerformance));
            });
            m_lazyPipsBySemiStableHash = new Lazy <Dictionary <long, PipId> >(() =>
            {
                var result = new Dictionary <long, PipId>();
                foreach (var pipId in PipTable.Keys)
                {
                    result[PipTable.GetPipSemiStableHash(pipId)] = pipId;
                }
                return(result);
            });

            if (preHydrateProcessPips)
            {
                Task
                .Run(() =>
                {
                    var start = DateTime.UtcNow;
                    Console.WriteLine("=== Started hydrating process pips");
                    Analysis.IgnoreResult(PipGraph.RetrievePipsOfType(Pips.Operations.PipType.Process).ToArray());
                    Console.WriteLine("=== Done hydrating process pips in " + DateTime.UtcNow.Subtract(start));
                })
                .Forget(ex =>
                {
                    Console.WriteLine("=== Prehydrating pips failed: " + ex);
                });
            }
        }
Esempio n. 5
0
        private Maybe <Lazy <WAHBitArray> > Op(Maybe <Lazy <WAHBitArray> > left, Maybe <Lazy <WAHBitArray> > right, Operation operation)
        {
            if (left.HasValue && right.HasValue)
            {
                switch (operation)
                {
                case Operation.And:
                    return(Maybe.Return(Lazy.Create(() => left.Value.Value.And(right.Value.Value))));

                case Operation.Or:
                    return(Maybe.Return(Lazy.Create(() => left.Value.Value.Or(right.Value.Value))));

                default:
                    throw new ArgumentException("{0} is not supported.".Fmt(operation));
                }
            }
            return(left.HasValue ? left : right);
        }
Esempio n. 6
0
        internal GitHubActions()
        {
            _eventContext = Lazy.Create(() =>
            {
                var content = File.ReadAllText(EventPath);
                return(JsonConvert.DeserializeObject <JObject>(content));
            });
            _httpClient = Lazy.Create(() =>
            {
                var base64Auth = Convert.ToBase64String(Encoding.ASCII.GetBytes($":{Token.NotNull()}"));

                var client         = new HttpClient();
                client.BaseAddress = new Uri("https://api.github.com");
                client.DefaultRequestHeaders.UserAgent.ParseAdd("nuke-build");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Auth);
                return(client);
            });
            _jobId = Lazy.Create(GetJobId);
        }
Esempio n. 7
0
        /// <summary>
        /// Parses a list of arguments and returns a ConfiguredCommand.
        /// </summary>
        public static ConfiguredCommand ParseArgs(string[] args, IParser parser, IIpcLogger logger = null, bool ignoreInvalidOptions = false)
        {
            var usageMessage = Lazy.Create(() => "Usage:" + Environment.NewLine + Usage());

            if (args.Length == 0)
            {
                throw new ArgumentException(I($"Command is required. {usageMessage.Value}"));
            }

            var argsQueue = new Queue <string>(args.Length);

            foreach (var arg in args)
            {
                if (arg[0] == ResponseFilePrefix)
                {
                    foreach (var argFromFile in ProcessResponseFile(arg, parser))
                    {
                        argsQueue.Enqueue(argFromFile);
                    }
                }
                else
                {
                    argsQueue.Enqueue(arg);
                }
            }

            string cmdName = argsQueue.Dequeue();

            if (!Commands.TryGetValue(cmdName, out Command cmd))
            {
                throw new ArgumentException(I($"No command '{cmdName}' is found. {usageMessage.Value}"));
            }

            var    sw        = Stopwatch.StartNew();
            Config conf      = BuildXL.Utilities.CLI.Config.ParseCommandLineArgs(cmd.Options, argsQueue, parser, caseInsensitive: true, ignoreInvalidOptions: ignoreInvalidOptions);
            var    parseTime = sw.Elapsed;

            logger = logger ?? new ConsoleLogger(Verbose.GetValue(conf), ServicePipDaemon.LogPrefix);
            logger.Verbose("Parsing command line arguments done in {0}", parseTime);
            return(new ConfiguredCommand(cmd, conf, logger));
        }
Esempio n. 8
0
 /// <summary>
 /// Extracts values of all public properties.
 /// </summary>
 public static ObjectInfo GenericObjectInfo(
     object obj,
     string preview = null,
     IEnumerable <string> includeProperties = null,
     IEnumerable <string> excludeProperties = null)
 {
     return(new ObjectInfo(
                preview ?? obj?.ToString(),
                Lazy.Create(() =>
     {
         var props = ExtractObjectProperties(obj).Concat(ExtractObjectFields(obj));
         if (includeProperties != null)
         {
             props = props.Where(p => includeProperties.Contains(p.Name));
         }
         if (excludeProperties != null)
         {
             props = props.Where(p => !excludeProperties.Contains(p.Name));
         }
         return props;
     })));
 }
Esempio n. 9
0
        // ReSharper disable once UnusedMethodReturnValue.Global
        protected bool Register(TGenome genome, out TGenome actual, Action <TGenome> onBeforeAdd = null)
        {
            if (genome == null)
            {
                throw new ArgumentNullException(nameof(genome));
            }
            Contract.EndContractBlock();

            var added = false;

            actual = Registry.GetOrAdd(genome.Hash, hash => Lazy.Create(() =>
            {
                added = true;
                Debug.Assert(genome.Hash == hash);
                onBeforeAdd?.Invoke(genome);
                // Cannot allow registration of an unfrozen genome because it then can be used by another thread.
                AssertFrozen(genome);
                //RegistryOrder.Enqueue(hash);
                return(genome);
            })).Value;

            return(added);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new output logger.
        ///
        /// The underlying file is created only upon first write.
        /// </summary>
        /// <param name="sidebandLogFile">File to which to save the log.</param>
        /// <param name="rootDirectories">Only paths under one of the root directories are recorded in <see cref="RecordFileWrite(PathTable, AbsolutePath)"/>.</param>
        public SharedOpaqueOutputLogger(string sidebandLogFile, [CanBeNull] IReadOnlyList <string> rootDirectories)
        {
            SidebandLogFile      = sidebandLogFile;
            RootDirectories      = rootDirectories;
            m_recordedPathsCache = new HashSet <AbsolutePath>();
            m_envelopeId         = FileEnvelopeId.Create();

            m_lazyBxlWriter = Lazy.Create(() =>
            {
                Directory.CreateDirectory(Path.GetDirectoryName(SidebandLogFile));
                return(new BuildXLWriter(
                           stream: new FileStream(SidebandLogFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete),
                           debug: false,
                           logStats: false,
                           leaveOpen: false));
            });

            m_lazyWriteHeader = Lazy.Create(() =>
            {
                FileEnvelope.WriteHeader(m_lazyBxlWriter.Value.BaseStream, m_envelopeId);
                return(Unit.Void);
            });
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a new output logger.
        ///
        /// The underlying file is created only upon first write.
        /// </summary>
        /// <param name="metadata">Metadata</param>
        /// <param name="sidebandLogFile">File to which to save the log.</param>
        /// <param name="rootDirectories">Only paths under one of these root directories will be recorded.</param>
        public SidebandWriter(SidebandMetadata metadata, string sidebandLogFile, [CanBeNull] IReadOnlyList <string> rootDirectories)
        {
            Metadata             = metadata;
            SidebandLogFile      = sidebandLogFile;
            RootDirectories      = rootDirectories;
            m_recordedPathsCache = new HashSet <AbsolutePath>();
            m_envelopeId         = FileEnvelopeId.Create();

            m_lazyBxlWriter = Lazy.Create(() =>
            {
                Directory.CreateDirectory(Path.GetDirectoryName(SidebandLogFile));
                var writer = new BuildXLWriter(
                    stream: new FileStream(SidebandLogFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete),
                    debug: false,
                    logStats: false,
                    leaveOpen: false);

                // write header and metadata before anything else
                FileEnvelope.WriteHeader(writer.BaseStream, m_envelopeId);
                Metadata.Serialize(writer);
                return(writer);
            });
        }
Esempio n. 12
0
        public ObjectInfo GetObjectInfo(object context, object obj)
        {
            obj = obj is EvaluationResult evalResult
                ? evalResult.Value
                : obj;

            if (obj == null || IsInvalid(obj))
            {
                return(s_nullObj);
            }

            if (obj.GetType().IsArray)
            {
                return(ArrayObjInfo(((IEnumerable)obj).Cast <object>().ToArray()));
            }

            var customResult = m_customRenderer?.Invoke(this, context, obj);

            if (customResult != null)
            {
                return(customResult);
            }

            return(Match(obj, new CaseMatcher <ObjectInfo>[]
            {
                Case <ScopeLocals>(scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex)))),
                Case <ScopePipGraph>(scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName)),
                Case <ScopeAllModules>(scope => ArrayObjInfo(scope.EvaluatedModules.ToArray()).WithPreview(EvaluatedModulesScopeName)),
                Case <IModuleAndContext>(mc => GetObjectInfo(mc.Tree.RootContext, mc.Module)),
                Case <ObjectInfo>(objInf => objInf),
                Case <IPipGraph>(graph => PipGraphInfo(graph)),
                Case <Pip>(pip => GenericObjectInfo(pip, $"<{pip.PipType}>")),
                Case <PipProvenance>(prov => ProvenanceInfo(prov)),
                Case <EnvironmentVariable>(envVar => EnvironmentVariableInfo(envVar)),
                Case <PipFragment>(pipFrag => PipFragmentInfo(context, pipFrag)),
                Case <Thunk>(thunk => thunk.Value != null ? GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>")),
                Case <FunctionLikeExpression>(lambda => LambdaInfo(lambda)),
                Case <Closure>(cls => LambdaInfo(cls.Function)),
                Case <SymbolAtom>(sym => new ObjectInfo(sym.ToString(StringTable))),
                Case <StringId>(id => new ObjectInfo(id.ToString(StringTable))),
                Case <PipId>(id => new ObjectInfo($"{id.Value}")),
                Case <UndefinedLiteral>(_ => new ObjectInfo("undefined", UndefinedLiteral.Instance)),
                Case <UndefinedValue>(_ => new ObjectInfo("undefined", UndefinedValue.Instance)),
                Case <AbsolutePath>(path => new ObjectInfo($"p`{path.ToString(PathTable)}`", path)),
                Case <RelativePath>(path => new ObjectInfo($"r`{path.ToString(StringTable)}`", path)),
                Case <PathAtom>(atom => new ObjectInfo($"a`{atom.ToString(StringTable)}`", atom)),
                Case <FileArtifact>(file => new ObjectInfo($"f`{file.Path.ToString(PathTable)}`", file)),
                Case <DirectoryArtifact>(dir => new ObjectInfo($"d`{dir.Path.ToString(PathTable)}`", dir)),
                Case <int>(num => new ObjectInfo($"{num}")),
                Case <uint>(num => new ObjectInfo($"{num}")),
                Case <short>(num => new ObjectInfo($"{num}", (int)num)),
                Case <long>(num => new ObjectInfo($"{num}")),
                Case <char>(ch => new ObjectInfo($"'{ch}'", ch.ToString())),
                Case <string>(str => new ObjectInfo($"\"{str}\"", str)),
                Case <Enum>(e => new ObjectInfo($"{e.GetType().Name}.{e}", e)),
                Case <NumberLiteral>(numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit)),
                Case <Func <object> >(func => FuncObjInfo(func)),
                Case <ArraySegment <object> >(arrSeg => ArrayObjInfo(arrSeg)),
                Case <IEnumerable>(enu =>
                                   new ObjectInfo("IEnumerable", Lazy.Create(() => new[] { new Property("Result", enu.Cast <object>().ToArray()) }))),
                Case <ArrayLiteral>(arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value).ToArray()).WithOriginal(arrLit)),
                Case <ModuleBinding>(binding => GetObjectInfo(context, binding.Body)),
                Case <ErrorValue>(error => ErrorValueInfo()),
                Case <object>(o => GenericObjectInfo(o, o?.ToString()))
            },
                         defaultResult: s_nullObj));
        }
Esempio n. 13
0
            /// <nodoc />
            public MacOsDefaults(PathTable pathTable, IMutablePipGraph pipGraph)
            {
                m_provenance = new PipProvenance(
                    0,
                    ModuleId.Invalid,
                    StringId.Invalid,
                    FullSymbol.Invalid,
                    LocationData.Invalid,
                    QualifierId.Unqualified,
                    PipData.Invalid);

                m_sourceSealDirectoryPaths =
                    new[]
                {
                    MacPaths.Applications,
                    MacPaths.Library,
                    MacPaths.UserProvisioning
                }
                .Select(p => AbsolutePath.Create(pathTable, p))
                .ToArray();

                // Sealed Source inputs
                // (using Lazy so that these directories are sealed and added to the graph only if explicitly requested by a process)
                m_lazySourceSealDirectories = Lazy.Create(() =>
                                                          new DefaultSourceSealDirectories(m_sourceSealDirectoryPaths.Select(p => GetSourceSeal(pipGraph, p)).ToArray()));

                m_untrackedFiles =
                    new[]
                {
                    // login.keychain is created by the OS the first time any process invokes an OS API that references the keychain.
                    // Untracked because build state will not be stored there and code signing will fail if required certs are in the keychain
                    MacPaths.Etc,
                    MacPaths.UserKeyChainsDb,
                    MacPaths.UserKeyChains,
                    MacPaths.UserCFTextEncoding,
                    MacPaths.TmpDir
                }
                .Select(p => FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, p)))
                .ToArray();

                m_untrackedDirectories =
                    new[]
                {
                    MacPaths.Bin,
                    MacPaths.Dev,
                    MacPaths.Private,
                    MacPaths.Sbin,
                    MacPaths.SystemLibrary,
                    MacPaths.UsrBin,
                    MacPaths.UsrInclude,
                    MacPaths.UsrLibexec,
                    MacPaths.UsrShare,
                    MacPaths.UsrStandalone,
                    MacPaths.UsrSbin,
                    MacPaths.Var,
                    MacPaths.UserPreferences,
                    // it's important to untrack /usr/lib instead of creating a sealed source directory
                    //   - the set of dynamically loaded libraries during an execution of a process is
                    //     not necessarily deterministic, i.e., when the same process---which itself is
                    //     deterministic---is executed multiple times on same inputs, the set of
                    //     dynamically loaded libraries is not necessarily going to stay the same.
                    MacPaths.UsrLib
                }
                .Select(p => DirectoryArtifact.CreateWithZeroPartialSealId(pathTable, p))
                .ToArray();
            }
Esempio n. 14
0
 public ShareCore(IStateMonad <TState, TValue> self, TState state)
 {
     _self  = self;
     _state = state;
     _lazy  = Lazy.Create <StateResult <TState, TValue> >(RunSelf);
 }
Esempio n. 15
0
 public ToIdentityCore(ITryMonad <T> self)
 {
     _self = self;
     _lazy = Lazy.Create <ITryResult <T> >(RunSelf);
 }
Esempio n. 16
0
 public Entry(IReadOnlyList <double> paramValues, Formula f)
 {
     ParamValues = paramValues;
     Correct     = Lazy.Create(() => f(ParamValues));
 }
Esempio n. 17
0
 public DataTreeNodeViewModel(DataTreeNode model, DataExplorerViewModel root) : base(model)
 {
     Root     = root;
     Format   = model.Format;
     children = Lazy.Create(() => model.Children.ToReadOnlyList(child => new DataTreeNodeViewModel(child, root)));
 }
Esempio n. 18
0
        internal ObjectInfo GetObjectInfo(EvaluationContext context, object obj)
        {
            obj = obj is EvaluationResult evalResult ? evalResult.Value : obj;

            var result = IsInvalid(obj)
                ? s_nullObj
                : Match(obj, new CaseMatcher <ObjectInfo>[]
            {
                Case <ScopeLocals>(scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex)))),
                Case <ScopeCurrentModule>(scope => ModuleLiteralInfo(context, scope.Env).WithPreview(CurrentModuleScopeName)),
                Case <ScopePipGraph>(scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName)),
                Case <ScopeAllModules>(scope => ArrayObjInfo(scope.EvaluatedModules).WithPreview(EvaluatedModulesScopeName)),
                Case <IModuleAndContext>(mc => GetObjectInfo(mc.Tree.RootContext, mc.Module)),
                Case <ObjectInfo>(objInf => objInf),
                Case <AmbientPlaceholder>(amb => new ObjectInfo(string.Empty, GetAmbientProperties(context, amb.Value).ToList())),
                Case <IPipGraph>(graph => PipGraphInfo(graph)),
                Case <Pip>(pip => GenericObjectInfo(pip, $"<{pip.PipType}>")),
                Case <PipProvenance>(prov => ProvenanceInfo(prov)),
                Case <EnvironmentVariable>(envVar => EnvironmentVariableInfo(envVar)),
                Case <PipFragment>(pipFrag => PipFragmentInfo(context, pipFrag)),
                Case <Thunk>(thunk => thunk.Value != null ? GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>")),
                Case <FunctionLikeExpression>(lambda => LambdaInfo(lambda)),
                Case <Closure>(cls => LambdaInfo(cls.Function)),
                Case <FullSymbol>(sym => new ObjectInfo(sym.ToString(context.FrontEndContext.SymbolTable))),
                Case <SymbolAtom>(sym => new ObjectInfo(sym.ToString(context.StringTable))),
                Case <StringId>(id => new ObjectInfo(id.ToString(context.StringTable))),
                Case <PipId>(id => new ObjectInfo($"{id.Value}")),
                Case <UndefinedLiteral>(_ => new ObjectInfo("undefined", UndefinedLiteral.Instance)),
                Case <UndefinedValue>(_ => new ObjectInfo("undefined", UndefinedValue.Instance)),
                Case <AbsolutePath>(path => new ObjectInfo($"p`{path.ToString(context.PathTable)}`", path)),
                Case <RelativePath>(path => new ObjectInfo($"r`{path.ToString(context.StringTable)}`", path)),
                Case <PathAtom>(atom => new ObjectInfo($"a`{atom.ToString(context.StringTable)}`", atom)),
                Case <FileArtifact>(file => new ObjectInfo($"f`{file.Path.ToString(context.PathTable)}`", file)),
                Case <DirectoryArtifact>(dir => new ObjectInfo($"d`{dir.Path.ToString(context.PathTable)}`", dir)),
                Case <uint>(num => new ObjectInfo($"{num}")),
                Case <short>(num => new ObjectInfo($"{num}", (int)num)),
                Case <long>(num => new ObjectInfo($"{num}")),
                Case <char>(ch => new ObjectInfo($"'{ch}'", ch.ToString())),
                Case <string>(str => new ObjectInfo($"\"{str}\"", str)),
                Case <Enum>(e => new ObjectInfo($"{e.GetType().Name}.{e}", e)),
                Case <NumberLiteral>(numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit)),
                Case <Func <object> >(func => FuncObjInfo(func)),
                Case <IEnumerable>(arr => ArrayObjInfo(arr.Cast <object>())),
                Case <ArrayLiteral>(arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value)).WithOriginal(arrLit)),
                Case <ModuleBinding>(binding => GetObjectInfo(context, binding.Body)),
                Case <ModuleLiteral>(modLit => ModuleLiteralInfo(context, modLit)),
                Case <CallableValue>(cv => CallableValueInfo(context, cv).WithOriginal(cv)),
                Case <ErrorValue>(error => ErrorValueInfo(context)),
                Case <Package>(package => PackageInfo(context, package)),
                Case <ObjectLiteral>(objLit => ObjectLiteralInfo(context, objLit).WithOriginal(objLit)),
                Case <object>(o => o.GetType().IsArray
                        ? ArrayObjInfo(((IEnumerable)o).Cast <object>())
                        : PrimitiveObjInfo(context, o)),
            },
                        defaultResult: s_nullObj);

            var ambientProperties = obj is AmbientPlaceholder
                ? new Property[0]
                : new[] { new Property("__prototype__", new AmbientPlaceholder(obj)) };

            return(new ObjectInfo(result.Preview, result.Properties.Concat(ambientProperties).ToArray()));
        }
Esempio n. 19
0
 /// <nodoc />
 public Property(string name, Func <object> factory, CompletionItemType kind = CompletionItemType.property)
     : this(name, Lazy.Create(factory), kind)
 {
 }
Esempio n. 20
0
        /// <summary>
        /// Internal constructor
        /// </summary>
        /// <param name="pipId">The pipId of the pip that this descriptor is assigned to</param>
        internal PipDescriptor(Process fullPip, CachedGraph buildGraph, ExecutionLogLoadOptions loadOptions, ConcurrentHashSet <FileDescriptor> emptyConcurrentHashSetOfFileDescriptor, ConcurrentHashSet <PipDescriptor> emptyConcurrentHashSetOfPipDescriptor,
                               ConcurrentHashSet <ProcessInstanceDescriptor> emptyConcurrentHashSetOfReportedProcesses, StringIdEnvVarDictionary emptyStringIDEnvVarDictionary, AbsolutePathConcurrentHashSet emptyAbsolutePathConcurrentHashSet)
        {
            Contract.Requires(fullPip != null);
            Contract.Requires(buildGraph != null);

            // IsInitializedFlag will be set to non 0 when all the pip properties have been set
            IsInitializedFlag         = 0;
            PipExecutionPerformance   = null;
            m_transitiveDependentPips = Lazy.Create(() => GetTransitiveDependentPips());
            m_criticalPathBasedOnNumberOfPipsProducedFromCache = Lazy.Create(() => FindCriticalPathBasedOnNumberOfPipsProducedFromCache());
            m_numberOfFilesProducedFromCacheOnCriticalPath     = Lazy.Create(() => FindNumberOfFilesProducedFromCacheOnCriticalPath());

            m_criticalPathBasedOnExecutionTime = Lazy.Create(() => FindCriticalPathBasedOnExecutionTime());
            m_dependencyChainLength            = Lazy.Create(() => FindDependencyChainLength());
            m_criticalPathLength = Lazy.Create(() => FindCriticalPathLength());
            m_buildGraph         = buildGraph;
            m_fullPip            = fullPip;

            PipTags = new StringIdConcurrentHashSet(m_buildGraph.Context.StringTable);
            foreach (var tag in m_fullPip.Tags)
            {
                if (tag.IsValid)
                {
                    PipTags.Add(tag);
                }
            }

            if ((loadOptions & ExecutionLogLoadOptions.DoNotLoadOutputFiles) == 0)
            {
                OutputFilesHashset = new ConcurrentHashSet <FileDescriptor>();
            }
            else
            {
                OutputFilesHashset = emptyConcurrentHashSetOfFileDescriptor;
            }

            if ((loadOptions & ExecutionLogLoadOptions.DoNotLoadSourceFiles) == 0)
            {
                DependentFilesHashset = new ConcurrentHashSet <FileDescriptor>();
                ProbedFilesHashset    = new ConcurrentHashSet <FileDescriptor>();
            }
            else
            {
                DependentFilesHashset = emptyConcurrentHashSetOfFileDescriptor;
                ProbedFilesHashset    = emptyConcurrentHashSetOfFileDescriptor;
            }

            if ((loadOptions & ExecutionLogLoadOptions.LoadObservedInputs) == 0)
            {
                ObservedInputsHashset = emptyConcurrentHashSetOfFileDescriptor;
            }
            else
            {
                ObservedInputsHashset = new ConcurrentHashSet <FileDescriptor>();
            }

            if ((loadOptions & ExecutionLogLoadOptions.LoadBuildGraph) == 0)
            {
                AdjacentInNodesHashset  = emptyConcurrentHashSetOfPipDescriptor;
                AdjacentOutNodesHashset = emptyConcurrentHashSetOfPipDescriptor;
            }
            else
            {
                AdjacentInNodesHashset  = new ConcurrentHashSet <PipDescriptor>();
                AdjacentOutNodesHashset = new ConcurrentHashSet <PipDescriptor>();
            }

            if ((loadOptions & ExecutionLogLoadOptions.LoadProcessMonitoringData) == 0)
            {
                ReportedProcessesHashset = emptyConcurrentHashSetOfReportedProcesses;
            }
            else
            {
                ReportedProcessesHashset = new ConcurrentHashSet <ProcessInstanceDescriptor>();
            }

            if ((loadOptions & ExecutionLogLoadOptions.DoNotLoadRarelyUsedPipProperties) == 0)
            {
                UntrackedPathsHashset          = new AbsolutePathConcurrentHashSet(m_buildGraph.Context.PathTable);
                UntrackedScopesHashset         = new AbsolutePathConcurrentHashSet(m_buildGraph.Context.PathTable);
                EnvironmentVariablesDictionary = new StringIdEnvVarDictionary(m_buildGraph.Context);
                foreach (var d in m_fullPip.UntrackedPaths)
                {
                    if (d.IsValid)
                    {
                        UntrackedPathsHashset.Add(d);
                    }
                }

                foreach (var d in m_fullPip.UntrackedScopes)
                {
                    if (d.IsValid)
                    {
                        UntrackedScopesHashset.Add(d);
                    }
                }
            }
            else
            {
                EnvironmentVariablesDictionary = emptyStringIDEnvVarDictionary;
                UntrackedPathsHashset          = emptyAbsolutePathConcurrentHashSet;
                UntrackedScopesHashset         = emptyAbsolutePathConcurrentHashSet;
            }
        }
Esempio n. 21
0
 private static Lazy <Task <T> > CreateAsyncLazyFromResult <T>(T obj)
 {
     return(Lazy.Create(() => Task.FromResult <T>(obj)));
 }
Esempio n. 22
0
 public ShareCore(IIOMonad <T> self)
 {
     _self = self;
     _lazy = Lazy.Create <T>(RunSelf);
 }
Esempio n. 23
0
 public ShareCore(IReaderMonad <TEnvironment, TValue> self, TEnvironment environmen)
 {
     _self        = self;
     _environment = environmen;
     _lazy        = Lazy.Create <TValue>(RunSelf);
 }
Esempio n. 24
0
 public ShareCore(IEitherMonad <TLeft, TRight> self)
 {
     _self = self;
     _lazy = Lazy.Create <IEitherResult <TLeft, TRight> >(RunSelf);
 }
Esempio n. 25
0
 public ShareCore(ITryMonad <T> self)
 {
     _self = self;
     _lazy = Lazy.Create <ITryResult <T> >(RunSelf);
 }
Esempio n. 26
0
 /// <nodoc />
 public Property(string name, object value, CompletionItemType kind = CompletionItemType.property)
 {
     Name          = name;
     m_valueAsLazy = value as Lazy <object> ?? Lazy.Create(() => value);
     Kind          = kind;
 }
Esempio n. 27
0
 internal Logger(IActionLogWriter defaultWriter, ILoggingPermissions permissions)
 {
     _writer      = defaultWriter;
     _permissions = permissions;
     _logs        = Lazy.Create(CreateLogs);
 }
Esempio n. 28
0
 /// <nodoc />
 public ObjectInfo(string preview, object original)
     : this(preview, original, Lazy.Create <IReadOnlyList <Property> >(() => Property.Empty))
 {
 }
        public static IEnumerable <T[]> GroupTopoSort <T>(
            this ICollection <T> source,
            [InstantHandle] Func <T, IEnumerable <T> > dependsOnGetter,
            IEqualityComparer <T> equalityComparer)
            where T : notnull
        {
            Code.NotNull(source, nameof(source));
            Code.NotNull(dependsOnGetter, nameof(dependsOnGetter));
            Code.NotNull(equalityComparer, nameof(equalityComparer));

            // Fast path
            if (source.Count == 0)
            {
                yield break;
            }

            var dependants =
                LazyDictionary.Create(
                    _ => new List <T>(),
                    equalityComparer,
                    false);
            var workArray = new int[source.Count];
            var indices   = new Dictionary <T, int>(equalityComparer);
            var level     = new List <T>();

            foreach (var(index, item) in source.WithIndex())
            {
                var count = 0;
                foreach (var dep in dependsOnGetter(item))
                {
                    dependants[dep].Add(item);
                    count++;
                }
                if (count == 0)
                {
                    level.Add(item);
                }
                else
                {
                    workArray[index] = count;
                }
                indices.Add(item, index);
            }

            if (level.Count == 0)
            {
                throw CycleException(nameof(source));
            }

            // Fast path
            if (level.Count == workArray.Length)
            {
                yield return(level.ToArray());

                yield break;
            }

            var pendingCount = workArray.Length;

            while (true)
            {
                var nextLevel = Lazy.Create(() => new List <T>(), false);
                foreach (var item in level)
                {
                    foreach (var dep in dependants[item])
                    {
                        var pending = --workArray[indices[dep]];
                        if (pending == 0)
                        {
                            nextLevel.Value.Add(dep);
                        }
                    }
                }
                yield return(level.ToArray());

                pendingCount -= level.Count;
                if (pendingCount == 0)
                {
                    yield break;
                }
                if (!nextLevel.IsValueCreated)
                {
                    throw CycleException(nameof(source));
                }
                level = nextLevel.Value;
            }
        }
Esempio n. 30
0
 /// <nodoc />
 public ObjectInfo(string preview = "", IReadOnlyList <Property> properties = null)
     : this(preview, null, Lazy.Create(() => properties ?? Property.Empty))
 {
 }