]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: fix FCE build when edksetup not executed
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index b7fbf8dd4d17bc891a7476492051c50d88ce8cf1..e8e09dc8a3660e7543d524ec068623dd4a955359 100644 (file)
@@ -655,7 +655,7 @@ class WorkspaceAutoGen(AutoGen):
             #\r
             # Generate Package level hash value\r
             #\r
-            GlobalData.gPackageHash[Arch] = {}\r
+            GlobalData.gPackageHash = {}\r
             if GlobalData.gUseHashCache:\r
                 for Pkg in Pkgs:\r
                     self._GenPkgLevelHash(Pkg)\r
@@ -741,7 +741,7 @@ class WorkspaceAutoGen(AutoGen):
         return True\r
 \r
     def _GenPkgLevelHash(self, Pkg):\r
-        if Pkg.PackageName in GlobalData.gPackageHash[Pkg.Arch]:\r
+        if Pkg.PackageName in GlobalData.gPackageHash:\r
             return\r
 \r
         PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)\r
@@ -764,7 +764,7 @@ class WorkspaceAutoGen(AutoGen):
                         f.close()\r
                         m.update(Content)\r
         SaveFileOnChange(HashFile, m.hexdigest(), False)\r
-        GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest()\r
+        GlobalData.gPackageHash[Pkg.PackageName] = m.hexdigest()\r
 \r
     def _GetMetaFiles(self, Target, Toolchain, Arch):\r
         AllWorkSpaceMetaFiles = set()\r
@@ -1166,6 +1166,17 @@ class PlatformAutoGen(AutoGen):
 \r
         return True\r
 \r
+    ## hash() operator of PlatformAutoGen\r
+    #\r
+    #  The platform file path and arch string will be used to represent\r
+    #  hash value of this object\r
+    #\r
+    #   @retval   int Hash value of the platform file path and arch\r
+    #\r
+    @cached_class_function\r
+    def __hash__(self):\r
+        return hash((self.MetaFile, self.Arch))\r
+\r
     @cached_class_function\r
     def __repr__(self):\r
         return "%s [%s]" % (self.MetaFile, self.Arch)\r
@@ -2579,6 +2590,16 @@ class ModuleAutoGen(AutoGen):
         self.ReferenceModules = []\r
         self.ConstPcd                  = {}\r
 \r
+    ## hash() operator of ModuleAutoGen\r
+    #\r
+    #  The module file path and arch string will be used to represent\r
+    #  hash value of this object\r
+    #\r
+    #   @retval   int Hash value of the module file path and arch\r
+    #\r
+    @cached_class_function\r
+    def __hash__(self):\r
+        return hash((self.MetaFile, self.Arch))\r
 \r
     def __repr__(self):\r
         return "%s [%s]" % (self.MetaFile, self.Arch)\r
@@ -3416,7 +3437,7 @@ class ModuleAutoGen(AutoGen):
                 RetVal.append(PackageDir)\r
             IncludesList = Package.Includes\r
             if Package._PrivateIncludes:\r
-                if not self.MetaFile.Path.startswith(PackageDir):\r
+                if not self.MetaFile.OriginalPath.Path.startswith(PackageDir):\r
                     IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r
             for Inc in IncludesList:\r
                 if Inc not in RetVal:\r
@@ -3558,18 +3579,36 @@ class ModuleAutoGen(AutoGen):
         fInputfile.close ()\r
         return OutputName\r
 \r
+    @cached_property\r
+    def OutputFile(self):\r
+        retVal = set()\r
+        OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
+        DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
+        for Item in self.CodaTargetList:\r
+            File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
+            retVal.add(File)\r
+        if self.DepexGenerated:\r
+            retVal.add(self.Name + '.depex')\r
+\r
+        Bin = self._GenOffsetBin()\r
+        if Bin:\r
+            retVal.add(Bin)\r
+\r
+        for Root, Dirs, Files in os.walk(OutputDir):\r
+            for File in Files:\r
+                if File.lower().endswith('.pdb'):\r
+                    retVal.add(File)\r
+\r
+        return retVal\r
+\r
     ## Create AsBuilt INF file the module\r
     #\r
-    def CreateAsBuiltInf(self, IsOnlyCopy = False):\r
-        self.OutputFile = set()\r
-        if IsOnlyCopy and GlobalData.gBinCacheDest:\r
-            self.CopyModuleToCache()\r
-            return\r
+    def CreateAsBuiltInf(self):\r
 \r
         if self.IsAsBuiltInfCreated:\r
             return\r
 \r
-        # Skip the following code for libraries\r
+        # Skip INF file generation for libraries\r
         if self.IsLibrary:\r
             return\r
 \r
@@ -3691,7 +3730,6 @@ class ModuleAutoGen(AutoGen):
         DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
         for Item in self.CodaTargetList:\r
             File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
-            self.OutputFile.add(File)\r
             if os.path.isabs(File):\r
                 File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
             if Item.Target.Ext.lower() == '.aml':\r
