Ejemplo n.º 1
0
        /// <summary>
        /// Compute the intersection of the pip's dependencies and the affected contents of the build
        /// </summary>
        public IReadOnlyList <AbsolutePath> GetChangeAffectedInputs(Process process)
        {
            var changeAffectedInputs = new HashSet <AbsolutePath>(process.Dependencies.Select(f => f.Path).Where(p => m_sourceChangeAffectedFiles.Contains(p)));

            foreach (var directory in process.DirectoryDependencies)
            {
                foreach (var file in m_fileContentManager.ListSealedDirectoryContents(directory))
                {
                    if (m_sourceChangeAffectedFiles.Contains(file))
                    {
                        changeAffectedInputs.Add(file.Path);
                    }
                }

                if (m_fileContentManager.Host.TryGetSourceSealDirectory(directory, out var sourceSealWithPatterns))
                {
                    var affectedMembers = m_sourceSealDirectoryAffectedMembers.GetOrAdd(
                        directory,
                        d => new List <AbsolutePath>(m_initialSourceChanges.Where(p => sourceSealWithPatterns.Contains(PathTable, p))));
                    changeAffectedInputs.AddRange(affectedMembers);
                }
            }

            return(ReadOnlyArray <AbsolutePath> .FromWithoutCopy(changeAffectedInputs.ToArray()));
        }
Ejemplo n.º 2
0
        private async Task <IIpcResult> ExecuteGetSealedDirectoryContentAsync(GetSealedDirectoryContentCommand cmd)
        {
            Contract.Requires(cmd != null);

            // for extra safety, check that provided directory path and directory id match
            AbsolutePath dirPath;
            bool         isValidPath = AbsolutePath.TryCreate(m_context.PathTable, cmd.FullDirectoryPath, out dirPath);

            if (!isValidPath || !cmd.Directory.Path.Equals(dirPath))
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           "directory path ids differ, or could not create AbsolutePath; directory = " + cmd.Directory.Path.ToString(m_context.PathTable) + ", directory path = " + cmd.FullDirectoryPath));
            }

            var files = m_fileContentManager.ListSealedDirectoryContents(cmd.Directory);

            Tracing.Logger.Log.ApiServerGetSealedDirectoryContentExecuted(m_loggingContext, cmd.Directory.Path.ToString(m_context.PathTable), files.Length);

            var inputContentsTasks = files
                                     .Select(f => m_fileContentManager.TryQuerySealedOrUndeclaredInputContentAsync(f.Path, nameof(ApiServer), allowUndeclaredSourceReads: true))
                                     .ToArray();

            var inputContents = await TaskUtilities.SafeWhenAll(inputContentsTasks);

            var results       = new List <BuildXL.Ipc.ExternalApi.SealedDirectoryFile>();
            var failedResults = new List <string>();

            for (int i = 0; i < files.Length; ++i)
            {
                // If the content has no value or has unknown length, then we have some inconsistency wrt the sealed directory content
                // Absent files are an exception since it is possible to have sealed directories with absent files (shared opaques is an example of this).
                // In those cases we leave the consumer to deal with them.
                if (!inputContents[i].HasValue || (inputContents[i].Value.Hash != WellKnownContentHashes.AbsentFile && !inputContents[i].Value.HasKnownLength))
                {
                    failedResults.Add(files[i].Path.ToString(m_context.PathTable));
                }
                else
                {
                    results.Add(new BuildXL.Ipc.ExternalApi.SealedDirectoryFile(
                                    files[i].Path.ToString(m_context.PathTable),
                                    files[i],
                                    inputContents[i].Value));
                }
            }

            if (failedResults.Count > 0)
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           string.Format("Could not find content information for {0} out of {1} files inside of '{4}':{2}{3}",
                                         failedResults.Count,
                                         files.Length,
                                         Environment.NewLine,
                                         string.Join("; ", failedResults),
                                         cmd.Directory.Path.ToString(m_context.PathTable))));
            }

            return(IpcResult.Success(cmd.RenderResult(results)));
        }
Ejemplo n.º 3
0
        private async Task <IIpcResult> ExecuteGetSealedDirectoryContent(GetSealedDirectoryContentCommand cmd)
        {
            Contract.Requires(cmd != null);

            // for extra safety, check that provided directory path and directory id match
            AbsolutePath dirPath;
            bool         isValidPath = AbsolutePath.TryCreate(m_context.PathTable, cmd.FullDirectoryPath, out dirPath);

            if (!isValidPath || !cmd.Directory.Path.Equals(dirPath))
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           "directory path ids differ, or could not create AbsolutePath; directory = " + cmd.Directory.Path.ToString(m_context.PathTable) + ", directory path = " + cmd.FullDirectoryPath));
            }

            var files = m_fileContentManager.ListSealedDirectoryContents(cmd.Directory);

            Tracing.Logger.Log.ApiServerGetSealedDirectoryContentExecuted(m_loggingContext, cmd.Directory.Path.ToString(m_context.PathTable), files.Length);

            var inputContentsTasks = files
                                     .Select(f => m_fileContentManager.TryQuerySealedOrUndeclaredInputContentAsync(f.Path, nameof(ApiServer), false))
                                     .ToArray();

            var inputContents = await TaskUtilities.SafeWhenAll(inputContentsTasks);

            var results       = new List <BuildXL.Ipc.ExternalApi.SealedDirectoryFile>();
            var failedResults = new List <string>();

            for (int i = 0; i < files.Length; ++i)
            {
                if (!inputContents[i].HasValue || !inputContents[i].Value.HasKnownLength)
                {
                    failedResults.Add(files[i].Path.ToString(m_context.PathTable));
                }
                else
                {
                    results.Add(new BuildXL.Ipc.ExternalApi.SealedDirectoryFile(
                                    files[i].Path.ToString(m_context.PathTable),
                                    files[i],
                                    inputContents[i].Value));
                }
            }

            if (failedResults.Count > 0)
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           string.Format("Could not find content information for {0} out of {1} files inside of '{4}':{2}{3}",
                                         failedResults.Count,
                                         files.Length,
                                         Environment.NewLine,
                                         string.Join("; ", failedResults),
                                         cmd.Directory.Path.ToString(m_context.PathTable))));
            }

            return(IpcResult.Success(cmd.RenderResult(results)));
        }
        /// <summary>
        /// Compute the intersection of the pip's dependencies and the affected contents of the build
        /// </summary>
        public IReadOnlyCollection <AbsolutePath> GetChangeAffectedInputs(Process process)
        {
            var changeAffectedInputs = new HashSet <AbsolutePath>();

            changeAffectedInputs.AddRange(process.Dependencies.Select(f => f.Path).Where(f => m_sourceChangeAffectedFiles.Contains(f)));

            foreach (var directory in process.DirectoryDependencies)
            {
                foreach (var file in m_fileContentManager.ListSealedDirectoryContents(directory))
                {
                    if (m_sourceChangeAffectedFiles.Contains(file))
                    {
                        changeAffectedInputs.Add(file.Path);
                    }
                }
            }

            return(ReadOnlyArray <AbsolutePath> .FromWithoutCopy(changeAffectedInputs.ToArray()));
        }