/// <summary> /// Deserializes a pip graph fragment from stream. /// </summary> public async Task <bool> DeserializeAsync( Stream stream, Func <PipGraphFragmentContext, PipGraphFragmentProvenance, PipId, Pip, Task <bool> > handleDeserializedPip = null, string fragmentDescriptionOverride = null, AbsolutePath filePathOrigin = default) { using (var reader = new PipRemapReader(m_pipExecutionContext, m_pipGraphFragmentContext, stream)) { try { string serializedDescription = reader.ReadNullableString(); FragmentDescription = fragmentDescriptionOverride ?? serializedDescription; var provenance = new PipGraphFragmentProvenance(filePathOrigin, FragmentDescription); bool serializedUsingTopSort = reader.ReadBoolean(); Func <PipId, Pip, Task <bool> > handleDeserializedPipInFragment = (pipId, pip) => handleDeserializedPip(m_pipGraphFragmentContext, provenance, pipId, pip); if (serializedUsingTopSort) { return(await DeserializeTopSortAsync(handleDeserializedPipInFragment, reader)); } else { return(await DeserializeSeriallyAsync(handleDeserializedPipInFragment, reader)); } } finally { Interlocked.Add(ref Stats.OptimizedSymbols, reader.OptimizedSymbols); } } }
/// <summary> /// Deserializes a pip graph fragment and call the given handleDeserializedPip function on each pip deserialized. /// </summary> public bool Deserialize( AbsolutePath filePath, Func <PipGraphFragmentContext, PipGraphFragmentProvenance, PipId, Pip, bool> handleDeserializedPip = null, string fragmentDescriptionOverride = null) { Contract.Requires(filePath.IsValid); string fileName = filePath.ToString(m_pipExecutionContext.PathTable); using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new PipRemapReader(m_pipExecutionContext, m_pipGraphFragmentContext, stream)) { string serializedDescription = reader.ReadNullableString(); FragmentDescription = (fragmentDescriptionOverride ?? serializedDescription) ?? filePath.ToString(m_pipExecutionContext.PathTable); var provenance = new PipGraphFragmentProvenance(filePath, FragmentDescription); m_totalPipsToDeserialize = reader.ReadInt32(); for (int i = 0; i < m_totalPipsToDeserialize; i++) { var pip = Pip.Deserialize(reader); // Pip id is not deserialized when pip is deserialized. // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip // is assumed to be unset, and is set when the pip gets inserted into the pip table. // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id. // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId() // remaps the pip id to a new pip id. var pipId = new PipId(reader.ReadUInt32()); var success = handleDeserializedPip?.Invoke(m_pipGraphFragmentContext, provenance, pipId, pip); if (success.HasValue & !success.Value) { return(false); } Stats.Increment(pip, serialize: false); } } return(true); }
/// <summary> /// Deserializes a pip graph fragment from stream. /// </summary> public bool Deserialize( Stream stream, Func <PipGraphFragmentContext, PipGraphFragmentProvenance, PipId, Pip, bool> handleDeserializedPip = null, string fragmentDescriptionOverride = null, AbsolutePath filePathOrigin = default) { using (var reader = new PipRemapReader(m_pipExecutionContext, m_pipGraphFragmentContext, stream)) { string serializedDescription = reader.ReadNullableString(); FragmentDescription = fragmentDescriptionOverride ?? serializedDescription; var provenance = new PipGraphFragmentProvenance(filePathOrigin, FragmentDescription); bool serializedUsingTopSort = reader.ReadBoolean(); Func <PipId, Pip, bool> handleDeserializedPipInFragment = (pipId, pip) => handleDeserializedPip(m_pipGraphFragmentContext, provenance, pipId, pip); if (serializedUsingTopSort) { return(DeserializeTopSort(handleDeserializedPipInFragment, reader)); } else { return(DeserializeSerially(handleDeserializedPipInFragment, reader)); } } }