Example #1
0
def RegisterObj(name=None, srcs=[], deps=[], option={}, build_type=None):
    # check inputs
    if name == None or not isinstance(name, str) or name.find('/') != -1:
        Util.Abort('name should be a string and not contain "/": %s' % name)
    if build_type == None or not isinstance(build_type, str):
        Util.Abort('invalid build type')
    _CheckList(srcs)
    _CheckList(deps)
    _CheckDict(option)

    cur_dir = os.getcwd()
    full_name = Path.GetLogicalPath(cur_dir, name)
    # assert not Path.IsStaticLib(full_name)

    build_manager = BuildManager.GetBuildManager()
    if build_manager.HasObj(full_name):
        return None

    # insert the object
    obj = BuildingObject.BuildingObject()
    obj.name_ = Path.RemoveSnake(full_name)
    obj.path_ = os.path.join(cur_dir, name)
    obj.build_type_ = build_type
    for src in srcs:
        obj.sources_.append(Path.GetLogicalPath(cur_dir, src))
    obj.option_ = option

    # handle dependencies
    for dep in deps:
        if not dep.startswith('//') and not dep.startswith(':'):
            Util.Abort('Invalid dep %s(%s), need starts with "//" or ":"' %
                       (name, dep))
        dep_path = Path.GetLogicalPath(cur_dir, dep)
        obj.raw_depends_.append(dep_path)  # before duplicate
        if dep_path not in obj.depends_:
            obj.depends_.append(dep_path)  # after dumplicate
        if Path.IsStaticLib(dep):
            if not os.path.exists(
                    Path.GetSnakeFilePathWithoutAbort(
                        Path.GetPrivateLogicalPath(dep))):
                continue
            else:
                dep_path = Path.GetLogicalPath(cur_dir,
                                               Path.GetPrivateLogicalPath(dep))
        dep_snake_file = Path.GetSnakeFilePath(dep_path)
        build_manager.AddDependentSnakeFile(dep_snake_file)
    build_manager.AddObj(obj.name_, obj)
    return obj
Example #2
0
 def _LoadSnakeFile(self, snake_path):
     command = self._GenerateRegistererCommand()
     # from Cpp import cc_binary
     # from Cpp import cc_libary
     try:
         exec(command)
     except:
         Util.Abort('exec failed: %s.' % command)
     # chdir to the lowest dir containing snake file.
     os.chdir(os.path.dirname(snake_path))
     try:
         f = file(snake_path, 'r')
     except:
         Util.Abort('No SNAKE file: %s' % snake_path)
     try:
         exec f
     except:
         traceback.print_exc()
     pass
Example #3
0
 def _PreProcessObjs(self):
     for obj_name in self.building_objs_:
         if not self.HasObj(obj_name):
             continue
         obj = self.GetObjByName(obj_name)
         try:
             builder = self.builders_[obj.build_type_]
         except:
             Util.Abort('invalid build type: %s' % obj.build_type_)
         builder.PreProcessObject(self.env_, obj)
Example #4
0
def GetAbsPath(path, abort=True):
    """//base/internal:base --> ~/$ROOT/base/internal/base"""
    assert path.startswith('//'), "INPUT %s" % path
    path = GetRelativePath(path)
    result = os.path.join(GetBaseDir(), path)
    if os.path.exists(result):
        return result
    if abort:
        Util.Abort('can not find absolute path: %s' % result)
    else:
        return ''
    pass
Example #5
0
 def _BuildObjs(self):
     os.chdir(Path.GetBaseDir())
     for obj_name in self.building_objs_:
         if Path.IsStaticLib(obj_name):
             continue
         obj = self.GetObjByName(obj_name)
         try:
             builder = self.builders_[obj.build_type_]
         except:
             Util.Abort('invalid build type: %s' % obj.build_type_)
         builder.BuildObject(self.env_, obj)
     pass
Example #6
0
def GetLogicalPath(cur_dir, path):
    """('~/$ROOT/base/internal/', 'base') --> '//base/internal:base'"""
    if path.startswith('//'):
        return path
    if path.startswith(':'):
        assert path.find('/') == -1, "INPUT %s" % path
        abs_path = os.path.join(cur_dir, path[1:])
    else:
        abs_path = os.path.join(cur_dir, path)
    result = os.path.dirname(abs_path) + ':' + os.path.basename(abs_path)
    if IsInDir(abs_path, GetBaseDir()):
        result = '//%s' % os.path.relpath(result, GetBaseDir())
    else:
        Util.Abort('invalid path: (%s, %s)' % (cur_dir, path))
    return result