@@ -3707,7 +3745,6 @@ class ModuleAutoGen(AutoGen):
             if os.path.exists(DepexFile):\r
                 self.DepexGenerated = True\r
         if self.DepexGenerated:\r
-            self.OutputFile.add(self.Name + '.depex')\r
             if self.ModuleType in [SUP_MODULE_PEIM]:\r
                 AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex')\r
             elif self.ModuleType in [SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r
@@ -3718,13 +3755,11 @@ class ModuleAutoGen(AutoGen):
         Bin = self._GenOffsetBin()\r
         if Bin:\r
             AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin)\r
-            self.OutputFile.add(Bin)\r
 \r
         for Root, Dirs, Files in os.walk(OutputDir):\r
             for File in Files:\r
                 if File.lower().endswith('.pdb'):\r
                     AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)\r
-                    self.OutputFile.add(File)\r
         HeaderComments = self.Module.HeaderComments\r
         StartPos = 0\r
         for Index in range(len(HeaderComments)):\r
@@ -3893,28 +3928,31 @@ class ModuleAutoGen(AutoGen):
         SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
 \r
         self.IsAsBuiltInfCreated = True\r
-        if GlobalData.gBinCacheDest:\r
-            self.CopyModuleToCache()\r
 \r
     def CopyModuleToCache(self):\r
