<commit_before>#
#  Copyright (c) 2007, Intel Corporation
#
#  All rights reserved. This program and the accompanying materials
#  are licensed and made available under the terms and conditions of the BSD License
#  which accompanies this distribution.  The full text of the license may be found at
#  http://opensource.org/licenses/bsd-license.php
#
#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#

import os, sys, string, glob, time, traceback
from threading import *
from optparse import OptionParser
from subprocess import *

from Common.TargetTxtClassObject import *
from Common.ToolDefClassObject import *
from Common.EdkIIWorkspaceBuild import *
from Common.DataType import *
from AutoGen.AutoGen import *
from GenFds.FdfParser import *
from Common.BuildToolError import *
import Common.EdkLogger
from BuildSpawn import *


VersionNumber = "0.01"
__version__ = "%prog Version " + VersionNumber
__copyright__ = "Copyright (c) 2007, Intel Corporation  All rights reserved."


class Build():
    def __init__(self, opt, args):
        self.SysPlatform  = sys.platform
        self.EdkToolsPath = os.getenv("EDK_TOOLS_PATH")
        self.WorkSpace    = os.getenv("WORKSPACE")
        self.Path         = os.getenv("PATH")
        self.Opt          = opt
        self.Args         = args
        self.ArgList      = ['all', 'genc', 'genmake', 'modules', 'libraries', 'clean', 'cleanall', 'cleanlib', 'run']
        self.TargetTxt    = TargetTxtClassObject()
        self.ToolDef      = ToolDefClassObject()
        self.Sem          = None
        self.StartTime    = time.time()
        self.GenC         = None
        self.GenMake      = None
        self.All          = None
        self.ReturnCode   = [0,1]
        if len(self.Args) == 0:
            self.All = 1
        elif len(self.Args) >= 2:
            EdkLogger.quiet("There are too many targets in command line input, please select one from: %s" %(''.join(elem + ' ' for elem in self.ArgList)))
        else:
            t = self.Args[0].lower()
            if t not in self.ArgList:
                EdkLogger.quiet("'%s' is an invalid targets, please select one from: %s" %(self.Args[0], ''.join(elem + ' ' for elem in self.ArgList)))
                self.isexit(1)
            if t == 'genc':
                self.GenC = 1
            elif t == 'genmake':
                self.GenMake = 1
            elif t == 'all' or t == '':
                self.All = 1
            else:
                self.Args = t
        EdkLogger.quiet(time.strftime("%a, %d %b %Y %H:%M:%S +0000\n", time.localtime()))


    def CheckEnvVariable(self):
        EdkLogger.quiet("Running Operating System = %s" % self.SysPlatform)

        if self.EdkToolsPath == None:
            EdkLogger.quiet("ERROR: Please set environment variable: EDK_TOOLS_PATH !\n")
            return 1
        else:
            EdkLogger.quiet("EDK_TOOLS_PATH = %s" % self.EdkToolsPath)

        if self.WorkSpace == None:
            EdkLogger.quiet("ERROR: Please set environment variable: WORKSPACE !\n")
            return 1
        else:
            EdkLogger.quiet("WORKSPACE = %s" % self.WorkSpace)

        if self.Path == None:
            EdkLogger.quiet("ERROR: Please set environment variable: PATH !\n")
            return 1
        else:
            if self.SysPlatform == "win32":
                #print EDK_TOOLS_PATH + "\Bin\Win32"
                if str(self.Path).find(os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win32"))) == -1:
                    path = os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win32"))
                    EdkLogger.quiet("ERROR: Please execute %s to set %s in environment variable: PATH!\n" % (os.path.normpath(os.path.join(path, 'edksetup.bat')), path))
                    return 1
            if self.SysPlatform == "win64":
                #print EDK_TOOLS_PATH + "\Bin\Win64"
                if str(self.Path).find(os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win64"))) == -1:
                    path = os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win64"))
                    EdkLogger.quiet("ERROR: Please execute %s to set %s in environment variable: PATH!\n" % (os.path.normpath(os.path.join(path, 'edksetup.bat')), path))
                    return 1
        return 0

    def Parser(self, ewb):
        pcdSet = {}
        if self.Opt.FDFFILE == None:
            self.Opt.FDFFILE = ewb.Fdf
            if self.Opt.FDFFILE != '' and os.path.isfile(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))) == False:
                EdkLogger.quiet("ERROR: The file: %s does not exist!" % self.Opt.FDFFILE)
                self.isexit(1)
            if self.Opt.FDFFILE != '':
                (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE)))
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The file: %s is not a FDF file!" % self.Opt.FDFFILE)
                    self.isexit(1)
                self.Opt.FDFFILE = os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
        else:
            if self.Opt.FDFFILE[0] == '.':
                EdkLogger.quiet("ERROR: Please specify a absolute path or a WORKSPACE realtive path for FDF file.")
                self.isexit(1)
            if os.path.isfile(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))) == True:
                realpath = os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))
                (filename, ext) = os.path.splitext(realpath)
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The input file: %s is not a FDF file!" % realpath)
                    self.isexit(1)
                self.Opt.FDFFILE = realpath
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
            elif os.path.isfile(os.path.abspath(self.Opt.FDFFILE)) == True:
                realpath = os.path.abspath(self.Opt.FDFFILE)
                (filename, ext) = os.path.splitext(realpath)
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The input file: %s is not a FDF file!" % realpath)
                    self.isexit(1)
                self.Opt.FDFFILE = realpath
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
            else:
                EdkLogger.quiet("ERROR: The file: %s does not exist!" % self.Opt.FDFFILE)
                self.isexit(1)

        if self.Opt.FDFFILE != '':
            EdkLogger.info('FDFFILE is: %s' % self.Opt.FDFFILE)

        ewb.GenBuildDatabase(pcdSet)
        ewb.TargetTxt = self.TargetTxt
        ewb.ToolDef = self.ToolDef

    def LibBuild(self, LibFile, PlatformFile, ewb, a, b, c):
        LibraryAutoGen = AutoGen(LibFile, PlatformFile, ewb, str(a), b, str(c))
        LibraryAutoGen.CreateAutoGenFile()
        LibraryAutoGen.CreateMakefile()
        for Platform in ewb.Build[c].PlatformDatabase.values():
            d = Platform.OutputDirectory
            (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(os.environ["WORKSPACE"], d, a + '_' + b, c, str(LibFile))))
            DestDir = filename
            EdkLogger.info('Makefile DestDir is: %s' % DestDir)
            FileList = glob.glob(os.path.normpath(os.path.join(DestDir, 'makefile')))
            FileNum = len(FileList)
            if FileNum > 0:
                self.SameTypeFileInDir(FileNum, 'makefile', DestDir)
                BuildSpawn(self.ReturnCode, self.Sem, FileList[0], 'pbuild', 1).start()
            else:
                EdkLogger.quiet("ERROR: There is no Makefile in %s.\n" % DestDir)
                self.isexit(1)

    def ModuleBuild(self, ModuleFile, PlatformFile, ewb, a, b, c, ModuleAutoGen):
        ModuleAutoGen.CreateAutoGenFile()
        ModuleAutoGen.CreateMakefile()
        for Platform in ewb.Build[c].PlatformDatabase.values():
            d = Platform.OutputDirectory
            (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(os.environ["WORKSPACE"], d, a + '_' + b, c, ModuleFile)))<commit_msg>fix a bug, PVCS 547. For build.exe, FDF file inputed in CLI can't override the FDF file set in DSC file.<commit_after>#