Example #7
0
    def _TopologySort(self, obj_list):
        out_map = {}
        objs = [] + obj_list
        result = []
        for item in obj_list:
            if not self.HasObj(item):
                out_map[item] = 0
                continue
            obj = self.GetObjByName(item)
            out_map[item] = len(obj.depends_)
        pass
        for i in range(len(obj_list)):
            found = False
            for idx in range(len(objs) - 1, -1, -1):
                if out_map[objs[idx]] == 0:
                    found = True
                    break

            if not found:
                # found loop, now remove all leaf nodes
                sz = 0
                while (sz != len(out_map)):
                    sz = len(out_map)
                    keys = out_map.keys()
                    for dep in keys:
                        dep_num = 0
                        for obj_name in keys:
                            if (obj_name == dep):
                                continue
                            if dep in self.GetObjByName(obj_name).depends_:
                                dep_num += 1
                        if dep_num == 0:
                            del out_map[dep]
                Util.Abort('Found dependency loop: %s' %
                           ' '.join(out_map.keys()))

            key = objs[idx]
            result.append(key)
            for k in out_map.iterkeys():
                if not self.HasObj(k):
                    continue
                if key in self.GetObjByName(k).depends_:
                    out_map[k] -= 1

            del out_map[key]
            objs.pop(idx)
        result.reverse()
        return result
Example #8
0
 def _AddBuilders(self):
     for lang in _Languages.split():
         command = 'from %s import %sBuilder; lang_builder = %sBuilder()' % (
             lang, lang, lang)
         try:
             exec(command)
         except:
             traceback.print_exc()
             Util.Abort('exec failed: %s.' % command)
         self.lang_builders_.append((lang, lang_builder))
         registers = lang_builder.GetSnakeRegisterers()
         #cc_binary cc_library  thrift_library
         for r in registers:
             self.builders_[r] = lang_builder
         lang_builder.GenerateEnv(self.env_)
         builders = lang_builder.RegisterSnakeBuilders()
         if len(builders) > 0:
             self.env_.Append(BUILDERS=builders)
