예제 #1
0
        public static ObservedPathSet CreatePathSet(PathTable pathTable, params string[] paths)
        {
            AbsolutePath[] pathIds = new AbsolutePath[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                pathIds[i] = AbsolutePath.Create(pathTable, paths[i]);
            }

            SortedReadOnlyArray <AbsolutePath, PathTable.ExpandedAbsolutePathComparer> sortedPathIds =
                SortedReadOnlyArray <AbsolutePath, PathTable.ExpandedAbsolutePathComparer> .SortUnsafe(
                    pathIds,
                    pathTable.ExpandedPathComparer);

            return(CreatePathSet(pathTable, pathIds));
        }
        private static ObservedInputProcessingResult CreateResult(PathTable pathTable, params ObservedInput[] inputs)
        {
            var sorted = SortedReadOnlyArray <ObservedInput, ObservedInputExpandedPathComparer> .SortUnsafe(
                inputs,
                new ObservedInputExpandedPathComparer(pathTable.ExpandedPathComparer));

            var emptyObservedAccessFileNames = SortedReadOnlyArray <StringId, CaseInsensitiveStringIdComparer> .FromSortedArrayUnsafe(
                ReadOnlyArray <StringId> .Empty,
                new CaseInsensitiveStringIdComparer(pathTable.StringTable));

            return(ObservedInputProcessingResult.CreateForSuccess(
                       sorted,
                       emptyObservedAccessFileNames,
                       dynamicObservations: ReadOnlyArray <(AbsolutePath, DynamicObservationKind)> .Empty,
                       allowedUndeclaredSourceReads: CollectionUtilities.EmptySet <AbsolutePath>()));
        }
예제 #3
0
        public static ObservedPathSet CreatePathSet(PathTable pathTable, params AbsolutePath[] paths)
        {
            ObservedPathEntry[] entries = paths.Select(p => new ObservedPathEntry(p, false, false, false, null, false)).ToArray();

            SortedReadOnlyArray <ObservedPathEntry, ObservedPathEntryExpandedPathComparer> sortedPathIds =
                SortedReadOnlyArray <ObservedPathEntry, ObservedPathEntryExpandedPathComparer> .SortUnsafe(
                    entries,
                    new ObservedPathEntryExpandedPathComparer(pathTable.ExpandedPathComparer));

            var emptyObservedAccessFileNames = SortedReadOnlyArray <StringId, CaseInsensitiveStringIdComparer> .FromSortedArrayUnsafe(
                ReadOnlyArray <StringId> .Empty,
                new CaseInsensitiveStringIdComparer(pathTable.StringTable));

            return(new ObservedPathSet(
                       sortedPathIds,
                       emptyObservedAccessFileNames,
                       new UnsafeOptions(UnsafeOptions.SafeConfigurationValues, new PreserveOutputsInfo(ContentHashingUtilities.CreateRandom(), 0))));
        }
예제 #4
0
        /// <inheritdoc />
        public SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> ListSealedDirectoryContents(DirectoryArtifact directoryArtifact)
        {
            SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> artifacts;

            if (!m_knownSealedDirectoryContents.TryGetValue(directoryArtifact, out artifacts))
            {
                if (m_allowUnspecifiedSealedDirectories)
                {
                    FileArtifact[] sourceArtifactsUnderSealRoot =
                        Directory.EnumerateFiles(directoryArtifact.Path.ToString(Context.PathTable), "*", SearchOption.AllDirectories)
                        .Select(p => FileArtifact.CreateSourceFile(AbsolutePath.Create(Context.PathTable, p)))
                        .ToArray();
                    return(SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .SortUnsafe(
                               sourceArtifactsUnderSealRoot,
                               OrdinalFileArtifactComparer.Instance));
                }
                else
                {
                    Contract.Assume(false, "Unknown directory artifact for path " + directoryArtifact.Path.ToString(Context.PathTable));
                }
            }

            return(artifacts);
        }
