git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@398 7335b...
authorjjin9 <jjin9@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 10:12:46 +0000 (10:12 +0000)
committerjjin9 <jjin9@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 10:12:46 +0000 (10:12 +0000)
Source/Python/build/build.py

index 57acd5e..5a9f84d 100644 (file)
@@ -18,11 +18,13 @@ from os.path import normpath
 \r
 from subprocess import *\r
 \r
-from NewTargetTxtClassObject import *\r
-from NewEdkIIWorkspaceBuild import *\r
-from AutoGen import *\r
-from BuildToolError import *\r
-import EdkLogger\r
+from Common.TargetTxtClassObject import *\r
+from Common.ToolDefClassObject import *\r
+from Common.EdkIIWorkspaceBuild import *\r
+from AutoGen.AutoGen import *\r
+from GenFds.FdfParser import *\r
+from Common.BuildToolError import *\r
+import Common.EdkLogger\r
 from BuildSpawn import *\r
 \r
 \r
@@ -91,10 +93,22 @@ class Build():
         self.Path         = os.getenv("PATH")\r
         self.Opt          = opt\r
         self.Args         = args\r
-        self.TargetTxt    = NewTargetTxtClassObject()\r
+        self.TargetTxt    = TargetTxtClassObject()\r
         self.ToolDef      = ToolDefClassObject()\r
         self.Sem          = None\r
         self.StartTime    = time.time()\r
+        self.GenC         = None\r
+        self.GenMake      = None\r
+        self.All          = None\r
+        t = self.Args[0].lower()\r
+        if t == 'genc':\r
+            self.GenC = 1\r
+        elif t == 'genmake':\r
+            self.enMake = 1\r
+        elif t == 'all' or t == '':\r
+            self.All = 1\r
+        else:\r
+            self.Args = t\r
         print time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())\r
         \r
 \r
@@ -184,7 +198,7 @@ class Build():
             AutoGenResult = AutoGen(ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch)\r
             AutoGenResult.CreateAutoGenFile()\r
         except Exception, e:\r
-            TrackInfo()\r
+            self.TrackInfo()\r
             print e\r
             return 1\r
 \r
@@ -194,12 +208,12 @@ class Build():
             AutoGenResult.CreateAutoGenFile()\r
             makefile = AutoGenResult.CreateMakefile()\r
         except Exception, e:\r
-            TrackInfo()\r
+            self.TrackInfo()\r
             print e\r
             return 1\r
 \r
 \r
-    def CleanAllFunc(self, ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch):\r
+    def OtherFunc(self, ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch):\r
         for d in ewb.DscDatabase[PlatformFile].Defines.DefinesDictionary['OUTPUT_DIRECTORY']:\r
             if ModuleFile == None:\r
                 DestDir = os.environ["WORKSPACE"] + '\\' + d.replace('/','\\') + '\\' + Target + '_' + ToolChain\r
@@ -210,20 +224,20 @@ class Build():
             FileNum = len(FileList)\r
             if FileNum > 0:\r
                 SameTypeFileInDir(FileNum, 'makefile', DestDir, StartTime)\r
-                p = Popen(["nmake", "/nologo", "-f", FileList[0], 'cleanall'], env=os.environ, cwd=os.path.dirname(FileList[0]))\r
+                p = Popen(["nmake", "/nologo", "-f", FileList[0], self.Args], env=os.environ, cwd=os.path.dirname(FileList[0]))\r
                 p.communicate()\r
                 if p.returncode != None:\r
                     return p.returncode\r
             else:\r
                 return 1\r
 \r
-    def ALLFunc(self, ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch):\r
+    def AllFunc(self, ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch):\r
         try:\r
             AutoGenResult = AutoGen(ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch)\r
             AutoGenResult.CreateAutoGenFile()\r
             makefile = AutoGenResult.CreateMakefile()\r
         except Exception, e:\r