Example #9
0
def Init_Also(Util_only):
    "This is the 3rd Init stage, done after getopts, etc"
    "usually called at the end of &main::Init"

    if Globals.Debug:
        print("Debug Quiet Verbose", Globals.Debug, Globals.Quiet,
              Globals.Verbose)

    Util.Show_INC
    #our $GUI = ($ENV{DISPLAY} eq '') ? 0 : 1;        # !!! but what about Win32?
    Globals.GUI = 0

    #!!! we can probably lose this test, since disty.pm is the only declarer
    #     of $Util_Only, since no one else uses Init.pm!
    if not Globals.Util_only:  # Session = '' ...
        if not Globals.SessionForce:
            Stats.Session('next')  # Sets the next Session No.
        else:
            Globals.Stats['Session'] = Globals.Session
            Pid = Stats.Session('read')
            # Returns 0 if available
            # check the process table ...
            if Globals.Pid and not Globals.Pid == Globals.Stats[
                    'PID'] or Is_Running(GLobals.Pid, 1):
                # The requested session is already running!
                if not Globals.SessionForce:
                    Exit(107, "Session %i start declined" % Globals.Session)
                Print_Log(11, "Forcing session %i" % Session)
            Stats.Session('write')  # Tags the Session.
        if not os.path.isdir(Globals.FileTmpDir):
            try:
                os.mkdir(Globals.FileTmpDir)
            except:
                exit("Unable to Create tmp dir %s" % Globals.FileTmpDir)
        Globals.FileTmpDir += Globals.PathSep + 's' + str(
            Globals.Stats['Session'])
        if not os.path.isdir(Globals.FileTmpDir):
            try:
                os.mkdir(Globals.FileTmpDir)
            except:
                exit("Unable to Create tmp dir %s" % Globals.FileTmpDir)
        Logs.Arc_Logs(Globals.FileTmpDir, '_logs')
        os.umask(0)
        Arc_File = "2arc2_logs_" + str(Util.PT_Date(time.time(), 5))
        try:
            if Globals.Verbose:
                print("Init_Also Creating arc file %s " %
                      join(Globals.FileTmpDir, Arc_File))
            fh = open(join(Globals.FileTmpDir, Arc_File), "w")
            #close(fh)
        except:
            exit("Unable to create Arc_File %s" %
                 join(Globals.FileTmpDir, Arc_File))

    # Set up log files...
    Log_Str = ''
    Globals.XLog = join(Globals.FileTmpDir, Globals.Main) + r".log"
    #!!!    &Read_Version;
    Msg = Get_Release_Info  # Sets $Version, etc or Aborts on error!
    if not Globals.Quiet: print("\n\n")
    if Globals.Stats['Session']:
        Log_Str += "Session " + str(Globals.Stats['Session']) + ": "
    Log_Str += "Starting %s version %s at %s" % (
        Globals.Main, Globals.TestData['Ver'], Util.PT_Date(time.time(), 2))
    Globals.Erc = Logs.Print_Log(1, Log_Str)
    Log_Str = ''
    if Globals.Erc: Util.Exit(3, "(%s)" % Globals.Xlog)
    Logs.Print_Log(
        11, "This PID = %s, ShellPID = %s" %
        (Globals.Stats['PID'], Globals.Stats['PPID']))
    if Globals.Debug: print("Init_also GP_Path %s" % Globals.GP_Path)
    Logs.Print_Log(11, 'path = ' + Globals.GP_Path)
    #for Module in  sys.modules['os'] :
    #Vers = Globals.CMtestVersion[FileOp.fnstrip(sys.modules['os'], 7)]
    #Module  = sys.modules['OS']  #Value (Full path / filename)
    #if Module[0:1] == '.' :
    #Module = join(os.getcwd(),Module)
    #Log_Str = "Lib: " + Module
    #if Vers == '' : Log_Str += "\t[Ver: %s]" % Vers
    #if not str.find(Module, "python") : Print_Log (11, Log_Str)
    #IncAge = time.time() - stat.st_mtime(Module)
    #if IncAge < 1000 : Print_Log (1, "Using new Module")

    Log_Str = ''

    if not Util_only:  # Required for test oriented scripts only ...
        Util.Abort('clear')
        # Remove any lurking abort flags
        Globals.Stats['Status'] = 'UserID'
        Globals.Stats['Power'] = 0  #Power supply on count
        Stats.Update_All()
        if Globals.GlobalVar['UserID_Check'] == 1:
            UserID_tmp = ''
            if Globals.CurrentUserID == 'none':
                Globals.CurrentUserID = Util.Ask_User(
                    'text16', 'UserID', 'Please enter your UserID#')
            UserID_tmp = bcrypt.hashpw(
                Globals.CurrentUserID.encode('utf-8'), bcrypt.gensalt(
                ))  # Still need to figure out key in python $Key;
            if Globals.Debug:
                print("Init user password hash is : %s" % UserID_tmp)
            UID_Check(UserID_tmp)  #Exit on fail!  Use adduser.pl ...
            Globals.Stats['UserID'] = UserID

        Globals.Stats['Status'] = 'Menu'
        Stats.Update_All()

        Globals.Comm_Log = join(Globals.FileTmpDir, "Comm.log")
        # system "rm -f $Comm_Log";        # OR
        #        &Rotate_Log ($Comm_Log, 10);
        # Aborts on error!
        Util.Abort('check')  # Make sure there isn't an ABORT flag lurking

        # Figure the UUT_IP address ...

        IPA = Globals.GlobalVar['UUT_IP_Base'].split(r".")
        IPAint = int(IPA[3])
        UUT_IP_Top = IPAint + int(
            Globals.GlobalVar['UUT_IP_Range']) - 1  # Highest sub allowed
        IPAint += int(Globals.Stats['Session']) - 1  # 1 per session or
        if IPAint > UUT_IP_Top:
            Exit(28, "No IP addr available for this session")
        Globals.UUT_IP = "%s.%s.%s.%s" % (IPA[0], IPA[1], IPA[2], IPAint)
        IPAint += 1  ##$IPA[3]++;  There is a possibility of conflict, but we shuld end up using 2 session if the second IP is used.
        if IPAint > UUT_IP_Top:
            Exit(28, "No Secondary IP addr available for this session")
        Globals.UUT_IP_SEC = "%s.%s.%s.%s" % (IPA[0], IPA[1], IPA[2], IPAint)

        Logs.Print_Log(11, "UUT_IP  = %s" % Globals.UUT_IP)
        Logs.Print_Log(11, "CmdFilePath = %s" % Globals.CmdFilePath)
        # Assign the output file ...
        Globals.Out_File = join(Globals.FileTmpDir,
                                Globals.Out_File)  # Default is cmtest.xml
        try:
            os.remove(Out_File)
        except:
            pass
        Logs.Print_Out_XML_Tag('Test')
        Globals.Erc = 0
        Stats.Update_All

        PT_Log = join(Globals.FileTmpDir, "Expect.log")
        try:
            os.remove(PT_Log)
        except:
            pass
    return
