Exemplo n.º 1
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
Exemplo n.º 2
0
    def __ConfigureBuild(self, report: PackageGeneratorConfigReport,
                         buildConfig: BuildConfigRecord) -> None:
        configReport = report.ConfigReport.ConfigCommandReport
        variableReport = report.VariableReport

        buildArgumentList = []
        for buildArgument in configReport.Arguments:
            buildArgument = ReportVariableFormatter.Format(
                buildArgument, variableReport, buildConfig.VariantSettingsDict)
            buildArgumentList.append(buildArgument)

        configCommandStr = ReportVariableFormatter.Format(
            configReport.CommandFormatString, variableReport,
            buildConfig.VariantSettingsDict)

        currentWorkingDirectory = ReportVariableFormatter.Format(
            configReport.CurrentWorkingDirectoryFormatString, variableReport,
            buildConfig.VariantSettingsDict)

        configCommand = [configCommandStr
                         ] + buildArgumentList  # + buildConfig.BuildConfigArgs
        #if len(buildContext.Platform.AdditionalBuildConfigArguments) > 0:
        #    buildCommand += buildContext.Platform.AdditionalBuildConfigArguments

        try:
            IOUtil.SafeMakeDirs(currentWorkingDirectory)

            cacheFilename = IOUtil.Join(currentWorkingDirectory,
                                        '.FslConfigureCache.json')

            dirtyBuildConfigureCache = self.__CheckBuildConfigureModifications(
                cacheFilename, report.GeneratedFileSet, configCommand)
            if dirtyBuildConfigureCache is None:
                self.Log.LogPrint(
                    "Build configuration not modified, skipping configure")
                return
            self.Log.LogPrint("Build configuration modifed, running configure")

            if self.Log.Verbosity >= 1:
                self.Log.LogPrint(
                    "Running build config command '{0}' in '{1}'".format(
                        self.__SafeJoinCommandArguments(configCommand),
                        currentWorkingDirectory))

            result = subprocess.call(configCommand,
                                     cwd=currentWorkingDirectory)
            if result != 0:
                self.Log.LogPrintWarning(
                    "The build config command '{0}' failed with '{1}'. It was run with CWD: '{2}'"
                    .format(self.__SafeJoinCommandArguments(configCommand),
                            result, currentWorkingDirectory))
                sys.exit(result)
            else:
                BuildConfigureCache.Save(self.Log, cacheFilename,
                                         dirtyBuildConfigureCache)
        except FileNotFoundError:
            self.Log.DoPrintWarning(
                "The build config command '{0}' failed with 'file not found'. It was run with CWD: '{1}'"
                .format(self.__SafeJoinCommandArguments(configCommand),
                        currentWorkingDirectory))
            raise