예제 #1
0
파일: make.py 프로젝트: ilfirin-ms/pymake2
def archive(archiver, flags, objects, library):
  if type(objects) is list:
    objs = ' '.join(objects)
  else:
    objs = objects
    
  objectsList = objs.split()

  satisfactionFlag = False
  if os.path.isfile(library):
    satisfactionFlag = True
    output_mTime = os.path.getmtime(library)
    for obj in objectsList:
      obj_mtime = os.path.getmtime(obj)
      if obj_mtime > output_mTime:
        satisfactionFlag = False
        break
  
  if not satisfactionFlag:
    util.print_color('Archiving...', util.tty_colors_cmds.On_Blue)
    cmd = '{AR} {flags} {output} {objs}'.format(AR=archiver, flags=flags, objs=objs, output=library)
    hl = util.is_Highlight_ON()
    success, outputs = sh(cmd, True, hl)
    if hl:
      print(_Highlight_Outputs(outputs))
    
    if not success:
      util.print_color("Failed to archive object files to assemble '%s'" % library, util.tty_colors_cmds.BRed)
      return False
    else:
      return True
  else:
    return True
예제 #2
0
파일: pymake2.py 프로젝트: yoyonel/pymake2
    def check_dependencies(self):
        if len(self.Dependencies) == 0:
            return True

        util.print_color('Dependency checking of Target "%s"' % self.Name,
                         util.tty_colors_cmds.On_Cyan)
        for i, item in enumerate(self.Dependencies):
            if type(item) is list:
                for sub_item in item:  # assumed to be list of file names (paths)
                    if not os.path.isfile(sub_item):
                        util.write_color(
                            'Dependency Error @ Target "%s": ' % self.Name,
                            util.tty_colors_cmds.BRed)
                        print('%s does not exist!' % sub_item)
                        return False
            elif type(item) is str:
                if not os.path.isfile(item):
                    util.write_color(
                        'Dependency Error @ Target "%s": ' % self.Name,
                        util.tty_colors_cmds.BRed)
                    print('%s does not exist!' % item)
                    return False
            elif type(item) is TargetT:  # another target
                if not item.run():
                    util.write_color(
                        'Dependency Error @ Target "%s": ' % self.Name,
                        util.tty_colors_cmds.BRed)
                    print('Target "%s" failed' % item.Name)
                    return False

        return True
예제 #3
0
파일: make.py 프로젝트: ilfirin-ms/pymake2
def link(linker, flags, objects, executable):
  if type(objects) is list:
    objs = ' '.join(objects)
  else:
    objs = objects.strip().strip('\n')
    
  objectsList = objs.split()

  linkFlag = True
  if os.path.isfile(executable):
    linkFlag = False
    exe_mTime = os.path.getmtime(executable)
    for obj in objectsList:
      obj_mtime = os.path.getmtime(obj)
      if obj_mtime > exe_mTime:
        linkFlag = True
        break
  
  if linkFlag:
    util.print_color('Linking ...', util.tty_colors_cmds.On_Blue)
    cmd = '{linker} {flags} {objs} -o {executable}'.format(linker=linker, flags=flags, objs=objs, executable=executable)
    hl = util.is_Highlight_ON()
    success, outputs = sh(cmd, True, hl)
    if hl:
      print(_Highlight_Outputs(outputs))
    
    if not success:
      util.print_color("Failed to link object files to assemble '%s'"%executable, util.tty_colors_cmds.BRed)
      return False
    else:
      return True
  else:
    return True
예제 #4
0
파일: make.py 프로젝트: saudalwasly/pymake2
def compile(compiler, flags, sources, objects):
    # utl.print_color('Compiling ...', utl.tty_colors.On_Cyan)
    Highlight_NO = True if util.is_Highlight_ON() else False

    if type(sources) is list:
        srcs = sources
    else:  # in the case of str
        srcs = sources.split()

    if type(objects) is list:
        objs = objects
    else:  # in the case of str
        objs = objects.split()

    if len(srcs) != len(objs):
        util.write_color('Error: ', util.tty_colors_cmds.Red)
        print 'the length of the source files list does not match with objects files list'
        return

    for i, item in enumerate(srcs):
        cmd = '{CC} {flags} -c {src} -o {obj}'.format(CC=compiler,
                                                      flags=flags,
                                                      src=item,
                                                      obj=objs[i])

        srcFile = os.path.basename(item)
        objFile = os.path.basename(objs[i])
        srcFile = srcFile.split('.')[0]
        objFile = objFile.split('.')[0]
        if srcFile != objFile:
            util.write_color('Compiling Error: ', util.tty_colors_cmds.BRed)
            print 'source file %s and object file %s do not match. Make sure that the source and the object files lists are correspondent' % (
                item, objs[i])
            return False
        if os.path.isfile(objs[i]):  # if the object file already exists
            src_mTime = os.path.getmtime(item)
            obj_mtime = os.path.getmtime(objs[i])
            if src_mTime <= obj_mtime:
                continue
        else:  # no obj file exists
            objDir = os.path.dirname(objs[i])
            objDir = os.path.normpath(objDir)
            if not os.path.exists(objDir):
                os.makedirs(objDir)

        util.print_color('Compiling: %s' % item, util.tty_colors_cmds.On_Cyan)
        success, outputs = sh(cmd, True, Highlight_NO)
        if Highlight_NO:
            print(_Highlight_Outputs(outputs))

        if not success:
            # if not run(cmd, show_cmd=True):
            util.write_color('Error: ', util.tty_colors_cmds.BRed)
            print 'failed to compile, \n  %s' % cmd
            return False

    return True
