def BuildContentState(self, log: Log,
                          pathFileRecord: PathRecord,
                          allowCaching: bool, allowNew: bool,
                          cachedSyncState: Optional['SyncState'] = None) -> ContentState:
        fileState = ContentState()
        fileState.Name = pathFileRecord.RelativePath
        fileState.Length = os.path.getsize(pathFileRecord.ResolvedPath)
        fileState.ModifiedDate = self.__FileModificationDate(pathFileRecord.ResolvedPath)
        fileState.TagChecksum = '0'

        cachedState = cachedSyncState.TryGetFileState(fileState) if cachedSyncState is not None else None
        if allowCaching and cachedState is not None and fileState.Length == cachedState.Length and fileState.ModifiedDate == cachedState.ModifiedDate:
            fileState.Checksum = cachedState.Checksum
            fileState.TagChecksum = cachedState.TagChecksum
            log.LogPrintVerbose(2, "Using cached checksum for '{0}'".format(fileState.Name))
        else:
            log.LogPrintVerbose(2, "Calculating checksum for '{0}'".format(fileState.Name))
            fileState.Checksum = IOUtil.HashFile(pathFileRecord.ResolvedPath)
        # Mark the entry as being new
        #if (cachedState is None or CacheState.New) and allowNew:
        if cachedState is None and allowNew:
            fileState.CacheState = CacheState.New
        elif cachedState is not None and not fileState.IsSameState(cachedState):
            fileState.CacheState = CacheState.Modified
            fileState.ModificationComment = fileState.GetDifferenceString(cachedState)
        else:
            fileState.CacheState = CacheState.Unmodified
        return fileState
Beispiel #2
0
    def __CheckBuildConfigureModifications(
            self, cacheFilename: str, generatedFileSet: Set[str],
            command: List[str],
            platformName: str) -> Optional[BuildConfigureCache]:
        """
        Generate hashes for all files in the set and compare them to the previously saved hashes
        Returns the new cache if its dirty else None if nothing was changed.
        """
        # Generate a hash for all generated files and compare them to the previous "hash"
        self.Log.LogPrintVerbose(4, "Checking current configuration")
        generatedFileDictCache = {}  # type: Dict[str,str]
        for filename in generatedFileSet:
            generatedFileDictCache[filename] = IOUtil.HashFile(filename)
        configureCache = BuildConfigureCache(generatedFileDictCache, command,
                                             platformName)

        isDirty = True
        self.Log.LogPrintVerbose(
            5, "- Loading previous configuration cache if present")
        previousConfigureCache = BuildConfigureCache.TryLoad(
            self.Log, cacheFilename)
        self.Log.LogPrintVerbose(5, "- Comparing cache entries")
        isDirty = previousConfigureCache is None or not BuildConfigureCache.IsEqual(
            configureCache, previousConfigureCache)

        return configureCache if isDirty else None
 def GenerateFileHash(filename: str) -> str:
     return IOUtil.HashFile(filename)