예제 #1
0
        /// <summary>
        /// Generates the PipInfo for a given pip, and then serializes it
        /// </summary>
        /// <param name="pipReference">PipReference to hydrate into a complete Pip</param>
        /// <param name="writer">Writer to write data to</param>
        /// <param name="serializer">Serializer to serialize with</param>
        public void GenerateAndSerializePipInfo(PipReference pipReference, JsonWriter writer, JsonSerializer serializer)
        {
            Pip pip = pipReference.HydratePip();

            // All PipInfos will have metadata
            PipInfo generatedPipInfo = new PipInfo
            {
                PipMetadata = GeneratePipMetadata(pip)
            };

            if (Filters.OnlyMetadata)
            {
                serializer.Serialize(writer, generatedPipInfo);
                return;
            }
            // Fill the data depending on the type of Pip
            switch (pip.PipType)
            {
            case PipType.CopyFile:
                generatedPipInfo.CopyFilePipDetails = GenerateCopyFilePipDetails((CopyFile)pip);
                break;

            case PipType.Process:
                generatedPipInfo.ProcessPipDetails = GenerateProcessPipDetails((Process)pip);
                break;

            case PipType.Ipc:
                generatedPipInfo.IpcPipDetails = GenerateIpcPipDetails((IpcPip)pip);
                break;

            case PipType.Value:
                generatedPipInfo.ValuePipDetails = GenerateValuePipDetails((ValuePip)pip);
                break;

            case PipType.SpecFile:
                generatedPipInfo.SpecFilePipDetails = GenerateSpecFilePipDetails((SpecFilePip)pip);
                break;

            case PipType.Module:
                generatedPipInfo.ModulePipDetails = GenerateModulePipDetails((ModulePip)pip);
                break;

            case PipType.HashSourceFile:
                generatedPipInfo.HashSourceFilePipDetails = GenerateHashSourceFilePipDetails((HashSourceFile)pip);
                break;

            case PipType.SealDirectory:
                generatedPipInfo.SealDirectoryPipDetails = GenerateSealDirectoryPipDetails((SealDirectory)pip);
                break;

            case PipType.WriteFile:
                generatedPipInfo.WriteFilePipDetails = GenerateWriteFilePipDetails((WriteFile)pip);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            serializer.Serialize(writer, generatedPipInfo);
        }
예제 #2
0
        private (Process process, ContentFingerprint contentFingerprint, string fingerprintText) GetFingerprintInfo(PipReference lazyPip)
        {
            // Make sure the extra event data has set the value properly here.
            Contract.Requires(m_fingerprintSalts.HasValue, "m_fingerprintSalts is not set.");

            Process pip = (Process)lazyPip.HydratePip();
            string  fingerprintText;

            // This checks for missing content info for pips.
            foreach (var dependency in pip.Dependencies)
            {
                if (!m_fileContentMap.ContainsKey(dependency))
                {
                    return(pip, ContentFingerprint.Zero, "FINGERPRINT CONTAINS UNKNOWN DEPENDENCIES");
                }
            }

            if (m_contentFingerprinter == null)
            {
                m_contentFingerprinter = new PipContentFingerprinter(
                    CachedGraph.Context.PathTable,
                    LookupHash,
                    m_fingerprintSalts.Value,
                    pathExpander: m_pathExpander,
                    pipDataLookup: CachedGraph.PipGraph.QueryFileArtifactPipData)
                {
                    FingerprintTextEnabled = true,
                };
            }

            // TODO: Allow specifying fingerprinting version on the command line
            ContentFingerprint fingerprint = m_contentFingerprinter.ComputeWeakFingerprint(
                pip,
                out fingerprintText);

            return(pip, fingerprint, fingerprintText);
        }