-            TrackInfo()\r
+            self.TrackInfo()\r
             print e\r
             return 1\r
         if makefile != "":\r
@@ -243,18 +257,6 @@ class Build():
         #\r
         self.Opt.TARGET_ARCH = list(set(self.Opt.TARGET_ARCH) & set(ewb.SupArchList))\r
 \r
-        GenC = 0\r
-        GenMake = 0\r
-        CleanAll = 0\r
-        for t in self.Args:\r
-            t = t.lower()\r
-            if t == 'genc':\r
-                GenC = 1\r
-            elif t == 'genmake':\r
-                GenMake = 1\r
-            elif t == 'cleanall':\r
-                CleanAll = 1\r
-\r
         if self.Opt.spawn == True:\r
             for a in self.Opt.TARGET:\r
                 for b in self.Opt.TOOL_CHAIN_TAG:\r
@@ -313,24 +315,24 @@ class Build():
         for a in self.Opt.TARGET:\r
             for b in self.Opt.TOOL_CHAIN_TAG:\r
                 if ModuleFile == None:\r
-                    if GenC == 1:\r
+                    if self.GenC == 1:\r
                         self.GenCFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
-                    elif GenMake == 1:\r
+                    elif self.GenMake == 1:\r
                         self.GenMakeFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
-                    elif CleanAll == 1:\r
-                        self.CleanAllFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
+                    elif self.All == 1:\r
+                        self.AllFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
                     else:\r
-                        self.ALLFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
+                        self.OtherFunc(ModuleFile, PlatformFile, ewb, a, b, self.Opt.TARGET_ARCH)\r
                 else:\r
                     for c in self.Opt.TARGET_ARCH:\r
-                        if GenC == 1:\r
+                        if self.GenC == 1:\r
                             self.GenCFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
-                        elif GenMake == 1:\r
+                        elif self.GenMake == 1:\r
                             self.GenMakeFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
-                        elif CleanAll == 1:\r
-                            self.CleanAllFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
+                        elif self.All == 1:\r
+                            self.AllFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
                         else:\r
-                            self.ALLFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
+                            self.OtherFunc(ModuleFile, PlatformFile, ewb, a, b, c)\r
         return 0\r
 \r
     def CalculateTime(self):\r
@@ -395,6 +397,9 @@ if __name__ == '__main__':
 #\r
     try:\r
         (opt, args) = MyOptionParser()\r
+        if len(args) >= 2:\r
+            print 'The num of target is large than one.'\r
+            sys.exit(1)\r
     except Exception, e:\r
         print e\r
         sys.exit(1)\r
@@ -413,6 +418,7 @@ if __name__ == '__main__':
 #\r
     if os.path.isfile(build.WorkSpace + '\\Conf\\target.txt') == True:\r
         StatusCode =build.TargetTxt.LoadTargetTxtFile(build.WorkSpace + '\\Conf\\target.txt')\r
+        \r
         if os.path.isfile(build.WorkSpace + '\\' + build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]) == True:\r
             StatusCode = build.ToolDef.LoadToolDefFile(build.WorkSpace + '\\' + build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])\r
         else:\r
@@ -445,11 +451,11 @@ if __name__ == '__main__':
 \r
     if build.Opt.TOOL_CHAIN_TAG == None:\r
         build.Opt.TOOL_CHAIN_TAG = build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]\r
-        if build.Opt.TOOL_CHAIN_TAG == '':\r
+        if build.Opt.TOOL_CHAIN_TAG == ['']:\r
             print "TOOL_CHAIN_TAG is None. Don't What to Build.\n"\r
             build.CalculateTime()\r
             sys.exit(1)\r
-    print "TOOL_CHAIN_TAG is", build.Opt.TOOL_CHAIN_TAG\r
+    print "TOOL_CHAIN_TAG is", " ".join(build.Opt.TOOL_CHAIN_TAG)\r
 \r
     if build.Opt.NUM == None:\r
         build.Opt.NUM = build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