Example #10
0
def Process_Cmd_File(Comm, File, Check_Only, No_Worries="", Cached=0):
    "Loop through command files"
    CFName = FileOp.fnstrip(File, 3)
    Endtime = ''
    if not os.path.exists(File) and No_Worries:
        return (0)
        #Only execute it it
    # the file exists
    fh = ''
    if Check_Only: Msg = "Syntax checking"
    else: Msg = 'Processing'
    Msg += " Cmd file \'%s\'" % CFName
    if Check_Only or Debug or Verbose: Logs.Print_Log(1, "%s ..." % Msg)
    if len(Globals.FH) > Globals.CmdFileNestLmt:
        Util.Exit(999, "Cmd files nested too deep!")
    if not os.path.exists(File):
        try:
            fh = open(File, 'r')
            Globals.FH.append(fh)

        except:
            Util.Exit(2, "Can\'t open Cmd file %s" % File)

    Line = 0
    Done = 0
    val = ()
    with open(File, 'r') as fh:
        for line in fh:
            val = ()
            Comm = Init_Product1.Comm_Current
            #HA Update our Port pointer, incase it changed
            if not (Check_Only and Line == 0):
                Globals.Stats['Status'] = 'Active'
            if Check_Only and Line == 0: Globals.Stats['Status'] = 'Check'
            if Line == 0: Stats.Update_All
            Util.Abort("check")
            if not Done: Line += 1  # Tags the last line used
            if Done: Print_Log(11, "Command Done")
            if Done: continue
            Log_Str = "%s - Line %s\n" % (
                Msg, Line)  # This should now get written to the Expect log
            Util.chomp(line)
            #line.rstring      # Remove any leading/trailing whitespace
            # s/^\s*(.*)\s*[\n|\r]$/$1/;     # Remove returns/linfeeds  JSW 020106 - Fix for returns/linefeed added to INC files
            if line == "": continue  # (now) null lines
            if line[0] == "#": continue
            if line == "\n": continue
            if not Check_Only:
                Add_2_Flat_Cmd_File("\t\t\t\t# %s%s\n" % (Log_Str, line))
            p = re.compile(r"^\<[\/]?(\w+)\>\s*(.*)$"
                           )  # Get the keyword, now includes </bypass>
            val = p.findall(line)
            KeyWord = val[0][0]
            Raw_Arg_1 = Arg = val[0][1]
            #Arg = Arg.translate(None,string.whitespace)  # Remove any white space
            Raw_Arg_2 = Arg
            if Arg.find(r"^\$(.*)"):
                Logs.Print2XLog("Found Variable: %s = <%s>\n" % (Arg, Arg), 1)
            #p = re.compile(r"<(\/.*)\>")  #</Loop> will not have matched above Added to patter above
            #Keyword = p.findall(line)[0][0]
            if not Globals.Bypass:
                p = re.compile(r"/^\$(.*)\[(.*)\]\[(.*)\]->\{(.*)\}")
                val = p.findall(Arg)
                if Arg.find(r"^\$(.*)\[(.*)\]\[(2.*)\]->\{(.*)\})"
                            ) and not Check_Only and not KeyWord.find("set$"):
                    # Array of Hash ex: $UUT_Variable_ref[0][x]->{Sahasera}
                    Arg_save = Arg
                    pp = re.compile(r"^\$(.*)\[(.*)\]\[(.*)\]->\{(.*)\})")
                    val2 = pp.findall(Arg)
                    #now build or command UUT_Variable_ref[0][x][Sahasera]
                    Arg = pp[1][pp[2]][pp[3]][pp[4]]
                    Logs.Print2XLog(
                        "Found 2way Variable List->HASH: %s = %s" %
                        (Arg_save, Arg), 1)
                elif Arg.find(r"^\$(.*)\[(.*)\]->\{(.*)\}") and not Check_Only and \
                         not KeyWord.find("set$") :
                    # Array of Hash ex: $UUT_Variable_ref[0]->{Sahasera}
                    Arg_save = Arg
                    pp = re.compile(r"^\$(.*)\[(.*)\]->\{(.*)\}")
                    val2 = pp.findall(Arg)
                    #now build or command UUT_Variable_ref[0][Sahasera]
                    Arg = pp[1][pp[2]][pp[3]]
                    Logs.Print2XLog(
                        "Found Variable List->HASH: %s = %s" % (Arg_save, Arg),
                        1)
                elif  Arg.find(r"^\$(.*)\[(.*)\]\[(.*)\]") and  not Check_Only \
                       and  not KeyWord.find(r"set$") :
                    Arg_save = Arg
                    pp = re.compile(r"^\$(.*)\[(.*)\]\[(.*)\]")
                    val2 = pp.findall(Arg)
                    #now build or command UUT_Variable_ref[0][Sahasera]
                    Arg = pp[1][pp[2]][pp[3]]
                elif Arg.find(
                        r"^\$(.*)\[(.*)\]"
                ) and not Check_Only and not KeyWord.find(r"set$"):
                    Arg_save = Arg
                    pp = re.compile(r"^\$(.*)\[(.*)\]")
                    val2 = pp.findall(Arg)
                    #now build or command UUT_Variable_ref[0][Sahasera]
                    Arg = pp[1][pp[2]]
                    Logs.Print2XLog(
                        "Found Variable List-: %s = <%s>" % (Arg_save, Arg), 1)
                    Logs.Print2XLog(
                        "Found 2 WAY Variable List-: %Arg_save = <%s>" %
                        (Arg_save, Arg), 1)
                elif Arg.find(r"^\$(.*)") and not Check_Only and not KeyWord.find(r"set$") \
                     and  not Arg.find(r"^\$\{(.*)\}/") :
                    pp = re.compile(r"^\$(.*)")
                    val2 = pp.findall(Arg)
                    #now build or command UUT_Variable_ref[0][Sahasera]
                    Arg = pp[1]
                    Logs.Print2XLog(
                        "Found Variable: <%s> = %s, Raw: %s : %s : %s " %
                        (Arg, Arg, Raw_Arg_1, Raw_Arg_2, val), 1)
                elif Arg.find(r"\$w+"):
                    Logs.Print2XLog(
                        "Warning: Found Possible Variable in : %s" % Arg)
                elif Arg.find(r"\[(.*)\]{3,}"):
                    Logs.Print2XLog(
                        "Warning: Found Possible Variable dimension too deep : %s"
                        % Arg)

                if not Check_Only:
                    Tag(
                        Cached, "Reading %s line %s\: %s=%s" %
                        (CFName, Line, KeyWord, Arg))
                #        unless ($KeyWord =~ /ctrl-\w?|end|wait|send|\/loop|getdata/) {
                if not KeyWord.find(
                        r"ctrl-\w?|end|wait|send|\/loop|\/bypass|getdata"):
                    # check to make sure $Arg is valid
                    Erc = 25
                    if Arg == '':
                        Util.Exit(
                            2,
                            "Null %s,%s,%s Arg at %s line %s: Cmd=\'%s\': Arg=\'%s\'"
                            % (Raw_Arg_1, Raw_Arg_2, Arg_save, CFName, Line,
                               KeyWord, Arg))
                    Erc = 0

                if Check_Only or not Caching or KeyWord.find("include"):
                    if not Globals.Bypass or KeyWord == r'/bypass':  # see if we are bypassing any code or ending bypass
                        Done = Exec_Cmd(Comm, CFName, Line, KeyWord, Arg,
                                        Check_Only, 0)
                    else:
                        Logs.Print_Log(11, "Bypass: %s %s" % KeyWord, Arg)
                elif KeyWord == r'/loop':  # Now exec everything in @LBuffer
                    while TestData['ATT'] < Loop_Time:
                        Endtime = PT_Date(time.time() + Stats['TTG'], 2)
                        Abort(check)
                        Stats['Loop'] += 1
                        Logs.Print_Log(
                            1, "%s: Starting loop %s (%s) End Time: %s)" %
                            (Session, Stats['Session'], Stats['Loop'],
                             Stats['TTG'], Endtime))
                        for Cmd in LBuffer:
                            if not Globals.Bypass or Cmd.find(
                                    "\/bypass"
                            ):  # see if we are bypassing any code or ending bypass
                                Print_Log(11, "LBuffer Exec: " + Cmd)
                                Done = Exec_Cmd(
                                    Comm, Cmd.split(",,"))  # was /,/ 3/15/12
                            else:
                                Print_Log(11, "Bypass: "******"Ending loop: ATT = %s, LoopTime = %s" %
                            (TestData['ATT'], Loop_Time))
                    Tag(Cached, "Ending loop after %s cycles" % Stats['Loop'])
                    Caching = 0  # Turns off caching, ready to execute
                    Loop_Time = 0
                    LBuffer = [
                    ]  # In case a crazy want's to start another loop!
                else:
                    Print_Log(
                        11, "Caching: %s,%s,%s,%s,%s,1" %
                        (CFName, Line, KeyWord, Arg, Check_Only))
                    LBuffer.append("%s,,%s,,%s,,%s,,%s,,1" %
                                   (CFName, Line, KeyWord, Arg, Check_Only))
    # end of while
    Tag(Cached, "Closing cmd file %s at line %s" % (File, Line))
    #Globals.FH[-1].close
    if len(Globals.FH):
        fh = Globals.FH.pop(-1)
        fh.close
    return ()