예제 #5
0
        /// <summary>
        /// Associates a directory artifact with its constituent file artifacts. The contents must be set before the directory artifact may
        /// be used by a pip (see <see cref="ListSealedDirectoryContents"/>).
        /// </summary>
        public void SetSealedDirectoryContents(DirectoryArtifact directory, params FileArtifact[] artifactsInDirectory)
        {
            Contract.Requires(directory.IsValid);
            Contract.Requires(artifactsInDirectory != null);

            FileArtifact[] artifacts = artifactsInDirectory.ToArray();
            SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> sortedArtifacts = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .SortUnsafe(
                artifacts,
                OrdinalFileArtifactComparer.Instance);

            bool added = m_knownSealedDirectoryContents.TryAdd(directory, sortedArtifacts);

            Contract.Assume(added);

            foreach (FileArtifact artifact in artifacts)
            {
                Contract.Assume(artifact.Path.IsWithin(Context.PathTable, directory.Path));
                m_knownSealedArtifacts[artifact.Path] = artifact;
            }
        }
예제 #6
0
        /// <nodoc />
        public static async Task <ExtractIncrementalState> TryLoadAsync(Logger logger, FrontEndContext context, DownloadData downloadData)
        {
            var manifestFilePath = downloadData.ExtractManifestFile.ToString(context.PathTable);

            ExtractIncrementalState result = null;

            if (!FileUtilities.Exists(manifestFilePath))
            {
                return(null);
            }

            using (var reader = new StreamReader(manifestFilePath))
            {
                var versionLine = await reader.ReadLineAsync();

                if (versionLine == null || !string.Equals(versionLine, ManifestVersion, StringComparison.Ordinal))
                {
                    logger.ExtractManifestDoesNotMatch(context.LoggingContext, downloadData.Settings.ModuleName, downloadData.Settings.Url, "version", ManifestVersion, versionLine);
                    return(null);
                }

                var urlLine = await reader.ReadLineAsync();

                if (!string.Equals(urlLine, downloadData.Settings.Url, StringComparison.Ordinal))
                {
                    logger.ExtractManifestDoesNotMatch(context.LoggingContext, downloadData.Settings.ModuleName, downloadData.Settings.Url, "url", downloadData.Settings.Url, urlLine);
                    return(null);
                }

                var archiveTypeLine = await reader.ReadLineAsync();

                if (archiveTypeLine == null || !Enum.TryParse <DownloadArchiveType>(archiveTypeLine, out var archiveType) || archiveType != downloadData.Settings.ArchiveType)
                {
                    logger.ExtractManifestDoesNotMatch(context.LoggingContext, downloadData.Settings.ModuleName, downloadData.Settings.Url, "archiveType", downloadData.Settings.ArchiveType.ToString(), archiveTypeLine);
                    return(null);
                }

                var fileCountLine = await reader.ReadLineAsync();

                if (fileCountLine == null || !uint.TryParse(fileCountLine, out var fileCount))
                {
                    return(null);
                }

                var hashes = new Dictionary <AbsolutePath, ContentHash>();
                var files  = new FileArtifact[fileCount];
                for (int i = 0; i < fileCount; i++)
                {
                    var filePathLine = await reader.ReadLineAsync();

                    if (filePathLine == null || !RelativePath.TryCreate(context.StringTable, filePathLine, out var relativeFilePath))
                    {
                        return(null);
                    }

                    var hashLine = await reader.ReadLineAsync();

                    if (hashLine == null || !ContentHash.TryParse(hashLine, out var contentHash))
                    {
                        return(null);
                    }

                    var filePath = downloadData.ContentsFolder.Path.Combine(context.PathTable, relativeFilePath);
                    files[i]         = FileArtifact.CreateSourceFile(filePath);
                    hashes[filePath] = contentHash;
                }

                var sortedFiles = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .SortUnsafe(
                    files,
                    OrdinalFileArtifactComparer.Instance);

                result = new ExtractIncrementalState(downloadData, sortedFiles, hashes);
            }

            return(result);
        }