-        FileDir = path.join(GlobalData.gBinCacheDest, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
+        FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
         CreateDirectory (FileDir)\r
         HashFile = path.join(self.BuildDir, self.Name + '.hash')\r
-        ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
         if os.path.exists(HashFile):\r
-            shutil.copy2(HashFile, FileDir)\r
+            CopyFileOnChange(HashFile, FileDir)\r
+        ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
         if os.path.exists(ModuleFile):\r
-            shutil.copy2(ModuleFile, FileDir)\r
+            CopyFileOnChange(ModuleFile, FileDir)\r
+\r
         if not self.OutputFile:\r
-            Ma = self.BuildDatabase[PathClass(ModuleFile), self.Arch, self.BuildTarget, self.ToolChain]\r
+            Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
             self.OutputFile = Ma.Binaries\r
-        if self.OutputFile:\r
-            for File in self.OutputFile:\r
-                File = str(File)\r
-                if not os.path.isabs(File):\r
-                    File = os.path.join(self.OutputDir, File)\r
-                if os.path.exists(File):\r
-                    shutil.copy2(File, FileDir)\r
+\r
+        for File in self.OutputFile:\r
+            File = str(File)\r
+            if not os.path.isabs(File):\r
+                File = os.path.join(self.OutputDir, File)\r
+            if os.path.exists(File):\r
+                sub_dir = os.path.relpath(File, self.OutputDir)\r
+                destination_file = os.path.join(FileDir, sub_dir)\r
+                destination_dir = os.path.dirname(destination_file)\r
+                CreateDirectory(destination_dir)\r
+                CopyFileOnChange(File, destination_dir)\r
 \r
     def AttemptModuleCacheCopy(self):\r
         # If library or Module is binary do not skip by hash\r
@@ -3924,21 +3962,26 @@ class ModuleAutoGen(AutoGen):
         for f_ext in self.SourceFileList:\r
             if '.inc' in str(f_ext):\r
                 return False\r
-        FileDir = path.join(GlobalData.gBinCacheSource, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
+        FileDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
         HashFile = path.join(FileDir, self.Name + '.hash')\r
         if os.path.exists(HashFile):\r
             f = open(HashFile, 'r')\r
             CacheHash = f.read()\r
             f.close()\r
+            self.GenModuleHash()\r
             if GlobalData.gModuleHash[self.Arch][self.Name]:\r
                 if CacheHash == GlobalData.gModuleHash[self.Arch][self.Name]:\r
                     for root, dir, files in os.walk(FileDir):\r
                         for f in files:\r
                             if self.Name + '.hash' in f:\r
-                                shutil.copy2(HashFile, self.BuildDir)\r
+                                CopyFileOnChange(HashFile, self.BuildDir)\r
                             else:\r
                                 File = path.join(root, f)\r
-                                shutil.copy2(File, self.OutputDir)\r
+                                sub_dir = os.path.relpath(File, FileDir)\r
+                                destination_file = os.path.join(self.OutputDir, sub_dir)\r
+                                destination_dir = os.path.dirname(destination_file)\r
+                                CreateDirectory(destination_dir)\r
+                                CopyFileOnChange(File, destination_dir)\r
                     if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
                         CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
                     return True\r
@@ -3979,7 +4022,8 @@ class ModuleAutoGen(AutoGen):
             for LibraryAutoGen in self.LibraryAutoGenList:\r
                 LibraryAutoGen.CreateMakeFile()\r
 \r
-        if self.CanSkip():\r
+        # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping\r
+        if not GlobalData.gUseHashCache and self.CanSkip():\r
             return\r
 \r
         if len(self.CustomMakefile) == 0:\r
@@ -4022,7 +4066,8 @@ class ModuleAutoGen(AutoGen):
             for LibraryAutoGen in self.LibraryAutoGenList:\r
                 LibraryAutoGen.CreateCodeFile()\r
 \r
-        if self.CanSkip():\r
+        # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping\r
+        if not GlobalData.gUseHashCache and self.CanSkip():\r
             return\r
 \r
         AutoGenList = []\r
@@ -4084,16 +4129,25 @@ class ModuleAutoGen(AutoGen):
         return RetVal\r
 \r
     def GenModuleHash(self):\r
+        # Initialize a dictionary for each arch type\r
         if self.Arch not in GlobalData.gModuleHash:\r
             GlobalData.gModuleHash[self.Arch] = {}\r
+\r
+        # Early exit if module or library has been hashed and is in memory\r
+        if self.Name in GlobalData.gModuleHash[self.Arch]:\r
+            return GlobalData.gModuleHash[self.Arch][self.Name].encode('utf-8')\r
+\r
+        # Initialze hash object\r
         m = hashlib.md5()\r
+\r
         # Add Platform level hash\r
         m.update(GlobalData.gPlatformHash.encode('utf-8'))\r
+\r
         # Add Package level hash\r
         if self.DependentPackageList:\r
             for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName):\r
-                if Pkg.PackageName in GlobalData.gPackageHash[self.Arch]:\r
-                    m.update(GlobalData.gPackageHash[self.Arch][Pkg.PackageName].encode('utf-8'))\r
+                if Pkg.PackageName in GlobalData.gPackageHash:\r
+                    m.update(GlobalData.gPackageHash[Pkg.PackageName].encode('utf-8'))\r
 \r
         # Add Library hash\r
         if self.LibraryAutoGenList:\r
@@ -4107,6 +4161,7 @@ class ModuleAutoGen(AutoGen):
         Content = f.read()\r
         f.close()\r
         m.update(Content)\r
+\r
         # Add Module's source files\r
         if self.SourceFileList:\r
             for File in sorted(self.SourceFileList, key=lambda x: str(x)):\r
@@ -4115,28 +4170,45 @@ class ModuleAutoGen(AutoGen):
                 f.close()\r
                 m.update(Content)\r
 \r
-        ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash")\r
-        if self.Name not in GlobalData.gModuleHash[self.Arch]:\r
-            GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest()\r
-        if GlobalData.gBinCacheSource:\r
-            if self.AttemptModuleCacheCopy():\r
-                return False\r
-        return SaveFileOnChange(ModuleHashFile, m.hexdigest(), False)\r
+        GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest()\r
+\r
+        return GlobalData.gModuleHash[self.Arch][self.Name].encode('utf-8')\r
 \r
     ## Decide whether we can skip the ModuleAutoGen process\r
     def CanSkipbyHash(self):\r
+        # Hashing feature is off\r
+        if not GlobalData.gUseHashCache:\r
+            return False\r
+\r
+        # Initialize a dictionary for each arch type\r
+        if self.Arch not in GlobalData.gBuildHashSkipTracking:\r
+            GlobalData.gBuildHashSkipTracking[self.Arch] = dict()\r
+\r
         # If library or Module is binary do not skip by hash\r
         if self.IsBinaryModule:\r
             return False\r
+\r
         # .inc is contains binary information so do not skip by hash as well\r
         for f_ext in self.SourceFileList:\r
             if '.inc' in str(f_ext):\r
                 return False\r
-        if GlobalData.gUseHashCache:\r
-            # If there is a valid hash or function generated a valid hash; function will return False\r
-            # and the statement below will return True\r
-            return not self.GenModuleHash()\r
-        return False\r
+\r
+        # Use Cache, if exists and if Module has a copy in cache\r
+        if GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy():\r
+            return True\r
+\r
+        # Early exit for libraries that haven't yet finished building\r
+        HashFile = path.join(self.BuildDir, self.Name + ".hash")\r
+        if self.IsLibrary and not os.path.exists(HashFile):\r
+            return False\r
+\r
+        # Return a Boolean based on if can skip by hash, either from memory or from IO.\r
+        if self.Name not in GlobalData.gBuildHashSkipTracking[self.Arch]:\r
+            # If hashes are the same, SaveFileOnChange() will return False.\r
+            GlobalData.gBuildHashSkipTracking[self.Arch][self.Name] = not SaveFileOnChange(HashFile, self.GenModuleHash(), True)\r
+            return GlobalData.gBuildHashSkipTracking[self.Arch][self.Name]\r
+        else:\r
+            return GlobalData.gBuildHashSkipTracking[self.Arch][self.Name]\r
 \r
     ## Decide whether we can skip the ModuleAutoGen process\r
     #  If any source file is newer than the module than we cannot skip\r