#  Copyright (c) 2007, Intel Corporation
#
#  All rights reserved. This program and the accompanying materials
#  are licensed and made available under the terms and conditions of the BSD License
#  which accompanies this distribution.  The full text of the license may be found at
#  http://opensource.org/licenses/bsd-license.php
#
#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#

import os, sys, string, glob, time, traceback
from threading import *
from optparse import OptionParser
from subprocess import *

from Common.TargetTxtClassObject import *
from Common.ToolDefClassObject import *
from Common.EdkIIWorkspaceBuild import *
from Common.DataType import *
from AutoGen.AutoGen import *
from GenFds.FdfParser import *
from Common.BuildToolError import *
import Common.EdkLogger
from BuildSpawn import *


VersionNumber = "0.01"
__version__ = "%prog Version " + VersionNumber
__copyright__ = "Copyright (c) 2007, Intel Corporation  All rights reserved."


class Build():
    def __init__(self, opt, args):
        self.SysPlatform  = sys.platform
        self.EdkToolsPath = os.getenv("EDK_TOOLS_PATH")
        self.WorkSpace    = os.getenv("WORKSPACE")
        self.Path         = os.getenv("PATH")
        self.Opt          = opt
        self.Args         = args
        self.ArgList      = ['all', 'genc', 'genmake', 'modules', 'libraries', 'clean', 'cleanall', 'cleanlib', 'run']
        self.TargetTxt    = TargetTxtClassObject()
        self.ToolDef      = ToolDefClassObject()
        self.Sem          = None
        self.StartTime    = time.time()
        self.GenC         = None
        self.GenMake      = None
        self.All          = None
        self.ReturnCode   = [0,1]
        if len(self.Args) == 0:
            self.All = 1
        elif len(self.Args) >= 2:
            EdkLogger.quiet("There are too many targets in command line input, please select one from: %s" %(''.join(elem + ' ' for elem in self.ArgList)))
        else:
            t = self.Args[0].lower()
            if t not in self.ArgList:
                EdkLogger.quiet("'%s' is an invalid targets, please select one from: %s" %(self.Args[0], ''.join(elem + ' ' for elem in self.ArgList)))
                self.isexit(1)
            if t == 'genc':
                self.GenC = 1
            elif t == 'genmake':
                self.GenMake = 1
            elif t == 'all' or t == '':
                self.All = 1
            else:
                self.Args = t
        EdkLogger.quiet(time.strftime("%a, %d %b %Y %H:%M:%S +0000\n", time.localtime()))


    def CheckEnvVariable(self):
        EdkLogger.quiet("Running Operating System = %s" % self.SysPlatform)

        if self.EdkToolsPath == None:
            EdkLogger.quiet("ERROR: Please set environment variable: EDK_TOOLS_PATH !\n")
            return 1
        else:
            EdkLogger.quiet("EDK_TOOLS_PATH = %s" % self.EdkToolsPath)

        if self.WorkSpace == None:
            EdkLogger.quiet("ERROR: Please set environment variable: WORKSPACE !\n")
            return 1
        else:
            EdkLogger.quiet("WORKSPACE = %s" % self.WorkSpace)

        if self.Path == None:
            EdkLogger.quiet("ERROR: Please set environment variable: PATH !\n")
            return 1
        else:
            if self.SysPlatform == "win32":
                #print EDK_TOOLS_PATH + "\Bin\Win32"
                if str(self.Path).find(os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win32"))) == -1:
                    path = os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win32"))
                    EdkLogger.quiet("ERROR: Please execute %s to set %s in environment variable: PATH!\n" % (os.path.normpath(os.path.join(path, 'edksetup.bat')), path))
                    return 1
            if self.SysPlatform == "win64":
                #print EDK_TOOLS_PATH + "\Bin\Win64"
                if str(self.Path).find(os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win64"))) == -1:
                    path = os.path.normpath(os.path.join(self.EdkToolsPath, "\Bin\Win64"))
                    EdkLogger.quiet("ERROR: Please execute %s to set %s in environment variable: PATH!\n" % (os.path.normpath(os.path.join(path, 'edksetup.bat')), path))
                    return 1
        return 0

    def Parser(self, ewb):
        pcdSet = {}
        if self.Opt.FDFFILE == None:
            self.Opt.FDFFILE = ewb.Fdf
            if self.Opt.FDFFILE != '' and os.path.isfile(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))) == False:
                EdkLogger.quiet("ERROR: The file: %s does not exist!" % self.Opt.FDFFILE)
                self.isexit(1)
            if self.Opt.FDFFILE != '':
                (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE)))
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The file: %s is not a FDF file!" % self.Opt.FDFFILE)
                    self.isexit(1)
                self.Opt.FDFFILE = os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
        else:
            if self.Opt.FDFFILE[0] == '.':
                EdkLogger.quiet("ERROR: Please specify a absolute path or a WORKSPACE realtive path for FDF file.")
                self.isexit(1)
            if os.path.isfile(os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))) == True:
                realpath = os.path.normpath(os.path.join(self.WorkSpace, self.Opt.FDFFILE))
                (filename, ext) = os.path.splitext(realpath)
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The input file: %s is not a FDF file!" % realpath)
                    self.isexit(1)
                self.Opt.FDFFILE = realpath
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
            elif os.path.isfile(os.path.abspath(self.Opt.FDFFILE)) == True:
                realpath = os.path.abspath(self.Opt.FDFFILE)
                (filename, ext) = os.path.splitext(realpath)
                if ext.lower() != '.fdf':
                    EdkLogger.quiet("ERROR: The input file: %s is not a FDF file!" % realpath)
                    self.isexit(1)
                self.Opt.FDFFILE = realpath
                fdf = FdfParser(self.Opt.FDFFILE)
                fdf.ParseFile()
                pcdSet = fdf.profile.PcdDict
            else:
                EdkLogger.quiet("ERROR: The file: %s does not exist!" % self.Opt.FDFFILE)
                self.isexit(1)

        if self.Opt.FDFFILE != '':
            EdkLogger.info('FDFFILE is: %s' % self.Opt.FDFFILE)

        ewb.GenBuildDatabase(pcdSet)
        ewb.Fdf = self.Opt.FDFFILE
        ewb.TargetTxt = self.TargetTxt
        ewb.ToolDef = self.ToolDef

    def LibBuild(self, LibFile, PlatformFile, ewb, a, b, c):
        LibraryAutoGen = AutoGen(LibFile, PlatformFile, ewb, str(a), b, str(c))
        LibraryAutoGen.CreateAutoGenFile()
        LibraryAutoGen.CreateMakefile()
        for Platform in ewb.Build[c].PlatformDatabase.values():
            d = Platform.OutputDirectory
            (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(os.environ["WORKSPACE"], d, a + '_' + b, c, str(LibFile))))
            DestDir = filename
            EdkLogger.info('Makefile DestDir is: %s' % DestDir)
            FileList = glob.glob(os.path.normpath(os.path.join(DestDir, 'makefile')))
            FileNum = len(FileList)
            if FileNum > 0:
                self.SameTypeFileInDir(FileNum, 'makefile', DestDir)
                BuildSpawn(self.ReturnCode, self.Sem, FileList[0], 'pbuild', 1).start()
            else:
                EdkLogger.quiet("ERROR: There is no Makefile in %s.\n" % DestDir)
                self.isexit(1)

    def ModuleBuild(self, ModuleFile, PlatformFile, ewb, a, b, c, ModuleAutoGen):
        ModuleAutoGen.CreateAutoGenFile()
        ModuleAutoGen.CreateMakefile()
        for Platform in ewb.Build[c].PlatformDatabase.values():
            d = Platform.OutputDirectory
            (filename, ext) = os.path.splitext(os.path.normpath(os.path.join(os.environ["WORKSPACE"], d, a + '_' + b, c, ModuleFile)))
{'fraction_non_alphanumeric': 0.12297201975076416, 'fraction_numerical': 0.007347754526216788, 'mean_word_length': 2.023995734091717, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5081274', 'n_tokens_mistral': 5482, 'n_tokens_neox': 5234, 'n_words': 1227}