예제 #5
0
파일: make.py 프로젝트: ilfirin-ms/pymake2
def sh(cmd, show_cmd=False, CaptureOutput = False, Timeout = -1):
  if show_cmd:
    print(cmd)
  try:
    if CaptureOutput:
      if Timeout > -1:
        P = sarge.run(cmd, shell=True, stdout=sarge.Capture(), stderr=sarge.Capture(), async_=True)
        # sleep(3)
        try:
          CMD = P.commands[0] #type: sarge.Command # FIXME: This line generates index exception sometime
          timed_out = util.wait_process(Timeout, CMD)
          if timed_out:
            util.print_color('The command "%s" is timed out!'%cmd, util.tty_colors_cmds.On_Red)
          util.kill_alive_process(CMD)
        except:
          pass
      else:
        P = sarge.run(cmd, shell=True, stdout=sarge.Capture(), stderr=sarge.Capture())
    else:
      if Timeout > -1:
        P = sarge.run(cmd, shell=True, async_=True)
        # sleep(3)
        try:
          CMD = P.commands[0] #type: sarge.Command # FIXME: This line generates index exception sometime
          timed_out = util.wait_process(Timeout, CMD)
          if timed_out:
            util.print_color('The command "%s" is timed out!'%cmd, util.tty_colors_cmds.On_Red)
          util.kill_alive_process(CMD)
        except:
          pass
      else:
        P = sarge.run(cmd, shell=True)
    
    outputs = ''

    if P.stdout and len(P.stdout.text) > 0:
      outputs = P.stdout.text
    if P.stderr and len(P.stderr.text) > 0:
      if outputs == '':
        outputs = P.stderr.text
      else:
        outputs += '\n' + P.stderr.text
    return P.returncode == 0, outputs
  except:
    if util.get_makefile_var('Debug') == True:
      util.Print_Debuging_messages()
  
    return False, ''
예제 #6
0
파일: make.py 프로젝트: ilfirin-ms/pymake2
def eval(txt):
  outerframe = inspect.stack()[1][0]
  outerframeGlobals = outerframe.f_globals
  
  vars = re.findall(r'\$\((\w+)\)', txt)
  newtxt = re.sub(r'\$\((\w+)\)', r'{\1}', txt)
  
  for v in vars:
    try:
      val = outerframeGlobals[v]
      if type(val) is list:
        val = ' '.join(val)
      newtxt = newtxt.replace('{%s}'%v, val)
    except:
      val = os.getenv(v)
      if val:
        newtxt = newtxt.replace('{%s}' % v, val)
      else:
        util.print_color('Error: cannot find variable %s' % v, util.tty_colors_cmds.Red)
        sys.exit()
  return newtxt
예제 #7
0
파일: pymake2.py 프로젝트: yoyonel/pymake2
    def run(self):
        if self.check_dependencies():
            util.print_color('Executing Target "%s"' % self.Name,
                             util.tty_colors_cmds.On_Cyan)
            try:
                if len(self.args_var) == 0:
                    ret_v = self.func()
                else:
                    ret_v = self.func(*self.args_var)

                if not ret_v:
                    util.print_color('Target "%s" failed' % self.Name,
                                     util.tty_colors_cmds.BRed)
                return ret_v
            except:
                util.print_color(
                    'Internal error in the target function "%s"' % self.Name,
                    util.tty_colors_cmds.BRed)
                if debug:
                    traceback.print_exc()

        else:
            return False
예제 #8
0
파일: pymake2.py 프로젝트: yoyonel/pymake2
def main():
    global debug, highlight_errors, highlight_warnings
    parser = argparse.ArgumentParser(
        description='pymake2 is a simple make system implemented in python')
    parser.add_argument(
        't', metavar='Target',
        help='the make target in the makefile').completer = complete_targets
    parser.add_argument('-f',
                        metavar='MakefilePath',
                        help='to pass a makefile, default = ./makefile.py')
    # parser.add_argument('-t', metavar='Target', help='the make target in the make file').completer = complete_targets
    parser.add_argument('-j',
                        metavar='Jobs',
                        type=int,
                        help='number of jobs used in the make process')

    argcomplete.autocomplete(parser)
    if len(sys.argv) > 1:
        args = parser.parse_args()
    else:
        args = ArgsT()

    if args.f:
        makefile_path = args.f
    elif auto_target():
        makefile_path = './makefile.py'
    else:
        ret_v = input('No makefile exists!, do you want to creat one?(y/n): ')
        if ret_v.lower() == 'y':
            with open('makefile.py', 'wb') as io_makefile:
                io_makefile.write(gccTemplate)
        sys.exit()

    import imp
    pkg_dir = os.path.normpath(os.path.dirname(__file__) + '/../')
    sys.path.insert(0, pkg_dir)
    if os.path.exists('/opt/pymake2'):
        sys.path.insert(0, '/opt/')

    makefile_m = imp.load_source('makefileM', makefile_path)
    make.shell('rm -f *.pyc')
    debug = getattr(makefile_m, 'Debug', False)
    highlight_errors = getattr(makefile_m, 'HighlightErrors', False)
    highlight_warnings = getattr(makefile_m, 'HighlightWarnings', False)
    targets = parse_makefile(makefile_path,
                             makefile_m)  # type: Dict[str, TargetT]

    if args.t:
        try:
            selected_target = targets[args.t.strip()]  # type: TargetT
            # func = getattr(makefileM, args.t)
        except:
            util.print_color(
                'Error: target function "%s" does not exist!' % args.t,
                util.tty_colors_cmds.BRed)
            if debug:
                traceback.print_exc()
            sys.exit()

        ret_v = selected_target.run()
        return ret_v

        # attrs = dir(makefileM)
        # for attr in attrs:
        #   if attr==args.t:
        #     func = getattr(makefileM, args.t)

    else:
        print('No target to build, exiting...')
        sys.exit()