public static ObservedInput Deserialize(BuildXLReader reader) { ObservedInputType type = (ObservedInputType)reader.ReadInt32Compact(); ObservedPathEntry pathEntry = ObservedPathEntry.Deserialize(reader); ContentHash? hash = HasPredefinedHash(type) ? (ContentHash?)null : ContentHashingUtilities.CreateFrom(reader); // don't specific explicit hash for predefined hash input types return(new ObservedInput(type, hash, pathEntry)); }
internal ObservedInput( ObservedInputType type, ContentHash?hash, ObservedPathEntry pathEntry) { Contract.Requires(hash.HasValue || HasPredefinedHash(type)); Contract.Requires(hash == null || hash.Value.HashType != HashType.Unknown); Type = type; Hash = hash ?? GetPredefinedHash(type); PathEntry = pathEntry; }
public static bool HasPredefinedHash(ObservedInputType type) { switch (type) { case ObservedInputType.AbsentPathProbe: case ObservedInputType.ExistingDirectoryProbe: case ObservedInputType.ExistingFileProbe: return(true); case ObservedInputType.FileContentRead: case ObservedInputType.DirectoryEnumeration: return(false); default: throw Contract.AssertFailure("Unknown ObservedInputType"); } }
/// <summary> /// Gets the predefined hash for the observed input type. This should only be called if /// <see cref="HasPredefinedHash(ObservedInputType)"/> returns true. /// </summary> public static ContentHash GetPredefinedHash(ObservedInputType type) { Contract.Requires(HasPredefinedHash(type), "ObservedInput type does not have predefined hash"); switch (type) { case ObservedInputType.AbsentPathProbe: return(WellKnownContentHashes.AbsentFile); case ObservedInputType.ExistingDirectoryProbe: case ObservedInputType.ExistingFileProbe: return(ContentHashingUtilities.ZeroHash); default: throw Contract.AssertFailure("Unexpected ObservedInputType"); } }
private ObservedInput( ObservedInputType type, AbsolutePath path, ContentHash?hash = null, bool isSearchPath = false, bool isDirectoryPath = false, bool directoryEnumeration = false, bool isFileProbe = false, string enumeratePatternRegex = null) : this(type, hash, new ObservedPathEntry(path, isSearchPathEnumeration : isSearchPath, isDirectoryPath : isDirectoryPath, isDirectoryEnumeration : directoryEnumeration, enumeratePatternRegex : enumeratePatternRegex, isFileProbe : isFileProbe)) { Contract.Requires(path.IsValid); }