@@ -473,17 +479,31 @@ if __name__ == '__main__':
 #\r
 # Call Parser\r
 #\r
-    if (build.Opt.DSCFILE != None or build.Opt.DSCFILE != '') and os.path.isfile(build.WorkSpace + '\\' + build.Opt.DSCFILE) == False:\r
+    if build.Opt.DSCFILE != None and build.Opt.DSCFILE != '' and os.path.isfile(build.WorkSpace + '\\' + build.Opt.DSCFILE) == False:\r
         print "The input file: %s is not existed!", build.Opt.DSCFILE\r
         build.CalculateTime()\r
         sys.exit(1)\r
-    if build.Opt.FDFFILE != None and os.path.isfile(build.WorkSpace + '\\' + build.Opt.FDFFILE) == False:\r
-        print "The input file: %s is not existed!", build.Opt.FDFFILE\r
-        build.CalculateTime()\r
-        sys.exit(1)\r
+\r
     try:\r
         if build.Opt.DSCFILE != None and build.Opt.DSCFILE != '':\r
-            ewb = NewWorkspaceBuild(build.Opt.DSCFILE, build.WorkSpace)  #opt.DSCFILE is relative path plus filename\r
+            pcdSet = {}\r
+            ewb = WorkspaceBuild(build.Opt.DSCFILE, build.WorkSpace)  #opt.DSCFILE is relative path plus filename\r
+            if build.Opt.FDFFILE == None:\r
+                build.Opt.FDFFILE = ewb.Fdf\r
+            if build.Opt.FDFFILE != None and build.Opt.FDFFILE != '' and os.path.isfile(build.WorkSpace + '\\' + build.Opt.FDFFILE) == False:\r
+                print "The input file: %s is not existed!", build.Opt.FDFFILE\r
+                build.CalculateTime()\r
+                sys.exit(1)\r
+            if build.Opt.FDFFILE != None and build.Opt.FDFFILE != '':\r
+                fdf = FdfParser(build.Opt.FDFFILE)\r
+                fdf.ParseFile()\r
+                pcdSet = fdf.profile.PcdDict\r
+                \r
+            ewb.GenBuildDatabase(pcdSet)\r
+            \r
+            ewb.TargetTxt = build.TargetTxt\r
+            ewb.ToolDef = build.ToolDef\r
+            \r
     except Exception, e:\r
         print e\r
         build.CalculateTime()\r
@@ -493,6 +513,7 @@ if __name__ == '__main__':
 # Platform Build or Module Build\r
 #\r
     CurWorkDir = os.getcwd()\r
+    CurWorkDir = 't:\\Nt32pkg'\r
 \r
     if build.Opt.INFFILE:\r
         if build.Opt.DSCFILE:\r
@@ -531,15 +552,15 @@ if __name__ == '__main__':
             if FileNum >= 2:\r
                 print "There are %d DSC files in %s.\n" % (FileNum, CurWorkDir)\r
                 sys.exit(1)\r
-            if os.environ('WORKSPACE')[len(os.environ('WORKSPACE'))-1] == '\\':\r
-                PlatformFile = FileList[0][len(os.environ('WORKSPACE')):]\r
+            if build.WorkSpace[len(build.WorkSpace)-1] == '\\':\r
+                PlatformFile = FileList[0][len(build.WorkSpace):]\r
             else:\r
-                PlatformFile = FileList[0][len(os.environ('WORKSPACE'))+1:]\r
+                PlatformFile = FileList[0][len(build.WorkSpace)+1:]\r
             print "Platform build:", PlatformFile\r
             #\r
             # Call Parser Again\r
             #\r
-            ewb = NewWorkspaceBuild(PlatformFile, build.WorkSpace)\r
+            ewb = WorkspaceBuild(PlatformFile, build.WorkSpace)\r
             StatusCode = build.Process(None, PlatformFile, ewb)\r
         else:\r
             print "ERROR: DON'T KNOW WHAT TO BUILD\n"\r