Example #1
0
 def __call__(self, args=None):
     sys.excepthook = self.handle
     if args is None:
         args = sys.argv[1:]
     if optcomplete:
         optcomplete.autocomplete(self.parser, self.arg_completer)
     elif 'COMP_LINE' in os.environ:
         return 0
     (options, args) = self.parser.parse_args(expand_args(args))
     _CONSOLE.setLevel(options.loglevel)
     if options.logfile:
         logfile = logging.FileHandler(options.logfile)
         logfile.setFormatter(
             logging.Formatter('%(asctime)s, %(levelname)s, %(message)s'))
         logfile.setLevel(logging.DEBUG)
         logging.getLogger().addHandler(logfile)
     if options.debug:
         logging.getLogger().setLevel(logging.DEBUG)
     else:
         logging.getLogger().setLevel(logging.INFO)
     if options.debug:
         import pdb
         return pdb.runcall(self.main, options, args)
     else:
         return self.main(options, args) or 0
Example #2
0
 def __call__(self, args=None):
     sys.excepthook = self.handle
     if args is None:
         args = sys.argv[1:]
     if optcomplete:
         optcomplete.autocomplete(self.parser, self.arg_completer)
     elif 'COMP_LINE' in os.environ:
         return 0
     (options, args) = self.parser.parse_args(expand_args(args))
     _CONSOLE.setLevel(options.loglevel)
     if options.logfile:
         logfile = logging.FileHandler(options.logfile)
         logfile.setFormatter(
             logging.Formatter('%(asctime)s, %(levelname)s, %(message)s'))
         logfile.setLevel(logging.DEBUG)
         logging.getLogger().addHandler(logfile)
     if options.debug:
         logging.getLogger().setLevel(logging.DEBUG)
     else:
         logging.getLogger().setLevel(logging.INFO)
     if options.debug:
         import pdb
         return pdb.runcall(self.main, options, args)
     else:
         return self.main(options, args) or 0
Example #3
0
def main(args):
  parser = optparse.OptionParser()
  parser.add_option('-C', '--serve-dir',
      help='Serve files out of this directory.',
      default=os.path.abspath('.'))
  parser.add_option('-p', '--port',
      help='Run server on this port.', default=5103)
  parser.add_option('--no-dir-check', '--no_dir_check',
      help='No check to ensure serving from safe directory.',
      dest='do_safe_check', action='store_false', default=True)
  parser.add_option('--test-mode',
      help='Listen for posts to /ok or /fail and shut down the server with '
          ' errorcodes 0 and 1 respectively.',
      action='store_true')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete httpd.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(args)
  if options.do_safe_check:
    SanityCheckDirectory(options.serve_dir)

  server = LocalHTTPServer(options.serve_dir, int(options.port),
                           options.test_mode)

  # Serve until the client tells us to stop. When it does, it will give us an
  # errorcode.
  print 'Serving %s on %s...' % (options.serve_dir, server.GetURL(''))
  return server.ServeForever()
Example #4
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-C', '--serve-dir',
      help='Serve files out of this directory.',
      default=os.path.abspath('.'))
  parser.add_argument('-p', '--port',
      help='Run server on this port.', default=5103)
  parser.add_argument('--no-dir-check', '--no_dir_check',
      help='No check to ensure serving from safe directory.',
      dest='do_safe_check', action='store_false', default=True)

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete httpd.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(args)
  if options.do_safe_check:
    SanityCheckDirectory(options.serve_dir)

  server = LocalHTTPServer(options.serve_dir, int(options.port))

  # Serve until the client tells us to stop. When it does, it will give us an
  # errorcode.
  print 'Serving %s on %s...' % (options.serve_dir, server.GetURL(''))
  return server.ServeForever()
Example #5
0
 def handle_completion(self):
     if self.is_completion_active():
         gparser = self.create_global_parser(no_usage=True, add_help=False)
         # set sys.path to COMP_LINE if it exists
         self._init_completion()
         # fetch the global options
         gopts = self.get_global_opts()
         # try to load StarClusterConfig into global options
         if gopts:
             try:
                 cfg = config.StarClusterConfig(gopts.CONFIG)
                 cfg.load()
             except exception.ConfigError:
                 cfg = None
             gopts.CONFIG = cfg
         scmap = {}
         for sc in commands.all_cmds:
             sc.gopts = gopts
             for n in sc.names:
                 scmap[n] = sc
         listcter = optcomplete.ListCompleter(scmap.keys())
         subcter = optcomplete.NoneCompleter()
         optcomplete.autocomplete(gparser, listcter, None, subcter,
                                  subcommands=scmap)
         sys.exit(1)
Example #6
0
def main(args):
    parser = optparse.OptionParser()
    parser.add_option("-C", "--serve-dir", help="Serve files out of this directory.", default=os.path.abspath("."))
    parser.add_option("-p", "--port", help="Run server on this port.", default=5103)
    parser.add_option(
        "--no-dir-check",
        "--no_dir_check",
        help="No check to ensure serving from safe directory.",
        dest="do_safe_check",
        action="store_false",
        default=True,
    )

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete httpd.py
    try:
        import optcomplete

        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(args)
    if options.do_safe_check:
        SanityCheckDirectory(options.serve_dir)

    server = LocalHTTPServer(options.serve_dir, int(options.port))

    # Serve until the client tells us to stop. When it does, it will give us an
    # errorcode.
    print "Serving %s on %s..." % (options.serve_dir, server.GetURL(""))
    return server.ServeForever()
Example #7
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-C', '--serve-dir',
      help='Serve files out of this directory.',
      default=os.path.abspath('.'))
  parser.add_argument('-p', '--port',
      help='Run server on this port.', default=7777)
  parser.add_argument('--no-dir-check', '--no_dir_check',
      help='No check to ensure serving from safe directory.',
      dest='do_safe_check', action='store_false', default=True)

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete httpd.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(args)
  if options.do_safe_check:
    SanityCheckDirectory(options.serve_dir)

  server = LocalHTTPServer(options.serve_dir, int(options.port))

  # Serve until the client tells us to stop. When it does, it will give us an
  # errorcode.
  print(('Serving {0} on {1}...'.format(options.serve_dir, server.GetURL(''))))
  return server.ServeForever()
Example #8
0
def main(argv):
  usage = 'Usage: %prog [options] <.nexe/.pexe or .nmf>'
  epilog = 'Example: create_html.py -o index.html my_nexe.nexe'
  parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
  parser.add_option('-v', '--verbose', action='store_true',
                    help='Verbose output')
  parser.add_option('-d', '--debug-libs', action='store_true',
                    help='When calling create_nmf request debug libaries')
  parser.add_option('-o', '--output', dest='output',
                    help='Name of html file to write (default is '
                         'input name with .html extension)',
                    metavar='FILE')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete create_html.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)

  if not args:
    parser.error('no input file specified')

  if options.verbose:
    Log.enabled = True

  CreateHTML(args, options)
  return 0
Example #9
0
def main(argv):
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('-v', '--verbose', action='store_true',
                      help='Verbose output')
  parser.add_argument('-d', '--debug-libs', action='store_true',
                      help='When calling create_nmf request debug libaries')
  parser.add_argument('-o', '--output', dest='output',
                      help='Name of html file to write (default is '
                           'input name with .html extension)',
                      metavar='FILE')
  parser.add_argument('exe', metavar='EXE_OR_NMF', nargs='+',
                      help='Executable (.nexe/.pexe) or nmf file to generate '
                           'html for.')
  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete create_html.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(argv)

  if options.verbose:
    Log.enabled = True

  CreateHTML(options.exe, options)
  return 0
Example #10
0
def main(argv):
    usage = 'Usage: %prog [options] <.nexe | .so>'
    epilog = 'Example: ncval.py my_nexe.nexe'
    parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      help='Verbose output')

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete ncval.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(argv)
    if not args:
        parser.error('No executable file specified')

    nexe = args[0]
    if options.verbose:
        Log.verbose = True

    # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the
    # amount of additional checking done here.
    osname = getos.GetPlatform()
    if not os.path.exists(nexe):
        raise Error('executable not found: %s' % nexe)
    if not os.path.isfile(nexe):
        raise Error('not a file: %s' % nexe)

    ncval = os.path.join(SCRIPT_DIR, 'ncval')
    if osname == 'win':
        ncval += '.exe'

    cmd = [ncval, nexe]
    Log('Running %s' % ' '.join(cmd))
    proc = subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    proc_out, _ = proc.communicate()
    if proc.returncode:
        # ncval doesn't print anything to stderr.
        sys.stderr.write('Validating %s failed:\n' % nexe)
        sys.stderr.write(proc_out + '\n')

        Log('Changing the modification time of %s to 0.' % nexe)
        # "untouch" the executable; that is, change the modification time to be so
        # old that it will be remade when `make` runs.
        statinfo = os.stat(nexe)
        mtime = 0
        os.utime(nexe, (statinfo.st_atime, mtime))

        return proc.returncode
    elif options.verbose:
        # By default, don't print anything on success.
        Log(proc_out)
Example #11
0
def CommandLineHandler():
    """Option parser interface."""

    # Create optparse instance
    parser = optparse.OptionParser()

    # Add the parser options
    parser.add_option(
        "--just-dot", action="store_true", dest="just_dot", default=False, help="Just print out the dot lines"
    )
    parser.add_option("--debug", action="store_true", dest="debug", default=False, help="Debug Mode")

    # Bash Autocompletion code:
    try:
        import optcomplete

        optcomplete_on = True
    except:
        optcomplete_on = False
    if optcomplete_on:
        optcomplete.autocomplete(parser)

        # Parse the command line options
    options, remainder = parser.parse_args()

    return options, remainder
Example #12
0
def CommandLineHandler():
    """Option parser interface."""

    # Create optparse instance
    parser = optparse.OptionParser()

    # Add the parser options
    parser.add_option('--just-dot',
                      action="store_true",
                      dest="just_dot",
                      default=False,
                      help="Just print out the dot lines")
    parser.add_option('--debug',
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="Debug Mode")

    # Bash Autocompletion code:
    try:
        import optcomplete
        optcomplete_on = True
    except:
        optcomplete_on = False
    if optcomplete_on:
        optcomplete.autocomplete(parser)

    # Parse the command line options
    options, remainder = parser.parse_args()

    return options, remainder
Example #13
0
def main(argv):
  usage = 'Usage: %prog [options] <.nexe/.pexe or .nmf>'
  epilog = 'Example: create_html.py -o index.html my_nexe.nexe'
  parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
  parser.add_option('-v', '--verbose', action='store_true',
                    help='Verbose output')
  parser.add_option('-d', '--debug-libs', action='store_true',
                    help='When calling create_nmf request debug libaries')
  parser.add_option('-o', '--output', dest='output',
                    help='Name of html file to write (default is '
                         'input name with .html extension)',
                    metavar='FILE')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete create_html.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)

  if not args:
    parser.error('no input file specified')

  if options.verbose:
    Log.enabled = True

  CreateHTML(args, options)
  return 0
Example #14
0
def main(argv):
    usage = "Usage: %prog [options] <.nexe/.pexe or .nmf>"
    epilog = "Example: create_html.py -o index.html my_nexe.nexe"
    parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
    parser.add_option("-v", "--verbose", action="store_true", help="Verbose output")
    parser.add_option("-d", "--debug-libs", action="store_true", help="When calling create_nmf request debug libaries")
    parser.add_option(
        "-o",
        "--output",
        dest="output",
        help="Name of html file to write (default is " "input name with .html extension)",
        metavar="FILE",
    )

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete create_html.py
    try:
        import optcomplete

        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(argv)

    if not args:
        parser.error("no input file specified")

    if options.verbose:
        Log.enabled = True

    CreateHTML(args, options)
    return 0
Example #15
0
def main(args):
  usage = '%prog [<options>] [<phase...>]'
  parser = optparse.OptionParser(description=__doc__, usage=usage)
  parser.add_option('--experimental', help='build experimental tests',
                    action='store_true')
  parser.add_option('--verbose', '-v', help='Verbose output',
                    action='store_true')

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete test_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(args[1:])

  pepper_ver = str(int(build_version.ChromeMajorVersion()))
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  toolchains = ['newlib', 'glibc', 'pnacl']
  toolchains.append(getos.GetPlatform())

  if options.verbose:
    build_projects.verbose = True

  phases = [
    ('build_examples', StepBuildExamples, pepperdir),
    ('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental),
    ('build_tests', StepBuildTests, pepperdir),
    ('sel_ldr_tests', StepRunSelLdrTests, pepperdir),
    ('browser_tests', StepRunBrowserTests, toolchains, options.experimental),
  ]

  if args:
    phase_names = [p[0] for p in phases]
    for arg in args:
      if arg not in phase_names:
        msg = 'Invalid argument: %s\n' % arg
        msg += 'Possible arguments:\n'
        for name in phase_names:
          msg += '   %s\n' % name
        parser.error(msg.strip())

  for phase in phases:
    phase_name = phase[0]
    if args and phase_name not in args:
      continue
    phase_func = phase[1]
    phase_args = phase[2:]
    phase_func(*phase_args)

  return 0
Example #16
0
def main(argv=None, show_help=False):

    argv = argv or sys.argv[1:]

    # Set the script name to ``amp`` so that OptionParser error messages don't
    # display a meaningless ``main.py`` to end users.
    sys.argv[0] = 'amp'

    usage = ("""Usage: amp <command> [options]
    \nCommands:
    \n%s
    version  show the version number and exit
    \nSee `amp help <command>` for more info on a specific command.""" %
    '\n'.join("    %-8s %s" % (cmd, COMMANDS[cmd].help) for cmd in sorted(COMMANDS))
    )

    autocomplete(
        OptionParser(add_help_option=False),
        ListCompleter(AUTOCOMPLETE_COMMANDS.keys()),
        subcommands=AUTOCOMPLETE_COMMANDS
        )

    if not argv:
        show_help = True
    else:
        command = argv[0]
        argv = argv[1:]
        if command in ['-h', '--help']:
            show_help = True
        elif command == 'help':
            if argv:
                command = argv[0]
                argv = ['--help']
            else:
                show_help = True
        if command in ['-v', '--version', 'version']:
            print('amp %s' % ampify.__release__)
            sys.exit()

    if show_help:
        print(usage)
        sys.exit(1)

    if command in COMMANDS:
        return COMMANDS[command](argv)

    # We support git-command like behaviour. That is, if there's an external
    # binary named ``amp-foo`` available on the ``$PATH``, then running ``amp
    # foo`` will automatically delegate to it.
    try:
        output, retcode = run_command(
            ['amp-%s' % command] + argv, retcode=True, redirect_stdout=False,
            redirect_stderr=False
            )
    except CommandNotFound:
        exit("ERROR: Unknown command %r" % command)

    if retcode:
        sys.exit(retcode)
Example #17
0
def main(argv):
  usage = 'Usage: %prog [options] <.nexe | .so>'
  epilog = 'Example: ncval.py my_nexe.nexe'
  parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
  parser.add_option('-v', '--verbose', action='store_true',
                    help='Verbose output')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete ncval.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)
  if not args:
    parser.error('No executable file specified')

  nexe = args[0]
  if options.verbose:
    Log.verbose = True

  # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the
  # amount of additional checking done here.
  osname = getos.GetPlatform()
  if not os.path.exists(nexe):
    raise Error('executable not found: %s' % nexe)
  if not os.path.isfile(nexe):
    raise Error('not a file: %s' % nexe)

  ncval = os.path.join(SCRIPT_DIR, 'ncval')
  if osname == 'win':
    ncval += '.exe'

  cmd = [ncval, nexe]
  Log('Running %s' % ' '.join(cmd))
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  proc_out, _ = proc.communicate()
  if proc.returncode:
    # ncval doesn't print anything to stderr.
    sys.stderr.write('Validating %s failed:\n' % nexe)
    sys.stderr.write(proc_out + '\n')

    Log('Changing the modification time of %s to 0.' % nexe)
    # "untouch" the executable; that is, change the modification time to be so
    # old that it will be remade when `make` runs.
    statinfo = os.stat(nexe)
    mtime = 0
    os.utime(nexe, (statinfo.st_atime, mtime))

    return proc.returncode
  elif options.verbose:
    # By default, don't print anything on success.
    Log(proc_out)
Example #18
0
def install_autocomplete(parser):
    """
    Install automatic programmable completion support if available.
    Scripts should work even if it's not there.
    """
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass
Example #19
0
def install_autocomplete(parser):
    """
    Install automatic programmable completion support if available.
    Scripts should work even if it's not there.
    """
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass
Example #20
0
def parse_args():
    '''Parse the arguments using optparse'''
    parser = optparse.OptionParser()
    parser.add_option('-D', '-b', '--bind', '--binddn', action='store',
                      dest='binddn', help='LDAP bind DN')
    parser.add_option('-s', '--shell', action='store', dest='shell',
                      help='new login shell for the user account')
    parser.add_option('-d', '--default', action='store_true', dest='default',
                      default=False, help='Set the default shell')

    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    return parser.parse_args()
Example #21
0
def parseArgs():
    """ Parse the command line args """
    # prevent optparse from totally munging usage
    formatter = optparse.IndentedHelpFormatter()
    formatter.format_usage = lambda usage: usage

    # Initialize this here, so we can probe it for xml rpc client commands in the usage
    initXMLRPCClient()
    from Hellanzb.HellaXMLRPC import RemoteCall
    usage = USAGE % (str(Hellanzb.version), '%prog', RemoteCall.allUsage())
    
    parser = optparse.OptionParser(formatter = formatter, usage = usage, version = Hellanzb.version)
    parser.add_option('-c', '--config', type='string', dest='configFile',
                      help='specify the configuration file')
    parser.add_option('-l', '--log-file', type='string', dest='logFile',
                      help='specify the log file (overwrites the Hellanzb.LOG_FILE config file setting)')
    parser.add_option('-d', '--debug-file', type='string', dest='debugLogFile',
                      help='specify the debug log file (turns on debugging output/overwrites the ' + \
                      'Hellanzb.DEBUG_MODE config file setting)')
    if not isWindows():
        parser.add_option('-D', '--daemon', action='store_true', dest='daemonize',
                          help='run hellanzb as a daemon process (fork and exit)')
    #parser.add_option('-n', '--just-download-nzb', type='string', dest='justDownload',
    #                  help='download the specified nzb and exit the program (do not post process)')
    parser.add_option('-p', '--post-process-dir', type='string', dest='postProcessDir',
                      help='post-process the specified nzb archive dir either in an already running hellanzb' + \
                      ' (via xmlrpc) if one is available, otherwise in the current process. then exit')
    parser.add_option('-P', '--rar-password', type='string', dest='rarPassword',
                      help='when used with the -p option, specifies the nzb archive\'s rar password')
    parser.add_option('-L', '--local-post-process', action='store_true', dest='localPostProcess',
                      help='when used with the -p option, do the post processing work in the current ' + \
                      'process (do not attempt to contact an already running queue daemon)')
    parser.add_option('-r', '--rpc-server', type='string', dest='rpcServer',
                      help='specify the rpc server hostname (overwrites Hellanzb.XMLRPC_SERVER config file setting)')
    parser.add_option('-s', '--rpc-password', type='string', dest='rpcPassword',
                      help='specify the rpc server password (overwrites Hellanzb.XMLRPC_PASSWORD config file setting)')
    parser.add_option('-t', '--rpc-port', type='int', dest='rpcPort',
                      help='specify the rpc server port (overwrites Hellanzb.XMLRPC_PORT config file setting)')
    if optcomplete:
        optcomplete.autocomplete(parser)
    return parser.parse_args()
Example #22
0
def main(argv):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Verbose output')
    parser.add_argument('-d',
                        '--debug-libs',
                        action='store_true',
                        help='When calling create_nmf request debug libaries')
    parser.add_argument('-o',
                        '--output',
                        dest='output',
                        help='Name of html file to write (default is '
                        'input name with .html extension)',
                        metavar='FILE')
    parser.add_argument(
        'exe',
        metavar='EXE_OR_NMF',
        nargs='+',
        help='Executable (.nexe/.pexe) or nmf file to generate '
        'html for.')
    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete create_html.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(argv)

    if options.verbose:
        Log.enabled = True

    CreateHTML(options.exe, options)
    return 0
Example #23
0
def main(argv):
  usage = 'Usage: %prog [options] <.nexe>'
  epilog = 'Example: sel_ldr.py my_nexe.nexe'
  parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
  parser.add_option('-v', '--verbose', action='store_true',
                    help='Verbose output')
  parser.add_option('-d', '--debug', action='store_true',
                    help='Enable debug stub')
  parser.add_option('--debug-libs', action='store_true',
                    help='For dynamic executables, reference debug '
                         'libraries rather then release')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete sel_ldr.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)
  if not args:
    parser.error('No executable file specified')

  nexe = args[0]
  if options.verbose:
    Log.verbose = True

  osname = getos.GetPlatform()
  if not os.path.exists(nexe):
    raise Error('executable not found: %s' % nexe)
  if not os.path.isfile(nexe):
    raise Error('not a file: %s' % nexe)

  arch, dynamic = create_nmf.ParseElfHeader(nexe)

  if arch == 'arm':
    raise Error('Cannot run ARM executables under sel_ldr')

  arch_suffix = arch.replace('-', '_')

  sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix)
  irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix)
  if osname == 'win':
    sel_ldr += '.exe'
  Log('ROOT    = %s' % NACL_SDK_ROOT)
  Log('SEL_LDR = %s' % sel_ldr)
  Log('IRT     = %s' % irt)
  cmd = [sel_ldr, '-a', '-B', irt, '-l', os.devnull]

  if options.debug:
    cmd.append('-g')

  if osname == 'linux':
    helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix)
    Log('HELPER  = %s' % helper)
    cmd.insert(0, helper)

  if dynamic:
    if options.debug_libs:
      libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                            'glibc_%s' % arch_suffix, 'Debug')
    else:
      libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                            'glibc_%s' % arch_suffix, 'Release')
    toolchain = '%s_x86_glibc' % osname
    sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain',
                               toolchain, 'x86_64-nacl')
    if arch == 'x86-64':
      sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib')
    else:
      sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32')
    ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so')
    cmd.append(ldso)
    Log('LD.SO   = %s' % ldso)
    libpath += ':' + sdk_lib_dir
    cmd.append('--library-path')
    cmd.append(libpath)


  cmd += args
  Log(cmd)
  rtn = subprocess.call(cmd)
  return rtn
Example #24
0
def main(args):
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('--experimental', help='build experimental tests',
                      action='store_true')
  parser.add_argument('--sanitizer',
                      help='Run sanitizer (asan/tsan/valgrind) tests',
                      action='store_true')
  parser.add_argument('--verbose', '-v', help='Verbose output',
                      action='store_true')
  parser.add_argument('phases', nargs="*")

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete test_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(args)

  pepper_ver = str(int(build_version.ChromeMajorVersion()))
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  toolchains = ['clang-newlib', 'newlib', 'glibc', 'pnacl']
  toolchains.append(getos.GetPlatform())

  if options.verbose:
    build_projects.verbose = True

  phases = [
    ('build_examples', StepBuildExamples, pepperdir),
    ('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental),
    ('build_tests', StepBuildTests, pepperdir),
    ('sel_ldr_tests', StepRunSelLdrTests, pepperdir, None),
    ('browser_tests', StepRunBrowserTests, toolchains, options.experimental),
  ]

  if options.sanitizer:
    if getos.GetPlatform() != 'linux':
      buildbot_common.ErrorExit('sanitizer tests only run on linux.')
    phases += [
      ('sel_ldr_tests_asan', StepRunSelLdrTests, pepperdir, 'address'),
      ('sel_ldr_tests_tsan', StepRunSelLdrTests, pepperdir, 'thread'),
      ('sel_ldr_tests_valgrind', StepRunSelLdrTests, pepperdir, 'valgrind')
    ]

  if options.phases:
    phase_names = [p[0] for p in phases]
    for arg in options.phases:
      if arg not in phase_names:
        msg = 'Invalid argument: %s\n' % arg
        msg += 'Possible arguments:\n'
        for name in phase_names:
          msg += '   %s\n' % name
        parser.error(msg.strip())

  for phase in phases:
    phase_name = phase[0]
    if options.phases and phase_name not in options.phases:
      continue
    phase_func = phase[1]
    phase_args = phase[2:]
    phase_func(*phase_args)

  return 0
Example #25
0
def main(args):
    usage = "%prog [<options>] [<phase...>]"
    parser = optparse.OptionParser(description=__doc__, usage=usage)
    parser.add_option("--experimental", help="build experimental tests", action="store_true")
    parser.add_option("--sanitizer", help="Run sanitizer (asan/tsan/valgrind) tests", action="store_true")
    parser.add_option("--verbose", "-v", help="Verbose output", action="store_true")

    if "NACL_SDK_ROOT" in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # of the build.
        del os.environ["NACL_SDK_ROOT"]

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete test_sdk.py
    try:
        import optcomplete

        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(args[1:])

    pepper_ver = str(int(build_version.ChromeMajorVersion()))
    pepperdir = os.path.join(OUT_DIR, "pepper_" + pepper_ver)
    toolchains = ["newlib", "glibc", "pnacl"]
    toolchains.append(getos.GetPlatform())

    if options.verbose:
        build_projects.verbose = True

    phases = [
        ("build_examples", StepBuildExamples, pepperdir),
        ("copy_tests", StepCopyTests, pepperdir, toolchains, options.experimental),
        ("build_tests", StepBuildTests, pepperdir),
        ("sel_ldr_tests", StepRunSelLdrTests, pepperdir, None),
        ("browser_tests", StepRunBrowserTests, toolchains, options.experimental),
    ]

    if options.sanitizer:
        if getos.GetPlatform() != "linux":
            buildbot_common.ErrorExit("sanitizer tests only run on linux.")
        phases += [
            ("sel_ldr_tests_asan", StepRunSelLdrTests, pepperdir, "address"),
            ("sel_ldr_tests_tsan", StepRunSelLdrTests, pepperdir, "thread"),
            ("sel_ldr_tests_valgrind", StepRunSelLdrTests, pepperdir, "valgrind"),
        ]

    if args:
        phase_names = [p[0] for p in phases]
        for arg in args:
            if arg not in phase_names:
                msg = "Invalid argument: %s\n" % arg
                msg += "Possible arguments:\n"
                for name in phase_names:
                    msg += "   %s\n" % name
                parser.error(msg.strip())

    for phase in phases:
        phase_name = phase[0]
        if args and phase_name not in args:
            continue
        phase_func = phase[1]
        phase_args = phase[2:]
        phase_func(*phase_args)

    return 0
Example #26
0
def main():
    """
    Main command-line execution loop.
    """
    try:
        # Parse command line options
        parser, options, arguments = parse_options()

        # Handle regular args vs -- args
        arguments = parser.largs
        remainder_arguments = parser.rargs

        # Update env with any overridden option values
        # NOTE: This needs to remain the first thing that occurs
        # post-parsing, since so many things hinge on the values in env.
        for option in env_options:
            env[option.dest] = getattr(options, option.dest)

        # Handle --hosts, --roles (comma separated string => list)
        for key in ['hosts', 'roles']:
            if key in env and isinstance(env[key], str):
                env[key] = env[key].split(',')

        # Handle output control level show/hide
        update_output_levels(show=options.show, hide=options.hide)

        # Handle version number option
        if options.show_version:
            print("Fabric %s" % env.version)
            sys.exit(0)

        # Load settings from user settings file, into shared env dict.
        env.update(load_settings(env.rcfile))

        # Find local fabfile path or abort
        fabfile = find_fabfile()
        if not fabfile and not remainder_arguments:
            abort("Couldn't find any fabfiles!")

        # Store absolute path to fabfile in case anyone needs it
        env.real_fabfile = fabfile

        # Load fabfile (which calls its module-level code, including
        # tweaks to env values) and put its commands in the shared commands
        # dict
        if fabfile:
            docstring, callables = load_fabfile(fabfile)
            commands.update(callables)

        # Autocompletion support
        autocomplete_items = [cmd.replace('_', '-') for cmd in commands]
        if 'autocomplete' in env:
            autocomplete_items += env.autocomplete

        autocomplete(parser, ListCompleter(autocomplete_items))

        # Handle hooks related options
        _disable_hooks = options.disable_hooks
        _enable_hooks = options.enable_hooks

        if _disable_hooks:
            for _hook in _disable_hooks.strip().split():
                DISABLED_HOOKS.append(_hook.strip())

        if _enable_hooks:
            for _hook in _enable_hooks.strip().split():
                ENABLED_HOOKS.append(_hook.strip())

        # Handle the non-execution flow
        if not arguments and not remainder_arguments:

            # Non-verbose command list
            if options.shortlist:
                shortlist()

            # Handle show (command-specific help) option
            if options.display:
                display_command(options.display)

            # Else, show the list of commands and exit
            list_commands(docstring)

        # Now that we're settled on a fabfile, inform user.
        if output.debug:
            if fabfile:
                print("Using fabfile '%s'" % fabfile)
            else:
                print("No fabfile loaded -- remainder command only")

        # Parse arguments into commands to run (plus args/kwargs/hosts)
        commands_to_run, env_update = parse_arguments(arguments)
        env.update(env_update)

        # Parse remainders into a faux "command" to execute
        remainder_command = parse_remainder(remainder_arguments)

        # Figure out if any specified task names are invalid
        unknown_commands = []
        for tup in commands_to_run:
            if tup[0] not in commands:
                unknown_commands.append(tup[0])

        # Abort if any unknown commands were specified
        if unknown_commands:
            abort("Command(s) not found:\n%s" \
                % indent(unknown_commands))

        # Generate remainder command and insert into commands, commands_to_run
        if remainder_command:
            r = '<remainder>'
            commands[r] = lambda: api.run(remainder_command)
            commands_to_run.append((r, [], {}, [], []))

        if output.debug:
            names = ", ".join(x[0] for x in commands_to_run)
            print("Commands to run: %s" % names)

        call_hooks('commands.before', commands, commands_to_run)

        # Initialse context runner
        env()

        # Initialise the default stage if none are given as the first command.
        if 'stages' in env:
            if commands_to_run[0][0] not in env.stages:
                execute_command(
                    (env.stages[0], (), {}, None, None, None), commands
                    )
            else:
                execute_command(commands_to_run.pop(0), commands)

        if env.config_file:
            config_path = realpath(expanduser(env.config_file))
            config_path = join(dirname(fabfile), config_path)
            config_file = open(config_path, 'rb')
            config = load_yaml(config_file.read())
            if not config:
                env.config = AttributeDict()
            elif not isinstance(config, dict):
                abort("Invalid config file found at %s" % config_path)
            else:
                env.config = AttributeDict(config)
            config_file.close()

        call_hooks('config.loaded')
        first_time_env_call = 1

        # At this point all commands must exist, so execute them in order.
        for spec in commands_to_run:
            execute_command(spec, commands)

        # If we got here, no errors occurred, so print a final note.
        if output.status:
            msg = "\nDone."
            if env.colors:
                msg = env.color_settings['finish'](msg)
            print(msg)

    except SystemExit:
        # a number of internal functions might raise this one.
        raise
    except KeyboardInterrupt:
        if output.status:
            msg = "\nStopped."
            if env.colors:
                msg = env.color_settings['finish'](msg)
            print >> sys.stderr, msg
        sys.exit(1)
    except:
        sys.excepthook(*sys.exc_info())
        # we might leave stale threads if we don't explicitly exit()
        sys.exit(1)
    finally:
        call_hooks('commands.after')
        disconnect_all()
    sys.exit(0)
Example #27
0
        'finetune_onlylast',
        'epochs where only not-pretrained upper layer is updated [%default]',
        0,
        converter=int),
    Option('finetune_online_learning',
           'online learning [%default]',
           '0',
           converter=int),
]

cfg = Config(options, usage="usage: %prog [options]")

try:
    sys.path.insert(0, os.path.join(os.getenv('HOME'), 'bin'))
    import optcomplete
    optcomplete.autocomplete(cfg._parser)
except ImportError:
    pass

cfg.grab_from_argv(sys.argv)  # to fetch the config file name
try:
    os.mkdir(cfg.workdir)
except:
    pass
cfg.config_file = os.path.join(cfg.workdir, "pyrbm.ini")

print "Loading configuration from ", cfg.config_file

if os.path.exists(cfg.config_file):
    cfg.grab_from_file(cfg.config_file)
cfg.grab_from_argv(sys.argv)  # overwrite using cmdline
Example #28
0
def parseArgs():
    """ Parse the command line args """
    # prevent optparse from totally munging usage
    formatter = optparse.IndentedHelpFormatter()
    formatter.format_usage = lambda usage: usage

    # Initialize this here, so we can probe it for xml rpc client commands in the usage
    initXMLRPCClient()
    from Hellanzb.HellaXMLRPC import RemoteCall
    usage = USAGE % (str(Hellanzb.version), '%prog', RemoteCall.allUsage())

    parser = optparse.OptionParser(formatter=formatter,
                                   usage=usage,
                                   version=Hellanzb.version)
    parser.add_option('-c',
                      '--config',
                      type='string',
                      dest='configFile',
                      help='specify the configuration file')
    parser.add_option(
        '-l',
        '--log-file',
        type='string',
        dest='logFile',
        help=
        'specify the log file (overwrites the Hellanzb.LOG_FILE config file setting)'
    )
    parser.add_option('-d', '--debug-file', type='string', dest='debugLogFile',
                      help='specify the debug log file (turns on debugging output/overwrites the ' + \
                      'Hellanzb.DEBUG_MODE config file setting)')
    if not isWindows():
        parser.add_option(
            '-D',
            '--daemon',
            action='store_true',
            dest='daemonize',
            help='run hellanzb as a daemon process (fork and exit)')
    #parser.add_option('-n', '--just-download-nzb', type='string', dest='justDownload',
    #                  help='download the specified nzb and exit the program (do not post process)')
    parser.add_option('-p', '--post-process-dir', type='string', dest='postProcessDir',
                      help='post-process the specified nzb archive dir either in an already running hellanzb' + \
                      ' (via xmlrpc) if one is available, otherwise in the current process. then exit')
    parser.add_option(
        '-P',
        '--rar-password',
        type='string',
        dest='rarPassword',
        help=
        'when used with the -p option, specifies the nzb archive\'s rar password'
    )
    parser.add_option('-L', '--local-post-process', action='store_true', dest='localPostProcess',
                      help='when used with the -p option, do the post processing work in the current ' + \
                      'process (do not attempt to contact an already running queue daemon)')
    parser.add_option(
        '-r',
        '--rpc-server',
        type='string',
        dest='rpcServer',
        help=
        'specify the rpc server hostname (overwrites Hellanzb.XMLRPC_SERVER config file setting)'
    )
    parser.add_option(
        '-s',
        '--rpc-password',
        type='string',
        dest='rpcPassword',
        help=
        'specify the rpc server password (overwrites Hellanzb.XMLRPC_PASSWORD config file setting)'
    )
    parser.add_option(
        '-t',
        '--rpc-port',
        type='int',
        dest='rpcPort',
        help=
        'specify the rpc server port (overwrites Hellanzb.XMLRPC_PORT config file setting)'
    )
    if optcomplete:
        optcomplete.autocomplete(parser)
    return parser.parse_args()
Example #29
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option(
        '-c',
        '--clobber',
        help='Clobber project directories before copying new files',
        action='store_true',
        default=False)
    parser.add_option('-b',
                      '--build',
                      help='Build the projects.',
                      action='store_true')
    parser.add_option(
        '--config',
        help='Choose configuration to build (Debug or Release).  Builds both '
        'by default')
    parser.add_option('-x',
                      '--experimental',
                      help='Build experimental projects',
                      action='store_true')
    parser.add_option(
        '-t',
        '--toolchain',
        help='Build using toolchain. Can be passed more than once.',
        action='append',
        default=[])
    parser.add_option(
        '-d',
        '--dest',
        help='Select which build destinations (project types) are valid.',
        action='append')
    parser.add_option('-v', '--verbose', action='store_true')

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete build_projects.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(argv[1:])

    if 'NACL_SDK_ROOT' in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # on the build.
        del os.environ['NACL_SDK_ROOT']

    pepper_ver = str(int(build_version.ChromeMajorVersion()))
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)

    if not options.toolchain:
        # Order matters here: the default toolchain for an example's Makefile will
        # be the first toolchain in this list that is available in the example.
        # e.g. If an example supports newlib and glibc, then the default will be
        # newlib.
        options.toolchain = ['pnacl', 'newlib', 'glibc', 'host']
        if options.experimental:
            options.toolchain.append('bionic')

    if 'host' in options.toolchain:
        options.toolchain.remove('host')
        options.toolchain.append(getos.GetPlatform())
        print 'Adding platform: ' + getos.GetPlatform()

    ValidateToolchains(options.toolchain)

    filters = {}
    if options.toolchain:
        filters['TOOLS'] = options.toolchain
        print 'Filter by toolchain: ' + str(options.toolchain)
    if not options.experimental:
        filters['EXPERIMENTAL'] = False
    if options.dest:
        filters['DEST'] = options.dest
        print 'Filter by type: ' + str(options.dest)
    if args:
        filters['NAME'] = args
        print 'Filter by name: ' + str(args)

    try:
        project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
    except parse_dsc.ValidationError as e:
        buildbot_common.ErrorExit(str(e))
    parse_dsc.PrintProjectTree(project_tree)

    UpdateHelpers(pepperdir, clobber=options.clobber)
    UpdateProjects(pepperdir,
                   project_tree,
                   options.toolchain,
                   clobber=options.clobber)

    if options.verbose:
        global verbose
        verbose = True

    if options.build:
        if options.config:
            configs = [options.config]
        else:
            configs = ['Debug', 'Release']
        for config in configs:
            BuildProjects(pepperdir, project_tree, config=config)

    return 0
Example #30
0
def main():
    """
    Main command-line execution loop.
    """
    try:
        # Parse command line options
        parser, options, arguments = parse_options()

        # Handle regular args vs -- args
        arguments = parser.largs
        remainder_arguments = parser.rargs

        # Update env with any overridden option values
        # NOTE: This needs to remain the first thing that occurs
        # post-parsing, since so many things hinge on the values in env.
        for option in env_options:
            env[option.dest] = getattr(options, option.dest)

        # Handle --hosts, --roles (comma separated string => list)
        for key in ['hosts', 'roles']:
            if key in env and isinstance(env[key], str):
                env[key] = env[key].split(',')

        # Handle output control level show/hide
        update_output_levels(show=options.show, hide=options.hide)

        # Handle version number option
        if options.show_version:
            print("Fabric %s" % env.version)
            sys.exit(0)

        # Load settings from user settings file, into shared env dict.
        env.update(load_settings(env.rcfile))

        # Find local fabfile path or abort
        fabfile = find_fabfile()
        if not fabfile and not remainder_arguments:
            abort("Couldn't find any fabfiles!")

        # Store absolute path to fabfile in case anyone needs it
        env.real_fabfile = fabfile

        # Load fabfile (which calls its module-level code, including
        # tweaks to env values) and put its commands in the shared commands
        # dict
        if fabfile:
            docstring, callables = load_fabfile(fabfile)
            commands.update(callables)

        # Autocompletion support
        autocomplete_items = [cmd.replace('_', '-') for cmd in commands]
        if 'autocomplete' in env:
            autocomplete_items += env.autocomplete

        autocomplete(parser, ListCompleter(autocomplete_items))

        # Handle hooks related options
        _disable_hooks = options.disable_hooks
        _enable_hooks = options.enable_hooks

        if _disable_hooks:
            for _hook in _disable_hooks.strip().split():
                DISABLED_HOOKS.append(_hook.strip())

        if _enable_hooks:
            for _hook in _enable_hooks.strip().split():
                ENABLED_HOOKS.append(_hook.strip())

        # Handle the non-execution flow
        if not arguments and not remainder_arguments:

            # Non-verbose command list
            if options.shortlist:
                shortlist()

            # Handle show (command-specific help) option
            if options.display:
                display_command(options.display)

            # Else, show the list of commands and exit
            list_commands(docstring)

        # Now that we're settled on a fabfile, inform user.
        if output.debug:
            if fabfile:
                print("Using fabfile '%s'" % fabfile)
            else:
                print("No fabfile loaded -- remainder command only")

        # Parse arguments into commands to run (plus args/kwargs/hosts)
        commands_to_run, env_update = parse_arguments(arguments)
        env.update(env_update)

        # Parse remainders into a faux "command" to execute
        remainder_command = parse_remainder(remainder_arguments)

        # Figure out if any specified task names are invalid
        unknown_commands = []
        for tup in commands_to_run:
            if tup[0] not in commands:
                unknown_commands.append(tup[0])

        # Abort if any unknown commands were specified
        if unknown_commands:
            abort("Command(s) not found:\n%s" \
                % indent(unknown_commands))

        # Generate remainder command and insert into commands, commands_to_run
        if remainder_command:
            r = '<remainder>'
            commands[r] = lambda: api.run(remainder_command)
            commands_to_run.append((r, [], {}, [], []))

        if output.debug:
            names = ", ".join(x[0] for x in commands_to_run)
            print("Commands to run: %s" % names)

        call_hooks('commands.before', commands, commands_to_run)

        # Initialse context runner
        env()

        # Initialise the default stage if none are given as the first command.
        if 'stages' in env:
            if commands_to_run[0][0] not in env.stages:
                execute_command(
                    (env.stages[0], (), {}, None, None, None), commands
                    )
            else:
                execute_command(commands_to_run.pop(0), commands)

        if env.config_file:
            config_path = realpath(expanduser(env.config_file))
            config_path = join(dirname(fabfile), config_path)
            config_file = open(config_path, 'rb')
            config = load_yaml(config_file.read())
            if not config:
                env.config = AttributeDict()
            elif not isinstance(config, dict):
                abort("Invalid config file found at %s" % config_path)
            else:
                env.config = AttributeDict(config)
            config_file.close()

        call_hooks('config.loaded')
        first_time_env_call = 1

        # At this point all commands must exist, so execute them in order.
        for spec in commands_to_run:
            execute_command(spec, commands)

        # If we got here, no errors occurred, so print a final note.
        if output.status:
            msg = "\nDone."
            if env.colors:
                msg = env.color_settings['finish'](msg)
            print(msg)

    except SystemExit:
        # a number of internal functions might raise this one.
        raise
    except KeyboardInterrupt:
        if output.status:
            msg = "\nStopped."
            if env.colors:
                msg = env.color_settings['finish'](msg)
            print >> sys.stderr, msg
        sys.exit(1)
    except:
        sys.excepthook(*sys.exc_info())
        # we might leave stale threads if we don't explicitly exit()
        sys.exit(1)
    finally:
        call_hooks('commands.after')
        disconnect_all()
    sys.exit(0)
Example #31
0
def main(args):
    usage = '%prog [<options>] [<phase...>]'
    parser = optparse.OptionParser(description=__doc__, usage=usage)
    parser.add_option('--experimental',
                      help='build experimental tests',
                      action='store_true')
    parser.add_option('--verbose',
                      '-v',
                      help='Verbose output',
                      action='store_true')

    if 'NACL_SDK_ROOT' in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # of the build.
        del os.environ['NACL_SDK_ROOT']

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete test_sdk.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(args[1:])

    pepper_ver = str(int(build_version.ChromeMajorVersion()))
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
    toolchains = ['newlib', 'glibc', 'pnacl']
    toolchains.append(getos.GetPlatform())

    if options.verbose:
        build_projects.verbose = True

    phases = [
        ('build_examples', StepBuildExamples, pepperdir),
        ('copy_tests', StepCopyTests, pepperdir, toolchains,
         options.experimental),
        ('build_tests', StepBuildTests, pepperdir),
        ('sel_ldr_tests', StepRunSelLdrTests, pepperdir),
        ('browser_tests', StepRunBrowserTests, toolchains,
         options.experimental),
    ]

    if args:
        phase_names = [p[0] for p in phases]
        for arg in args:
            if arg not in phase_names:
                msg = 'Invalid argument: %s\n' % arg
                msg += 'Possible arguments:\n'
                for name in phase_names:
                    msg += '   %s\n' % name
                parser.error(msg.strip())

    for phase in phases:
        phase_name = phase[0]
        if args and phase_name not in args:
            continue
        phase_func = phase[1]
        phase_args = phase[2:]
        phase_func(*phase_args)

    return 0
Example #32
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--channel',
                        help='Channel to display in the name of the package.')

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete build_app.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(args)

    if options.channel:
        if options.channel not in ('Dev', 'Beta'):
            parser.error('Unknown channel: %s' % options.channel)

    toolchains = ['newlib', 'glibc']

    pepper_ver = str(int(build_version.ChromeMajorVersion()))
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
    app_dir = os.path.join(OUT_DIR, 'naclsdk_app')
    app_examples_dir = os.path.join(app_dir, 'examples')
    sdk_resources_dir = SDK_RESOURCE_DIR
    platform = getos.GetPlatform()

    buildbot_common.RemoveDir(app_dir)
    buildbot_common.MakeDir(app_dir)

    # Add some dummy directories so build_projects doesn't complain...
    buildbot_common.MakeDir(os.path.join(app_dir, 'tools'))
    buildbot_common.MakeDir(os.path.join(app_dir, 'toolchain'))

    config = 'Release'

    filters = {}
    filters['DISABLE_PACKAGE'] = False
    filters['EXPERIMENTAL'] = False
    filters['TOOLS'] = toolchains
    filters['DEST'] = [
        'examples/api', 'examples/getting_started', 'examples/demo',
        'examples/tutorial'
    ]
    tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
    build_projects.UpdateHelpers(app_dir, clobber=True)
    build_projects.UpdateProjects(app_dir,
                                  tree,
                                  clobber=False,
                                  toolchains=toolchains,
                                  configs=[config],
                                  first_toolchain=True)

    # Collect permissions from each example, and aggregate them.
    def MergeLists(list1, list2):
        return list1 + [x for x in list2 if x not in list1]

    all_permissions = []
    all_socket_permissions = []
    all_filesystem_permissions = []
    for _, project in parse_dsc.GenerateProjects(tree):
        permissions = project.get('PERMISSIONS', [])
        all_permissions = MergeLists(all_permissions, permissions)
        socket_permissions = project.get('SOCKET_PERMISSIONS', [])
        all_socket_permissions = MergeLists(all_socket_permissions,
                                            socket_permissions)
        filesystem_permissions = project.get('FILESYSTEM_PERMISSIONS', [])
        all_filesystem_permissions = MergeLists(all_filesystem_permissions,
                                                filesystem_permissions)
    if all_socket_permissions:
        all_permissions.append({'socket': all_socket_permissions})
    if all_filesystem_permissions:
        all_permissions.append({'fileSystem': all_filesystem_permissions})
    pretty_permissions = json.dumps(all_permissions, sort_keys=True, indent=4)

    for filename in ['background.js', 'icon128.png']:
        buildbot_common.CopyFile(os.path.join(sdk_resources_dir, filename),
                                 os.path.join(app_examples_dir, filename))

    os.environ['NACL_SDK_ROOT'] = pepperdir

    build_projects.BuildProjects(app_dir,
                                 tree,
                                 deps=False,
                                 clean=False,
                                 config=config)

    RemoveBuildCruft(app_dir)
    StripNexes(app_dir, platform, pepperdir)

    # Add manifest.json after RemoveBuildCruft... that function removes the
    # manifest.json files for the individual examples.
    name = 'Native Client SDK'
    if options.channel:
        name += ' (%s)' % options.channel
    template_dict = {
        'name': name,
        'channel': options.channel,
        'description':
        'Native Client SDK examples, showing API use and key concepts.',
        'key':
        False,  # manifests with "key" are rejected when uploading to CWS.
        'permissions': pretty_permissions,
        'version': build_version.ChromeVersionNoTrunk()
    }
    easy_template.RunTemplateFile(
        os.path.join(sdk_resources_dir, 'manifest.json.template'),
        os.path.join(app_examples_dir, 'manifest.json'), template_dict)

    app_zip = os.path.join(app_dir, 'examples.zip')
    os.chdir(app_examples_dir)
    oshelpers.Zip([app_zip, '-r', '*'])

    return 0
Example #33
0
def main(argv):
  parser = optparse.OptionParser(
      usage='Usage: %prog [options] nexe [extra_libs...]', description=__doc__)
  parser.add_option('-o', '--output', dest='output',
                    help='Write manifest file to FILE (default is stdout)',
                    metavar='FILE')
  parser.add_option('-D', '--objdump', dest='objdump',
                    help='Override the default "objdump" tool used to find '
                         'shared object dependencies',
                    metavar='TOOL')
  parser.add_option('--no-default-libpath', action='store_true',
                    help="Don't include the SDK default library paths")
  parser.add_option('--debug-libs', action='store_true',
                    help='Use debug library paths when constructing default '
                         'library path.')
  parser.add_option('-L', '--library-path', dest='lib_path',
                    action='append', default=[],
                    help='Add DIRECTORY to library search path',
                    metavar='DIRECTORY')
  parser.add_option('-P', '--path-prefix', dest='path_prefix', default='',
                    help='A path to prepend to shared libraries in the .nmf',
                    metavar='DIRECTORY')
  parser.add_option('-s', '--stage-dependencies', dest='stage_dependencies',
                    help='Destination directory for staging libraries',
                    metavar='DIRECTORY')
  parser.add_option('-t', '--toolchain', help='Legacy option, do not use')
  parser.add_option('-n', '--name', dest='name',
                    help='Rename FOO as BAR',
                    action='append', default=[], metavar='FOO,BAR')
  parser.add_option('-x', '--extra-files',
                    help=('Add extra key:file tuple to the "files"' +
                          ' section of the .nmf'),
                    action='append', default=[], metavar='FILE')
  parser.add_option('-O', '--pnacl-optlevel',
                    help='Set the optimization level to N in PNaCl manifests',
                    metavar='N')
  parser.add_option('-v', '--verbose',
                    help='Verbose output', action='store_true')
  parser.add_option('-d', '--debug-mode',
                    help='Debug mode', action='store_true')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete create_nmf.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)
  if options.verbose:
    Trace.verbose = True
  if options.debug_mode:
    DebugPrint.debug_mode = True

  if options.toolchain is not None:
    sys.stderr.write('warning: option -t/--toolchain is deprecated.\n')

  if len(args) < 1:
    parser.error('No nexe files specified.  See --help for more info')

  canonicalized = ParseExtraFiles(options.extra_files, sys.stderr)
  if canonicalized is None:
    parser.error('Bad --extra-files (-x) argument syntax')

  remap = {}
  for ren in options.name:
    parts = ren.split(',')
    if len(parts) != 2:
      parser.error('Expecting --name=<orig_arch.so>,<new_name.so>')
    remap[parts[0]] = parts[1]

  if options.path_prefix:
    path_prefix = options.path_prefix.split('/')
  else:
    path_prefix = []

  for libpath in options.lib_path:
    if not os.path.exists(libpath):
      sys.stderr.write('Specified library path does not exist: %s\n' % libpath)
    elif not os.path.isdir(libpath):
      sys.stderr.write('Specified library is not a directory: %s\n' % libpath)

  if not options.no_default_libpath:
    # Add default libraries paths to the end of the search path.
    config = options.debug_libs and 'Debug' or 'Release'
    options.lib_path += GetDefaultLibPath(config)

  pnacl_optlevel = None
  if options.pnacl_optlevel is not None:
    pnacl_optlevel = int(options.pnacl_optlevel)
    if pnacl_optlevel < 0 or pnacl_optlevel > 3:
      sys.stderr.write(
          'warning: PNaCl optlevel %d is unsupported (< 0 or > 3)\n' %
          pnacl_optlevel)

  nmf = NmfUtils(objdump=options.objdump,
                 main_files=args,
                 lib_path=options.lib_path,
                 extra_files=canonicalized,
                 lib_prefix=path_prefix,
                 remap=remap,
                 pnacl_optlevel=pnacl_optlevel)

  nmf.GetManifest()
  if not options.output:
    sys.stdout.write(nmf.GetJson())
  else:
    with open(options.output, 'w') as output:
      output.write(nmf.GetJson())

  if options.stage_dependencies and not nmf.pnacl:
    Trace('Staging dependencies...')
    nmf.StageDependencies(options.stage_dependencies)

  return 0
Example #34
0
def main(argv):
  parser = optparse.OptionParser()
  parser.add_option('-c', '--clobber',
      help='Clobber project directories before copying new files',
      action='store_true', default=False)
  parser.add_option('-b', '--build',
      help='Build the projects. Otherwise the projects are only copied.',
      action='store_true')
  parser.add_option('--config',
      help='Choose configuration to build (Debug or Release).  Builds both '
           'by default')
  parser.add_option('--bionic',
      help='Enable bionic projects', action='store_true')
  parser.add_option('-x', '--experimental',
      help='Build experimental projects', action='store_true')
  parser.add_option('-t', '--toolchain',
      help='Build using toolchain. Can be passed more than once.',
      action='append', default=[])
  parser.add_option('-d', '--dest',
      help='Select which build destinations (project types) are valid.',
      action='append')
  parser.add_option('-v', '--verbose', action='store_true')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_projects.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(argv)

  global verbose
  if options.verbose:
    verbose = True

  buildbot_common.verbose = verbose

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # on the build.
    del os.environ['NACL_SDK_ROOT']

  pepper_ver = str(int(build_version.ChromeMajorVersion()))
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)

  if not options.toolchain:
    # Order matters here: the default toolchain for an example's Makefile will
    # be the first toolchain in this list that is available in the example.
    # e.g. If an example supports newlib and glibc, then the default will be
    # newlib.
    options.toolchain = ['pnacl', 'newlib', 'glibc', 'host']
    if options.experimental or options.bionic:
      options.toolchain.append('bionic')

  if 'host' in options.toolchain:
    options.toolchain.remove('host')
    options.toolchain.append(getos.GetPlatform())
    Trace('Adding platform: ' + getos.GetPlatform())

  ValidateToolchains(options.toolchain)

  filters = {}
  if options.toolchain:
    filters['TOOLS'] = options.toolchain
    Trace('Filter by toolchain: ' + str(options.toolchain))
  if not options.experimental:
    filters['EXPERIMENTAL'] = False
  if options.dest:
    filters['DEST'] = options.dest
    Trace('Filter by type: ' + str(options.dest))
  if args:
    filters['NAME'] = args
    Trace('Filter by name: ' + str(args))

  try:
    project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
  except parse_dsc.ValidationError as e:
    buildbot_common.ErrorExit(str(e))

  if verbose:
    parse_dsc.PrintProjectTree(project_tree)

  UpdateHelpers(pepperdir, clobber=options.clobber)
  UpdateProjects(pepperdir, project_tree, options.toolchain,
                 clobber=options.clobber)

  if options.build:
    if options.config:
      configs = [options.config]
    else:
      configs = ['Debug', 'Release']
    for config in configs:
      BuildProjects(pepperdir, project_tree, config=config, deps=False)

  return 0
Example #35
0
def main(argv):
    parser = optparse.OptionParser(
        usage='Usage: %prog [options] nexe [extra_libs...]',
        description=__doc__)
    parser.add_option('-o',
                      '--output',
                      dest='output',
                      help='Write manifest file to FILE (default is stdout)',
                      metavar='FILE')
    parser.add_option('-D',
                      '--objdump',
                      dest='objdump',
                      help='Override the default "objdump" tool used to find '
                      'shared object dependencies',
                      metavar='TOOL')
    parser.add_option('--no-default-libpath',
                      action='store_true',
                      help="Don't include the SDK default library paths")
    parser.add_option('--debug-libs',
                      action='store_true',
                      help='Use debug library paths when constructing default '
                      'library path.')
    parser.add_option('-L',
                      '--library-path',
                      dest='lib_path',
                      action='append',
                      default=[],
                      help='Add DIRECTORY to library search path',
                      metavar='DIRECTORY')
    parser.add_option('-P',
                      '--path-prefix',
                      dest='path_prefix',
                      default='',
                      help='Deprecated. An alias for --lib-prefix.',
                      metavar='DIRECTORY')
    parser.add_option('-p',
                      '--lib-prefix',
                      dest='lib_prefix',
                      default='',
                      help='A path to prepend to shared libraries in the .nmf',
                      metavar='DIRECTORY')
    parser.add_option('-N',
                      '--nexe-prefix',
                      dest='nexe_prefix',
                      default='',
                      help='A path to prepend to nexes in the .nmf',
                      metavar='DIRECTORY')
    parser.add_option('-s',
                      '--stage-dependencies',
                      dest='stage_dependencies',
                      help='Destination directory for staging libraries',
                      metavar='DIRECTORY')
    parser.add_option('--no-arch-prefix',
                      action='store_true',
                      help='Don\'t put shared libraries in the lib32/lib64 '
                      'directories. Instead, they will be put in the same '
                      'directory as the .nexe that matches its architecture.')
    parser.add_option('-t', '--toolchain', help='Legacy option, do not use')
    parser.add_option('-n',
                      '--name',
                      dest='name',
                      help='Rename FOO as BAR',
                      action='append',
                      default=[],
                      metavar='FOO,BAR')
    parser.add_option('-x',
                      '--extra-files',
                      help=('Add extra key:file tuple to the "files"' +
                            ' section of the .nmf'),
                      action='append',
                      default=[],
                      metavar='FILE')
    parser.add_option(
        '-O',
        '--pnacl-optlevel',
        help='Set the optimization level to N in PNaCl manifests',
        metavar='N')
    parser.add_option('--pnacl-debug-optlevel',
                      help='Set the optimization level to N for debugging '
                      'sections in PNaCl manifests',
                      metavar='N')
    parser.add_option('-v',
                      '--verbose',
                      help='Verbose output',
                      action='store_true')
    parser.add_option('-d',
                      '--debug-mode',
                      help='Debug mode',
                      action='store_true')

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete create_nmf.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options, args = parser.parse_args(argv)
    if options.verbose:
        Trace.verbose = True
    if options.debug_mode:
        DebugPrint.debug_mode = True

    if options.toolchain is not None:
        sys.stderr.write('warning: option -t/--toolchain is deprecated.\n')

    if len(args) < 1:
        parser.error('No nexe files specified.  See --help for more info')

    canonicalized = ParseExtraFiles(options.extra_files, sys.stderr)
    if canonicalized is None:
        parser.error('Bad --extra-files (-x) argument syntax')

    remap = {}
    for ren in options.name:
        parts = ren.split(',')
        if len(parts) != 2:
            parser.error('Expecting --name=<orig_arch.so>,<new_name.so>')
        remap[parts[0]] = parts[1]

    if options.path_prefix:
        options.lib_prefix = options.path_prefix

    for libpath in options.lib_path:
        if not os.path.exists(libpath):
            sys.stderr.write('Specified library path does not exist: %s\n' %
                             libpath)
        elif not os.path.isdir(libpath):
            sys.stderr.write('Specified library is not a directory: %s\n' %
                             libpath)

    if not options.no_default_libpath:
        # Add default libraries paths to the end of the search path.
        config = options.debug_libs and 'Debug' or 'Release'
        options.lib_path += GetDefaultLibPath(config)
        for path in options.lib_path:
            Trace('libpath: %s' % path)

    pnacl_optlevel = None
    if options.pnacl_optlevel is not None:
        pnacl_optlevel = int(options.pnacl_optlevel)
        if pnacl_optlevel < 0 or pnacl_optlevel > 3:
            sys.stderr.write(
                'warning: PNaCl optlevel %d is unsupported (< 0 or > 3)\n' %
                pnacl_optlevel)
    if options.pnacl_debug_optlevel is not None:
        pnacl_debug_optlevel = int(options.pnacl_debug_optlevel)
    else:
        pnacl_debug_optlevel = pnacl_optlevel

    nmf_root = None
    if options.output:
        nmf_root = os.path.dirname(options.output)

    nmf = NmfUtils(objdump=options.objdump,
                   main_files=args,
                   lib_path=options.lib_path,
                   extra_files=canonicalized,
                   lib_prefix=options.lib_prefix,
                   nexe_prefix=options.nexe_prefix,
                   no_arch_prefix=options.no_arch_prefix,
                   remap=remap,
                   pnacl_optlevel=pnacl_optlevel,
                   pnacl_debug_optlevel=pnacl_debug_optlevel,
                   nmf_root=nmf_root)

    if not options.output:
        sys.stdout.write(nmf.GetJson())
    else:
        with open(options.output, 'w') as output:
            output.write(nmf.GetJson())

    if options.stage_dependencies and not nmf.pnacl:
        Trace('Staging dependencies...')
        nmf.StageDependencies(options.stage_dependencies)

    return 0
Example #36
0
def main(argv):
    epilog = 'Example: sel_ldr.py my_nexe.nexe'
    parser = argparse.ArgumentParser(description=__doc__, epilog=epilog)
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Verbose output')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='Enable debug stub')
    parser.add_argument('--debug-libs',
                        action='store_true',
                        help='For dynamic executables, reference debug '
                        'libraries rather then release')
    parser.add_argument('executable', help='executable (.nexe) to run')
    parser.add_argument('args',
                        nargs='*',
                        help='argument to pass to exectuable')

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete sel_ldr.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(argv)

    if options.verbose:
        Log.verbose = True

    osname = getos.GetPlatform()
    if not os.path.exists(options.executable):
        raise Error('executable not found: %s' % options.executable)
    if not os.path.isfile(options.executable):
        raise Error('not a file: %s' % options.executable)

    arch, dynamic = create_nmf.ParseElfHeader(options.executable)

    if arch == 'arm' and osname != 'linux':
        raise Error('Cannot run ARM executables under sel_ldr on ' + osname)

    arch_suffix = arch.replace('-', '_')

    sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix)
    irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix)
    if osname == 'win':
        sel_ldr += '.exe'
    Log('ROOT    = %s' % NACL_SDK_ROOT)
    Log('SEL_LDR = %s' % sel_ldr)
    Log('IRT     = %s' % irt)
    cmd = [sel_ldr]

    if osname == 'linux':
        # Run sel_ldr under nacl_helper_bootstrap
        helper = os.path.join(SCRIPT_DIR,
                              'nacl_helper_bootstrap_%s' % arch_suffix)
        Log('HELPER  = %s' % helper)
        cmd.insert(0, helper)
        cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX')
        cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX')

    cmd += ['-a', '-B', irt]

    if options.debug:
        cmd.append('-g')

    if not options.verbose:
        cmd += ['-l', os.devnull]

    if arch == 'arm':
        # Use the QEMU arm emulator if available.
        qemu_bin = FindQemu()
        if qemu_bin:
            qemu = [
                qemu_bin, '-cpu', 'cortex-a8', '-L',
                os.path.abspath(
                    os.path.join(NACL_SDK_ROOT, 'toolchain',
                                 'linux_arm_trusted'))
            ]
            # '-Q' disables platform qualification, allowing arm binaries to run.
            cmd = qemu + cmd + ['-Q']
        else:
            raise Error(
                'Cannot run ARM executables under sel_ldr without an emulator'
                '. Try installing QEMU (http://wiki.qemu.org/).')

    if dynamic:
        if options.debug_libs:
            libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                                   'glibc_%s' % arch_suffix, 'Debug')
        else:
            libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                                   'glibc_%s' % arch_suffix, 'Release')
        toolchain = '%s_x86_glibc' % osname
        sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', toolchain,
                                   'x86_64-nacl')
        if arch == 'x86-64':
            sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib')
        else:
            sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32')
        ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so')
        cmd.append(ldso)
        Log('LD.SO = %s' % ldso)
        libpath += ':' + sdk_lib_dir
        cmd.append('--library-path')
        cmd.append(libpath)

    # Append arguments for the executable itself.
    cmd.append(options.executable)
    cmd += options.args

    Log(cmd)
    return subprocess.call(cmd)
Example #37
0
                         default=5.0),
    optparse.make_option("--debug-threading",action="store_true",dest='thread_debug',
                         help="Print debugging information about threading."),
    optparse.make_option("--debug-file",action="store",type="string",dest="debug_file",
                         help="Regular expression that matches filename(s) whose code we want to display debug messages from.",
                         default=""),
    optparse.make_option("-q",action='store_const',const=-1,
                         dest='debug',
                         help="Don't print gourmet error messages"),
    optparse.make_option("--showtimes",action="store_true",dest="time",
                         help="Print timestamps on debug statements."),
    optparse.make_option("-v",action='count',
                         help="Be verbose (extra v's will increase the verbosity level",
                         dest='debug'),
    optparse.make_option("--gourmet-base",
                         dest="gourmet_base",
                         help="Root directory for Gourmet data files.",
                         action="store",
                         default=""),
    optparse.make_option("--disable-psyco",
                         dest="psyco",
                         action="store_false",
                         help="Do not use psyco if it is installed.",
                         default=True),
    ]
    )
if has_optcomplete:
    optcomplete.autocomplete(parser)

(options, args) = parser.parse_args()
Example #38
0
def main(args):
  parser = optparse.OptionParser()
  parser.add_option('--tar', help='Force the tar step.',
      action='store_true')
  parser.add_option('--archive', help='Force the archive step.',
      action='store_true')
  parser.add_option('--gyp',
      help='Use gyp to build examples/libraries/Makefiles.',
      action='store_true')
  parser.add_option('--release', help='PPAPI release version.',
      dest='release', default=None)
  parser.add_option('--build-ports',
      help='Build naclport bundle.', action='store_true')
  parser.add_option('--build-app-engine',
      help='Build AppEngine demos.', action='store_true')
  parser.add_option('--experimental',
      help='build experimental examples and libraries', action='store_true',
      dest='build_experimental')
  parser.add_option('--skip-toolchain', help='Skip toolchain untar',
      action='store_true')
  parser.add_option('--mac-sdk',
      help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  global options
  options, args = parser.parse_args(args[1:])

  generate_make.use_gyp = options.gyp
  if buildbot_common.IsSDKBuilder():
    options.archive = True
    options.build_ports = True
    options.build_app_engine = True
    options.tar = True

  toolchains = ['newlib', 'glibc', 'arm', 'pnacl', 'host']
  print 'Building: ' + ' '.join(toolchains)

  if options.archive and not options.tar:
    parser.error('Incompatible arguments with archive.')

  chrome_version = int(build_version.ChromeMajorVersion())
  chrome_revision = build_version.ChromeRevision()
  nacl_revision = build_version.NaClRevision()
  pepper_ver = str(chrome_version)
  pepper_old = str(chrome_version - 1)
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
  tarname = 'naclsdk_' + getos.GetPlatform() + '.tar.bz2'
  tarfile = os.path.join(OUT_DIR, tarname)

  if options.release:
    pepper_ver = options.release
  print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  if not options.skip_toolchain:
    BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
    BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
    BuildStepDownloadToolchains()
    BuildStepUntarToolchains(pepperdir, toolchains)

  BuildStepBuildToolchains(pepperdir, toolchains)

  BuildStepUpdateHelpers(pepperdir, True)
  BuildStepUpdateUserProjects(pepperdir, toolchains,
                              options.build_experimental, True)

  BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision)

  # Ship with libraries prebuilt, so run that first.
  BuildStepBuildLibraries(pepperdir, 'src')
  GenerateNotice(pepperdir)

  # Verify the SDK contains what we expect.
  BuildStepVerifyFilelist(pepperdir)

  if options.tar:
    BuildStepTarBundle(pepper_ver, tarfile)

  if options.build_ports and getos.GetPlatform() == 'linux':
    ports_tarfile = os.path.join(OUT_DIR, 'naclports.tar.bz2')
    BuildStepSyncNaClPorts()
    BuildStepBuildNaClPorts(pepper_ver, pepperdir)
    if options.tar:
      BuildStepTarNaClPorts(pepper_ver, ports_tarfile)

  if options.build_app_engine and getos.GetPlatform() == 'linux':
    BuildStepBuildAppEngine(pepperdir, chrome_revision)

  # Archive on non-trybots.
  if options.archive:
    BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision,
                           tarfile)
    if options.build_ports and getos.GetPlatform() == 'linux':
      BuildStepArchiveBundle('naclports', pepper_ver, chrome_revision,
                             nacl_revision, ports_tarfile)
    BuildStepArchiveSDKTools()

  return 0
Example #39
0
def main(args):
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('--qemu', help='Add qemu for ARM.',
      action='store_true')
  parser.add_argument('--tar', help='Force the tar step.',
      action='store_true')
  parser.add_argument('--archive', help='Force the archive step.',
      action='store_true')
  parser.add_argument('--release', help='PPAPI release version.',
      dest='release', default=None)
  parser.add_argument('--build-app-engine',
      help='Build AppEngine demos.', action='store_true')
  parser.add_argument('--experimental',
      help='build experimental examples and libraries', action='store_true',
      dest='build_experimental')
  parser.add_argument('--skip-toolchain', help='Skip toolchain untar',
      action='store_true')
  parser.add_argument('--no-clean', dest='clean', action='store_false',
      help="Don't clean gypbuild directories")
  parser.add_argument('--mac-sdk',
      help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')
  parser.add_argument('--no-arm-trusted', action='store_true',
      help='Disable building of ARM trusted components (sel_ldr, etc).')
  parser.add_argument('--no-use-sysroot', action='store_true',
      help='Disable building against sysroot.')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  global options
  options = parser.parse_args(args)

  buildbot_common.BuildStep('build_sdk')

  if buildbot_common.IsSDKBuilder():
    options.archive = True
    # TODO(binji): re-enable app_engine build when the linux builder stops
    # breaking when trying to git clone from github.
    # See http://crbug.com/412969.
    options.build_app_engine = False
    options.tar = True

  # NOTE: order matters here. This will be the order that is specified in the
  # Makefiles; the first toolchain will be the default.
  toolchains = ['pnacl', 'x86_glibc', 'arm_glibc', 'clang-newlib', 'host']

  print 'Building: ' + ' '.join(toolchains)
  platform = getos.GetPlatform()

  if options.archive and not options.tar:
    parser.error('Incompatible arguments with archive.')

  chrome_version = int(build_version.ChromeMajorVersion())
  chrome_revision = build_version.ChromeRevision()
  nacl_revision = build_version.NaClRevision()
  pepper_ver = str(chrome_version)
  pepper_old = str(chrome_version - 1)
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
  tarname = 'naclsdk_%s.tar.bz2' % platform
  tarfile = os.path.join(OUT_DIR, tarname)

  if options.release:
    pepper_ver = options.release
  print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  if platform == 'linux':
    # Linux-only: make sure the debian/stable sysroot image is installed
    install_script = os.path.join(SRC_DIR, 'build', 'linux', 'sysroot_scripts',
                                  'install-sysroot.py')

    buildbot_common.Run([sys.executable, install_script, '--arch=arm'])
    buildbot_common.Run([sys.executable, install_script, '--arch=i386'])
    buildbot_common.Run([sys.executable, install_script, '--arch=amd64'])

  if not options.skip_toolchain:
    BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
    BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
    BuildStepDownloadToolchains(toolchains)
    BuildStepUntarToolchains(pepperdir, toolchains)
    if platform == 'linux':
      buildbot_common.Move(os.path.join(pepperdir, 'toolchain', 'arm_trusted'),
                           os.path.join(OUT_DIR, 'arm_trusted'))


  if platform == 'linux':
    # Linux-only: Copy arm libraries from the arm_trusted package.  These are
    # needed to be able to run sel_ldr_arm under qemu.
    arm_libs = [
      'lib/arm-linux-gnueabihf/librt.so.1',
      'lib/arm-linux-gnueabihf/libpthread.so.0',
      'lib/arm-linux-gnueabihf/libgcc_s.so.1',
      'lib/arm-linux-gnueabihf/libc.so.6',
      'lib/arm-linux-gnueabihf/ld-linux-armhf.so.3',
      'lib/arm-linux-gnueabihf/libm.so.6',
      'usr/lib/arm-linux-gnueabihf/libstdc++.so.6'
    ]
    arm_lib_dir = os.path.join(pepperdir, 'tools', 'lib', 'arm_trusted', 'lib')
    buildbot_common.MakeDir(arm_lib_dir)
    for arm_lib in arm_libs:
      arm_lib = os.path.join(OUT_DIR, 'arm_trusted', arm_lib)
      buildbot_common.CopyFile(arm_lib, arm_lib_dir)
    buildbot_common.CopyFile(os.path.join(OUT_DIR, 'arm_trusted', 'qemu-arm'),
                             os.path.join(pepperdir, 'tools'))


  BuildStepBuildToolchains(pepperdir, toolchains,
                           not options.skip_toolchain,
                           options.clean)

  BuildStepUpdateHelpers(pepperdir, True)
  BuildStepUpdateUserProjects(pepperdir, toolchains,
                              options.build_experimental, True)

  BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision)

  # Ship with libraries prebuilt, so run that first.
  BuildStepBuildLibraries(pepperdir, 'src')
  GenerateNotice(pepperdir)

  # Verify the SDK contains what we expect.
  BuildStepVerifyFilelist(pepperdir)

  if options.tar:
    BuildStepTarBundle(pepper_ver, tarfile)

  if platform == 'linux':
    BuildStepBuildPNaClComponent(pepper_ver, chrome_revision)

  if options.build_app_engine and platform == 'linux':
    BuildStepBuildAppEngine(pepperdir, chrome_revision)

  if options.qemu:
    qemudir = os.path.join(NACL_DIR, 'toolchain', 'linux_arm-trusted')
    oshelpers.Copy(['-r', qemudir, pepperdir])

  # Archive the results on Google Cloud Storage.
  if options.archive:
    BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision,
                           tarfile)
    # Only archive sdk_tools/naclport/pnacl_component on linux.
    if platform == 'linux':
      BuildStepArchiveSDKTools()
      BuildStepArchivePNaClComponent(chrome_revision)

  return 0
Example #40
0
def main(argv):
    epilog = 'Example: sel_ldr.py my_nexe.nexe'
    parser = argparse.ArgumentParser(description=__doc__, epilog=epilog)
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Verbose output')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='Enable debug stub')
    parser.add_argument('-e',
                        '--exceptions',
                        action='store_true',
                        help='Enable exception handling interface')
    parser.add_argument('-p',
                        '--passthrough-environment',
                        action='store_true',
                        help='Pass environment of host through to nexe')
    parser.add_argument('--debug-libs',
                        action='store_true',
                        help='Legacy option, do not use')
    parser.add_argument(
        '--config',
        default='Release',
        help='Use a particular library configuration (normally '
        'Debug or Release)')
    parser.add_argument('executable', help='executable (.nexe) to run')
    parser.add_argument('args',
                        nargs='*',
                        help='argument to pass to exectuable')
    parser.add_argument('--library-path', help='Pass extra library paths')

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete sel_ldr.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(argv)

    if options.verbose:
        Log.verbose = True

    osname = getos.GetPlatform()
    if not os.path.exists(options.executable):
        raise Error('executable not found: %s' % options.executable)
    if not os.path.isfile(options.executable):
        raise Error('not a file: %s' % options.executable)

    elf_arch, dynamic = create_nmf.ParseElfHeader(options.executable)

    if elf_arch == 'arm' and osname != 'linux':
        raise Error('Cannot run ARM executables under sel_ldr on ' + osname)

    arch_suffix = elf_arch.replace('-', '_')

    sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix)
    irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix)
    if osname == 'win':
        sel_ldr += '.exe'
    Log('ROOT    = %s' % NACL_SDK_ROOT)
    Log('SEL_LDR = %s' % sel_ldr)
    Log('IRT     = %s' % irt)
    cmd = [sel_ldr]

    if osname == 'linux':
        # Run sel_ldr under nacl_helper_bootstrap
        helper = os.path.join(SCRIPT_DIR,
                              'nacl_helper_bootstrap_%s' % arch_suffix)
        Log('HELPER  = %s' % helper)
        cmd.insert(0, helper)
        cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX')
        cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX')

    # This script is provided mostly as way to run binaries during testing, not
    # to run untrusted code in a production environment.  As such we want it be
    # as invisible as possible.  So we pass -q (quiet) to disable most of output
    # of sel_ldr itself, and -a (disable ACL) to enable local filesystem access.
    cmd += ['-q', '-a', '-B', irt]

    # Set the default NACLVERBOSITY level LOG_ERROR (-3).  This can still be
    # overridden in the environment if debug information is desired.  However
    # in most cases we don't want the application stdout/stderr polluted with
    # sel_ldr logging.
    if 'NACLVERBOSITY' not in os.environ and not options.verbose:
        os.environ['NACLVERBOSITY'] = "-3"

    if options.debug:
        cmd.append('-g')

    if options.exceptions:
        cmd.append('-e')

    if options.passthrough_environment:
        cmd.append('-p')

    if elf_arch == 'arm':
        # Use the QEMU arm emulator if available.
        qemu_bin = FindQemu()
        if not qemu_bin:
            raise Error(
                'Cannot run ARM executables under sel_ldr without an emulator'
                '. Try installing QEMU (http://wiki.qemu.org/).')

        arm_libpath = os.path.join(NACL_SDK_ROOT, 'tools', 'lib',
                                   'arm_trusted')
        if not os.path.isdir(arm_libpath):
            raise Error('Could not find ARM library path: %s' % arm_libpath)
        qemu = [qemu_bin, '-cpu', 'cortex-a8', '-L', arm_libpath]
        # '-Q' disables platform qualification, allowing arm binaries to run.
        cmd = qemu + cmd + ['-Q']

    if dynamic:
        if options.debug_libs:
            sys.stderr.write(
                'warning: --debug-libs is deprecated (use --config).\n')
            options.config = 'Debug'

        sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'lib',
                                   'glibc_%s' % arch_suffix, options.config)

        if elf_arch == 'x86-64':
            lib_subdir = 'lib'
            tcarch = 'x86'
            tcsubarch = 'x86_64'
            usr_arch = 'x86_64'
        elif elf_arch == 'arm':
            lib_subdir = 'lib'
            tcarch = 'arm'
            tcsubarch = 'arm'
            usr_arch = 'arm'
        elif elf_arch == 'x86-32':
            lib_subdir = 'lib32'
            tcarch = 'x86'
            tcsubarch = 'x86_64'
            usr_arch = 'i686'
        else:
            raise Error("Unknown arch: %s" % elf_arch)

        toolchain = '%s_%s_glibc' % (osname, tcarch)
        toolchain_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', toolchain)
        interp_prefix = os.path.join(toolchain_dir, tcsubarch + '-nacl')
        lib_dir = os.path.join(interp_prefix, lib_subdir)
        usr_lib_dir = os.path.join(toolchain_dir, usr_arch + '-nacl', 'usr',
                                   'lib')

        libpath = [usr_lib_dir, sdk_lib_dir, lib_dir]

        if options.config not in ['Debug', 'Release']:
            config_fallback = 'Release'
            if 'Debug' in options.config:
                config_fallback = 'Debug'
            libpath.append(
                os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix,
                             config_fallback))

        if options.library_path:
            libpath.extend(
                [os.path.abspath(p) for p in options.library_path.split(':')])
        libpath = ':'.join(libpath)
        if elf_arch == 'arm':
            ldso = os.path.join(SCRIPT_DIR, 'elf_loader_arm.nexe')
            cmd.append('-E')
            cmd.append('LD_LIBRARY_PATH=%s' % libpath)
            cmd.append(ldso)
            cmd.append('--interp-prefix')
            cmd.append(interp_prefix)
        else:
            ldso = os.path.join(lib_dir, 'runnable-ld.so')
            cmd.append(ldso)
            cmd.append('--library-path')
            cmd.append(libpath)
        Log('dynamic loader = %s' % ldso)

    # Append arguments for the executable itself.
    cmd.append(options.executable)
    cmd += options.args

    Log(cmd)
    return subprocess.call(cmd)
def main(args):
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option('--nacl-tree-path',
                      help='Path to native client tree for bionic build.',
                      dest='nacl_tree_path')
    parser.add_option('--qemu', help='Add qemu for ARM.', action='store_true')
    parser.add_option('--bionic',
                      help='Add bionic build.',
                      action='store_true')
    parser.add_option('--tar', help='Force the tar step.', action='store_true')
    parser.add_option('--archive',
                      help='Force the archive step.',
                      action='store_true')
    parser.add_option('--release',
                      help='PPAPI release version.',
                      dest='release',
                      default=None)
    parser.add_option('--build-ports',
                      help='Build naclport bundle.',
                      action='store_true')
    parser.add_option('--build-app-engine',
                      help='Build AppEngine demos.',
                      action='store_true')
    parser.add_option('--experimental',
                      help='build experimental examples and libraries',
                      action='store_true',
                      dest='build_experimental')
    parser.add_option('--skip-toolchain',
                      help='Skip toolchain untar',
                      action='store_true')
    parser.add_option(
        '--mac-sdk',
        help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')
    parser.add_option(
        '--no-arm-trusted',
        action='store_true',
        help='Disable building of ARM trusted components (sel_ldr, etc).')

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete build_sdk.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    global options
    options, args = parser.parse_args(args[1:])
    if args:
        parser.error("Unexpected arguments: %s" % str(args))

    if options.nacl_tree_path:
        options.bionic = True
        toolchain_build = os.path.join(options.nacl_tree_path,
                                       'toolchain_build')
        print 'WARNING: Building bionic toolchain from NaCl checkout.'
        print 'This option builds bionic from the sources currently in the'
        print 'provided NativeClient checkout, and the results instead of '
        print 'downloading a toolchain from the builder. This may result in a'
        print 'NaCl SDK that can not run on ToT chrome.'
        print 'NOTE:  To clobber you will need to run toolchain_build_bionic.py'
        print 'directly from the NativeClient checkout.'
        print ''
        response = raw_input("Type 'y' and hit enter to continue.\n")
        if response != 'y' and response != 'Y':
            print 'Aborting.'
            return 1

        # Get head version of NativeClient tree
        buildbot_common.BuildStep('Build bionic toolchain.')
        buildbot_common.Run(
            [sys.executable, 'toolchain_build_bionic.py', '-f'],
            cwd=toolchain_build)
    else:
        toolchain_build = None

    if buildbot_common.IsSDKBuilder():
        options.archive = True
        options.build_ports = True
        # TODO(binji): re-enable app_engine build when the linux builder stops
        # breaking when trying to git clone from github.
        # See http://crbug.com/412969.
        options.build_app_engine = False
        options.tar = True

    # NOTE: order matters here. This will be the order that is specified in the
    # Makefiles; the first toolchain will be the default.
    toolchains = ['pnacl', 'newlib', 'glibc', 'arm', 'host']

    # Changes for experimental bionic builder
    if options.bionic:
        toolchains.append('bionic')
        options.build_ports = False
        options.build_app_engine = False

    print 'Building: ' + ' '.join(toolchains)

    if options.archive and not options.tar:
        parser.error('Incompatible arguments with archive.')

    chrome_version = int(build_version.ChromeMajorVersion())
    chrome_revision = build_version.ChromeRevision()
    nacl_revision = build_version.NaClRevision()
    pepper_ver = str(chrome_version)
    pepper_old = str(chrome_version - 1)
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
    pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
    if options.bionic:
        tarname = 'naclsdk_bionic.tar.bz2'
    else:
        tarname = 'naclsdk_' + getos.GetPlatform() + '.tar.bz2'
    tarfile = os.path.join(OUT_DIR, tarname)

    if options.release:
        pepper_ver = options.release
    print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

    if 'NACL_SDK_ROOT' in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # of the build.
        del os.environ['NACL_SDK_ROOT']

    if not options.skip_toolchain:
        BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
        BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
        BuildStepDownloadToolchains(toolchains)
        if options.nacl_tree_path:
            # Instead of untarring, copy the raw bionic toolchain
            not_bionic = [i for i in toolchains if i != 'bionic']
            BuildStepUntarToolchains(pepperdir, not_bionic)
            tcname = GetToolchainDirName('bionic', 'arm')
            srcdir = os.path.join(toolchain_build, 'out', tcname)
            bionicdir = os.path.join(pepperdir, 'toolchain', tcname)
            oshelpers.Copy(['-r', srcdir, bionicdir])
        else:
            BuildStepUntarToolchains(pepperdir, toolchains)

        BuildStepBuildToolchains(pepperdir, toolchains)

    BuildStepUpdateHelpers(pepperdir, True)
    BuildStepUpdateUserProjects(pepperdir, toolchains,
                                options.build_experimental, True)

    BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision,
                           nacl_revision)

    # Ship with libraries prebuilt, so run that first.
    BuildStepBuildLibraries(pepperdir, 'src')
    GenerateNotice(pepperdir)

    # Verify the SDK contains what we expect.
    if not options.bionic:
        BuildStepVerifyFilelist(pepperdir)

    if options.tar:
        BuildStepTarBundle(pepper_ver, tarfile)

    if options.build_ports and getos.GetPlatform() == 'linux':
        ports_tarfile = os.path.join(OUT_DIR, 'naclports.tar.bz2')
        BuildStepSyncNaClPorts()
        BuildStepBuildNaClPorts(pepper_ver, pepperdir)
        if options.tar:
            BuildStepTarNaClPorts(pepper_ver, ports_tarfile)

    if options.build_app_engine and getos.GetPlatform() == 'linux':
        BuildStepBuildAppEngine(pepperdir, chrome_revision)

    if options.qemu:
        qemudir = os.path.join(NACL_DIR, 'toolchain', 'linux_arm-trusted')
        oshelpers.Copy(['-r', qemudir, pepperdir])

    # Archive on non-trybots.
    if options.archive:
        BuildStepArchiveBundle('build', pepper_ver, chrome_revision,
                               nacl_revision, tarfile)
        if options.build_ports and getos.GetPlatform() == 'linux':
            BuildStepArchiveBundle('naclports', pepper_ver, chrome_revision,
                                   nacl_revision, ports_tarfile)
        BuildStepArchiveSDKTools()

    return 0
def main(args):
  parser = optparse.OptionParser(description=__doc__)
  parser.add_option('--nacl-tree-path',
      help='Path to native client tree for bionic build.',
      dest='nacl_tree_path')
  parser.add_option('--qemu', help='Add qemu for ARM.',
      action='store_true')
  parser.add_option('--bionic', help='Add bionic build.',
      action='store_true')
  parser.add_option('--tar', help='Force the tar step.',
      action='store_true')
  parser.add_option('--archive', help='Force the archive step.',
      action='store_true')
  parser.add_option('--release', help='PPAPI release version.',
      dest='release', default=None)
  parser.add_option('--build-ports',
      help='Build naclport bundle.', action='store_true')
  parser.add_option('--build-app-engine',
      help='Build AppEngine demos.', action='store_true')
  parser.add_option('--experimental',
      help='build experimental examples and libraries', action='store_true',
      dest='build_experimental')
  parser.add_option('--skip-toolchain', help='Skip toolchain untar',
      action='store_true')
  parser.add_option('--mac-sdk',
      help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')
  parser.add_option('--no-arm-trusted', action='store_true',
      help='Disable building of ARM trusted components (sel_ldr, etc).')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  global options
  options, args = parser.parse_args(args[1:])
  if args:
    parser.error("Unexpected arguments: %s" % str(args))

  if options.nacl_tree_path:
    options.bionic = True
    toolchain_build = os.path.join(options.nacl_tree_path, 'toolchain_build')
    print 'WARNING: Building bionic toolchain from NaCl checkout.'
    print 'This option builds bionic from the sources currently in the'
    print 'provided NativeClient checkout, and the results instead of '
    print 'downloading a toolchain from the builder. This may result in a'
    print 'NaCl SDK that can not run on ToT chrome.'
    print 'NOTE:  To clobber you will need to run toolchain_build_bionic.py'
    print 'directly from the NativeClient checkout.'
    print ''
    response = raw_input("Type 'y' and hit enter to continue.\n")
    if response != 'y' and response != 'Y':
      print 'Aborting.'
      return 1

    # Get head version of NativeClient tree
    buildbot_common.BuildStep('Build bionic toolchain.')
    buildbot_common.Run([sys.executable, 'toolchain_build_bionic.py', '-f'],
                        cwd=toolchain_build)
  else:
    toolchain_build = None

  if buildbot_common.IsSDKBuilder():
    options.archive = True
    options.build_ports = True
    # TODO(binji): re-enable app_engine build when the linux builder stops
    # breaking when trying to git clone from github.
    # See http://crbug.com/412969.
    options.build_app_engine = False
    options.tar = True

  # NOTE: order matters here. This will be the order that is specified in the
  # Makefiles; the first toolchain will be the default.
  toolchains = ['pnacl', 'newlib', 'glibc', 'arm', 'host']

  # Changes for experimental bionic builder
  if options.bionic:
    toolchains.append('bionic')
    options.build_ports = False
    options.build_app_engine = False

  print 'Building: ' + ' '.join(toolchains)

  if options.archive and not options.tar:
    parser.error('Incompatible arguments with archive.')

  chrome_version = int(build_version.ChromeMajorVersion())
  chrome_revision = build_version.ChromeRevision()
  nacl_revision = build_version.NaClRevision()
  pepper_ver = str(chrome_version)
  pepper_old = str(chrome_version - 1)
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
  if options.bionic:
    tarname = 'naclsdk_bionic.tar.bz2'
  else:
    tarname = 'naclsdk_' + getos.GetPlatform() + '.tar.bz2'
  tarfile = os.path.join(OUT_DIR, tarname)

  if options.release:
    pepper_ver = options.release
  print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  if not options.skip_toolchain:
    BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
    BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
    BuildStepDownloadToolchains(toolchains)
    if options.nacl_tree_path:
      # Instead of untarring, copy the raw bionic toolchain
      not_bionic = [i for i in toolchains if i != 'bionic']
      BuildStepUntarToolchains(pepperdir, not_bionic)
      tcname = GetToolchainDirName('bionic', 'arm')
      srcdir = os.path.join(toolchain_build, 'out', tcname)
      bionicdir = os.path.join(pepperdir, 'toolchain', tcname)
      oshelpers.Copy(['-r', srcdir, bionicdir])
    else:
      BuildStepUntarToolchains(pepperdir, toolchains)

    BuildStepBuildToolchains(pepperdir, toolchains)

  BuildStepUpdateHelpers(pepperdir, True)
  BuildStepUpdateUserProjects(pepperdir, toolchains,
                              options.build_experimental, True)

  BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision)

  # Ship with libraries prebuilt, so run that first.
  BuildStepBuildLibraries(pepperdir, 'src')
  GenerateNotice(pepperdir)

  # Verify the SDK contains what we expect.
  if not options.bionic:
    BuildStepVerifyFilelist(pepperdir)

  if options.tar:
    BuildStepTarBundle(pepper_ver, tarfile)

  if options.build_ports and getos.GetPlatform() == 'linux':
    ports_tarfile = os.path.join(OUT_DIR, 'naclports.tar.bz2')
    BuildStepSyncNaClPorts()
    BuildStepBuildNaClPorts(pepper_ver, pepperdir)
    if options.tar:
      BuildStepTarNaClPorts(pepper_ver, ports_tarfile)

  if options.build_app_engine and getos.GetPlatform() == 'linux':
    BuildStepBuildAppEngine(pepperdir, chrome_revision)

  if options.qemu:
    qemudir = os.path.join(NACL_DIR, 'toolchain', 'linux_arm-trusted')
    oshelpers.Copy(['-r', qemudir, pepperdir])

  # Archive on non-trybots.
  if options.archive:
    BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision,
                           tarfile)
    if options.build_ports and getos.GetPlatform() == 'linux':
      BuildStepArchiveBundle('naclports', pepper_ver, chrome_revision,
                             nacl_revision, ports_tarfile)
    BuildStepArchiveSDKTools()

  return 0
Example #43
0
def main(args):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "-o", "--output", dest="output", help="Write manifest file to FILE (default is stdout)", metavar="FILE"
    )
    parser.add_argument(
        "-D",
        "--objdump",
        dest="objdump",
        help='Override the default "objdump" tool used to find ' "shared object dependencies",
        metavar="TOOL",
    )
    parser.add_argument("--no-default-libpath", action="store_true", help="Don't include the SDK default library paths")
    parser.add_argument("--debug-libs", action="store_true", help="Legacy option, do not use")
    parser.add_argument(
        "--config", default="Release", help="Use a particular library configuration (normally " "Debug or Release)"
    )
    parser.add_argument(
        "-L",
        "--library-path",
        dest="lib_path",
        action="append",
        default=[],
        help="Add DIRECTORY to library search path",
        metavar="DIRECTORY",
    )
    parser.add_argument(
        "-P",
        "--path-prefix",
        dest="path_prefix",
        default="",
        help="Deprecated. An alias for --lib-prefix.",
        metavar="DIRECTORY",
    )
    parser.add_argument(
        "-p",
        "--lib-prefix",
        dest="lib_prefix",
        default="",
        help="A path to prepend to shared libraries in the .nmf",
        metavar="DIRECTORY",
    )
    parser.add_argument(
        "-N",
        "--nexe-prefix",
        dest="nexe_prefix",
        default="",
        help="A path to prepend to nexes in the .nmf",
        metavar="DIRECTORY",
    )
    parser.add_argument(
        "-s",
        "--stage-dependencies",
        dest="stage_dependencies",
        help="Destination directory for staging libraries",
        metavar="DIRECTORY",
    )
    parser.add_argument(
        "--no-arch-prefix",
        action="store_true",
        help="Don't put shared libraries in the lib32/lib64 "
        "directories. Instead, they will be put in the same "
        "directory as the .nexe that matches its architecture.",
    )
    parser.add_argument("-t", "--toolchain", help="Legacy option, do not use")
    parser.add_argument(
        "-n", "--name", dest="name", help="Rename FOO as BAR", action="append", default=[], metavar="FOO,BAR"
    )
    parser.add_argument(
        "-x",
        "--extra-files",
        help='Add extra key:file tuple to the "files"' " section of the .nmf",
        action="append",
        default=[],
        metavar="FILE",
    )
    parser.add_argument(
        "-O", "--pnacl-optlevel", help="Set the optimization level to N in PNaCl manifests", metavar="N"
    )
    parser.add_argument(
        "--pnacl-debug-optlevel",
        help="Set the optimization level to N for debugging " "sections in PNaCl manifests",
        metavar="N",
    )
    parser.add_argument("-v", "--verbose", help="Verbose output", action="store_true")
    parser.add_argument("-d", "--debug-mode", help="Debug mode", action="store_true")
    parser.add_argument("executables", metavar="EXECUTABLE", nargs="+")

    # To enable bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete create_nmf.py
    try:
        import optcomplete

        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(args)
    if options.verbose:
        Trace.verbose = True
    if options.debug_mode:
        DebugPrint.debug_mode = True

    if options.toolchain is not None:
        sys.stderr.write("warning: option -t/--toolchain is deprecated.\n")
    if options.debug_libs:
        sys.stderr.write("warning: --debug-libs is deprecated (use --config).\n")
        # Implement legacy behavior
        options.config = "Debug"

    canonicalized = ParseExtraFiles(options.extra_files, sys.stderr)
    if canonicalized is None:
        parser.error("Bad --extra-files (-x) argument syntax")

    remap = {}
    for ren in options.name:
        parts = ren.split(",")
        if len(parts) != 2:
            parser.error("Expecting --name=<orig_arch.so>,<new_name.so>")
        remap[parts[0]] = parts[1]

    if options.path_prefix:
        options.lib_prefix = options.path_prefix

    for libpath in options.lib_path:
        if not os.path.exists(libpath):
            sys.stderr.write("Specified library path does not exist: %s\n" % libpath)
        elif not os.path.isdir(libpath):
            sys.stderr.write("Specified library is not a directory: %s\n" % libpath)

    if not options.no_default_libpath:
        # Add default libraries paths to the end of the search path.
        options.lib_path += GetDefaultLibPath(options.config)
        for path in options.lib_path:
            Trace("libpath: %s" % path)

    pnacl_optlevel = None
    if options.pnacl_optlevel is not None:
        pnacl_optlevel = int(options.pnacl_optlevel)
        if pnacl_optlevel < 0 or pnacl_optlevel > 3:
            sys.stderr.write("warning: PNaCl optlevel %d is unsupported (< 0 or > 3)\n" % pnacl_optlevel)
    if options.pnacl_debug_optlevel is not None:
        pnacl_debug_optlevel = int(options.pnacl_debug_optlevel)
    else:
        pnacl_debug_optlevel = pnacl_optlevel

    nmf_root = None
    if options.output:
        nmf_root = os.path.dirname(options.output)

    nmf = NmfUtils(
        objdump=options.objdump,
        main_files=options.executables,
        lib_path=options.lib_path,
        extra_files=canonicalized,
        lib_prefix=options.lib_prefix,
        nexe_prefix=options.nexe_prefix,
        no_arch_prefix=options.no_arch_prefix,
        remap=remap,
        pnacl_optlevel=pnacl_optlevel,
        pnacl_debug_optlevel=pnacl_debug_optlevel,
        nmf_root=nmf_root,
    )

    if options.output is None:
        sys.stdout.write(nmf.GetJson())
    else:
        with open(options.output, "w") as output:
            output.write(nmf.GetJson())

    if options.stage_dependencies and not nmf.pnacl:
        Trace("Staging dependencies...")
        nmf.StageDependencies(options.stage_dependencies)

    return 0
Example #44
0
def main(argv):
  epilog = 'Example: sel_ldr.py my_nexe.nexe'
  parser = argparse.ArgumentParser(description=__doc__, epilog=epilog)
  parser.add_argument('-v', '--verbose', action='store_true',
                      help='Verbose output')
  parser.add_argument('-d', '--debug', action='store_true',
                      help='Enable debug stub')
  parser.add_argument('--debug-libs', action='store_true',
                      help='For dynamic executables, reference debug '
                           'libraries rather then release')
  parser.add_argument('executable', help='executable (.nexe) to run')
  parser.add_argument('args', nargs='*', help='argument to pass to exectuable')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete sel_ldr.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(argv)

  if options.verbose:
    Log.verbose = True

  osname = getos.GetPlatform()
  if not os.path.exists(options.executable):
    raise Error('executable not found: %s' % options.executable)
  if not os.path.isfile(options.executable):
    raise Error('not a file: %s' % options.executable)

  arch, dynamic = create_nmf.ParseElfHeader(options.executable)

  if arch == 'arm' and osname != 'linux':
    raise Error('Cannot run ARM executables under sel_ldr on ' + osname)

  arch_suffix = arch.replace('-', '_')

  sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix)
  irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix)
  if osname == 'win':
    sel_ldr += '.exe'
  Log('ROOT    = %s' % NACL_SDK_ROOT)
  Log('SEL_LDR = %s' % sel_ldr)
  Log('IRT     = %s' % irt)
  cmd = [sel_ldr]

  if osname == 'linux':
    # Run sel_ldr under nacl_helper_bootstrap
    helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix)
    Log('HELPER  = %s' % helper)
    cmd.insert(0, helper)
    cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX')
    cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX')

  cmd += ['-a', '-B', irt]

  if options.debug:
    cmd.append('-g')

  if not options.verbose:
    cmd += ['-l', os.devnull]

  if arch == 'arm':
    # Use the QEMU arm emulator if available.
    qemu_bin = FindQemu()
    if qemu_bin:
      qemu = [qemu_bin, '-cpu', 'cortex-a8', '-L',
              os.path.abspath(os.path.join(NACL_SDK_ROOT, 'toolchain',
                                           'linux_arm_trusted'))]
      # '-Q' disables platform qualification, allowing arm binaries to run.
      cmd = qemu + cmd + ['-Q']
    else:
      raise Error('Cannot run ARM executables under sel_ldr without an emulator'
                  '. Try installing QEMU (http://wiki.qemu.org/).')

  if dynamic:
    if options.debug_libs:
      libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                            'glibc_%s' % arch_suffix, 'Debug')
    else:
      libpath = os.path.join(NACL_SDK_ROOT, 'lib',
                            'glibc_%s' % arch_suffix, 'Release')
    toolchain = '%s_x86_glibc' % osname
    sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain',
                               toolchain, 'x86_64-nacl')
    if arch == 'x86-64':
      sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib')
    else:
      sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32')
    ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so')
    cmd.append(ldso)
    Log('LD.SO = %s' % ldso)
    libpath += ':' + sdk_lib_dir
    cmd.append('--library-path')
    cmd.append(libpath)


  # Append arguments for the executable itself.
  cmd.append(options.executable)
  cmd += options.args

  Log(cmd)
  return subprocess.call(cmd)
Example #45
0
def main(args):
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('-o', '--output', dest='output',
                      help='Write manifest file to FILE (default is stdout)',
                      metavar='FILE')
  parser.add_argument('-D', '--objdump', dest='objdump',
                      help='Override the default "objdump" tool used to find '
                           'shared object dependencies',
                      metavar='TOOL')
  parser.add_argument('--no-default-libpath', action='store_true',
                      help="Don't include the SDK default library paths")
  parser.add_argument('--debug-libs', action='store_true',
                      help='Legacy option, do not use')
  parser.add_argument('--config', default='Release',
                      help='Use a particular library configuration (normally '
                           'Debug or Release')
  parser.add_argument('-L', '--library-path', dest='lib_path',
                      action='append', default=[],
                      help='Add DIRECTORY to library search path',
                      metavar='DIRECTORY')
  parser.add_argument('-P', '--path-prefix', dest='path_prefix', default='',
                      help='Deprecated. An alias for --lib-prefix.',
                      metavar='DIRECTORY')
  parser.add_argument('-p', '--lib-prefix', dest='lib_prefix', default='',
                      help='A path to prepend to shared libraries in the .nmf',
                      metavar='DIRECTORY')
  parser.add_argument('-N', '--nexe-prefix', dest='nexe_prefix', default='',
                      help='A path to prepend to nexes in the .nmf',
                      metavar='DIRECTORY')
  parser.add_argument('-s', '--stage-dependencies', dest='stage_dependencies',
                      help='Destination directory for staging libraries',
                      metavar='DIRECTORY')
  parser.add_argument('--no-arch-prefix', action='store_true',
                      help='Don\'t put shared libraries in the lib32/lib64 '
                      'directories. Instead, they will be put in the same '
                      'directory as the .nexe that matches its architecture.')
  parser.add_argument('-t', '--toolchain', help='Legacy option, do not use')
  parser.add_argument('-n', '--name', dest='name',
                      help='Rename FOO as BAR',
                      action='append', default=[], metavar='FOO,BAR')
  parser.add_argument('-x', '--extra-files',
                      help='Add extra key:file tuple to the "files"'
                           ' section of the .nmf',
                      action='append', default=[], metavar='FILE')
  parser.add_argument('-O', '--pnacl-optlevel',
                      help='Set the optimization level to N in PNaCl manifests',
                      metavar='N')
  parser.add_argument('--pnacl-debug-optlevel',
                      help='Set the optimization level to N for debugging '
                           'sections in PNaCl manifests',
                      metavar='N')
  parser.add_argument('-v', '--verbose',
                      help='Verbose output', action='store_true')
  parser.add_argument('-d', '--debug-mode',
                      help='Debug mode', action='store_true')
  parser.add_argument('executables', metavar='EXECUTABLE', nargs='+')

  # To enable bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete create_nmf.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options = parser.parse_args(args)
  if options.verbose:
    Trace.verbose = True
  if options.debug_mode:
    DebugPrint.debug_mode = True

  if options.toolchain is not None:
    sys.stderr.write('warning: option -t/--toolchain is deprecated.\n')
  if options.debug_libs:
    sys.stderr.write('warning: --debug-libs is deprecated (use --config).\n')
    # Implement legacy behavior
    if not options.config:
      options.config = 'Debug'

  canonicalized = ParseExtraFiles(options.extra_files, sys.stderr)
  if canonicalized is None:
    parser.error('Bad --extra-files (-x) argument syntax')

  remap = {}
  for ren in options.name:
    parts = ren.split(',')
    if len(parts) != 2:
      parser.error('Expecting --name=<orig_arch.so>,<new_name.so>')
    remap[parts[0]] = parts[1]

  if options.path_prefix:
    options.lib_prefix = options.path_prefix

  for libpath in options.lib_path:
    if not os.path.exists(libpath):
      sys.stderr.write('Specified library path does not exist: %s\n' % libpath)
    elif not os.path.isdir(libpath):
      sys.stderr.write('Specified library is not a directory: %s\n' % libpath)

  if not options.no_default_libpath:
    # Add default libraries paths to the end of the search path.
    options.lib_path += GetDefaultLibPath(options.config)
    for path in options.lib_path:
      Trace('libpath: %s' % path)

  pnacl_optlevel = None
  if options.pnacl_optlevel is not None:
    pnacl_optlevel = int(options.pnacl_optlevel)
    if pnacl_optlevel < 0 or pnacl_optlevel > 3:
      sys.stderr.write(
          'warning: PNaCl optlevel %d is unsupported (< 0 or > 3)\n' %
          pnacl_optlevel)
  if options.pnacl_debug_optlevel is not None:
    pnacl_debug_optlevel = int(options.pnacl_debug_optlevel)
  else:
    pnacl_debug_optlevel = pnacl_optlevel

  nmf_root = None
  if options.output:
    nmf_root = os.path.dirname(options.output)

  nmf = NmfUtils(objdump=options.objdump,
                 main_files=options.executables,
                 lib_path=options.lib_path,
                 extra_files=canonicalized,
                 lib_prefix=options.lib_prefix,
                 nexe_prefix=options.nexe_prefix,
                 no_arch_prefix=options.no_arch_prefix,
                 remap=remap,
                 pnacl_optlevel=pnacl_optlevel,
                 pnacl_debug_optlevel=pnacl_debug_optlevel,
                 nmf_root=nmf_root)

  if options.output is None:
    sys.stdout.write(nmf.GetJson())
  else:
    with open(options.output, 'w') as output:
      output.write(nmf.GetJson())

  if options.stage_dependencies and not nmf.pnacl:
    Trace('Staging dependencies...')
    nmf.StageDependencies(options.stage_dependencies)

  return 0
def main(args):
  parser = optparse.OptionParser()
  parser.add_option('-c', '--channel',
      help='Channel to display in the name of the package.')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_app.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  options, args = parser.parse_args(args[1:])

  if options.channel:
    if options.channel not in ('Dev', 'Beta'):
      parser.error('Unknown channel: %s' % options.channel)

  toolchains = ['newlib', 'glibc']

  pepper_ver = str(int(build_version.ChromeMajorVersion()))
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  app_dir = os.path.join(OUT_DIR, 'naclsdk_app')
  app_examples_dir = os.path.join(app_dir, 'examples')
  sdk_resources_dir = SDK_RESOURCE_DIR
  platform = getos.GetPlatform()

  buildbot_common.RemoveDir(app_dir)
  buildbot_common.MakeDir(app_dir)

  # Add some dummy directories so build_projects doesn't complain...
  buildbot_common.MakeDir(os.path.join(app_dir, 'tools'))
  buildbot_common.MakeDir(os.path.join(app_dir, 'toolchain'))

  config = 'Release'

  filters = {}
  filters['DISABLE_PACKAGE'] = False
  filters['EXPERIMENTAL'] = False
  filters['TOOLS'] = toolchains
  filters['DEST'] = ['examples/api', 'examples/benchmarks',
                     'examples/getting_started', 'examples/demo',
                     'examples/tutorial']
  tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
  build_projects.UpdateHelpers(app_dir, clobber=True)
  build_projects.UpdateProjects(app_dir, tree, clobber=False,
                                toolchains=toolchains, configs=[config],
                                first_toolchain=True)

  # Collect permissions from each example, and aggregate them.
  def MergeLists(list1, list2):
    return list1 + [x for x in list2 if x not in list1]
  all_permissions = []
  all_socket_permissions = []
  for _, project in parse_dsc.GenerateProjects(tree):
    permissions = project.get('PERMISSIONS', [])
    all_permissions = MergeLists(all_permissions, permissions)
    socket_permissions = project.get('SOCKET_PERMISSIONS', [])
    all_socket_permissions = MergeLists(all_socket_permissions,
                                        socket_permissions)
  if all_socket_permissions:
    all_permissions.append({'socket': all_socket_permissions})
  pretty_permissions = json.dumps(all_permissions, sort_keys=True, indent=4)

  for filename in ['background.js', 'icon128.png']:
    buildbot_common.CopyFile(os.path.join(sdk_resources_dir, filename),
                             os.path.join(app_examples_dir, filename))

  os.environ['NACL_SDK_ROOT'] = pepperdir

  build_projects.BuildProjects(app_dir, tree, deps=False, clean=False,
                               config=config)

  RemoveBuildCruft(app_dir)
  StripNexes(app_dir, platform, pepperdir)

  # Add manifest.json after RemoveBuildCruft... that function removes the
  # manifest.json files for the individual examples.
  name = 'Native Client SDK'
  if options.channel:
    name += ' (%s)' % options.channel
  template_dict = {
    'name': name,
    'channel': options.channel,
    'description':
        'Native Client SDK examples, showing API use and key concepts.',
    'key': False,  # manifests with "key" are rejected when uploading to CWS.
    'permissions': pretty_permissions,
    'version': build_version.ChromeVersionNoTrunk()
  }
  easy_template.RunTemplateFile(
      os.path.join(sdk_resources_dir, 'manifest.json.template'),
      os.path.join(app_examples_dir, 'manifest.json'),
      template_dict)

  app_zip = os.path.join(app_dir, 'examples.zip')
  os.chdir(app_examples_dir)
  oshelpers.Zip([app_zip, '-r', '*'])

  return 0
Example #47
0
    optparse.make_option("--debug-threading-interval",
                         action="store",
                         type="float",
                         dest='thread_debug_interval',
                         help="Interval for threading debug calls",
                         default=5.0),
    optparse.make_option("--debug-threading",action="store_true",dest='thread_debug',
                         help="Print debugging information about threading."),
    optparse.make_option("--debug-file",action="store",type="string",dest="debug_file",
                         help="Regular expression that matches filename(s) whose code we want to display debug messages from.",
                         default=""),
    optparse.make_option("-q",action='store_const',const=-1,
                         dest='debug',
                         help="Don't print gourmet error messages"),
    optparse.make_option("--showtimes",action="store_true",dest="time",
                         help="Print timestamps on debug statements."),
    optparse.make_option("-v",action='count',
                         help="Be verbose (extra v's will increase the verbosity level",
                         dest='debug'),
    optparse.make_option("--disable-psyco",
                         dest="psyco",
                         action="store_false",
                         help="Do not use psyco if it is installed.",
                         default=True),
    ]
    )
if has_optcomplete:
    optcomplete.autocomplete(parser)

(options, args) = parser.parse_args()
Example #48
0
def main(args):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--experimental',
                        help='build experimental tests',
                        action='store_true')
    parser.add_argument('--sanitizer',
                        help='Run sanitizer (asan/tsan/valgrind) tests',
                        action='store_true')
    parser.add_argument('--verbose',
                        '-v',
                        help='Verbose output',
                        action='store_true')
    parser.add_argument('phases', nargs="*")

    if 'NACL_SDK_ROOT' in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # of the build.
        del os.environ['NACL_SDK_ROOT']

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete test_sdk.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    options = parser.parse_args(args)

    pepper_ver = str(int(build_version.ChromeMajorVersion()))
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
    toolchains = ['clang-newlib', 'newlib', 'glibc', 'pnacl']
    toolchains.append(getos.GetPlatform())

    if options.verbose:
        build_projects.verbose = True

    phases = [
        ('build_examples', StepBuildExamples, pepperdir),
        ('copy_tests', StepCopyTests, pepperdir, toolchains,
         options.experimental),
        ('build_tests', StepBuildTests, pepperdir),
        ('sel_ldr_tests', StepRunSelLdrTests, pepperdir, None),
        ('browser_tests', StepRunBrowserTests, toolchains,
         options.experimental),
    ]

    if options.sanitizer:
        if getos.GetPlatform() != 'linux':
            buildbot_common.ErrorExit('sanitizer tests only run on linux.')
        phases += [
            ('sel_ldr_tests_asan', StepRunSelLdrTests, pepperdir, 'address'),
            ('sel_ldr_tests_tsan', StepRunSelLdrTests, pepperdir, 'thread'),
            ('sel_ldr_tests_valgrind', StepRunSelLdrTests, pepperdir,
             'valgrind')
        ]

    if options.phases:
        phase_names = [p[0] for p in phases]
        for arg in options.phases:
            if arg not in phase_names:
                msg = 'Invalid argument: %s\n' % arg
                msg += 'Possible arguments:\n'
                for name in phase_names:
                    msg += '   %s\n' % name
                parser.error(msg.strip())

    for phase in phases:
        phase_name = phase[0]
        if options.phases and phase_name not in options.phases:
            continue
        phase_func = phase[1]
        phase_args = phase[2:]
        phase_func(*phase_args)

    return 0
Example #49
0
def main(args):
  parser = optparse.OptionParser(description=__doc__)
  parser.add_option('--bionic', help='Add bionic build.',
      action='store_true')
  parser.add_option('--tar', help='Force the tar step.',
      action='store_true')
  parser.add_option('--archive', help='Force the archive step.',
      action='store_true')
  parser.add_option('--gyp',
      help='Use gyp to build examples/libraries/Makefiles.',
      action='store_true')
  parser.add_option('--release', help='PPAPI release version.',
      dest='release', default=None)
  parser.add_option('--build-ports',
      help='Build naclport bundle.', action='store_true')
  parser.add_option('--build-app-engine',
      help='Build AppEngine demos.', action='store_true')
  parser.add_option('--experimental',
      help='build experimental examples and libraries', action='store_true',
      dest='build_experimental')
  parser.add_option('--skip-toolchain', help='Skip toolchain untar',
      action='store_true')
  parser.add_option('--mac-sdk',
      help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')

  # To setup bash completion for this command first install optcomplete
  # and then add this line to your .bashrc:
  #  complete -F _optcomplete build_sdk.py
  try:
    import optcomplete
    optcomplete.autocomplete(parser)
  except ImportError:
    pass

  global options
  options, args = parser.parse_args(args[1:])
  if args:
    parser.error("Unexpected arguments: %s" % str(args))

  generate_make.use_gyp = options.gyp
  if buildbot_common.IsSDKBuilder():
    options.archive = True
    options.build_ports = True
    options.build_app_engine = True
    options.tar = True

  toolchains = ['newlib', 'glibc', 'arm', 'pnacl', 'host']
  if options.bionic:
    toolchains.append('bionic')

  print 'Building: ' + ' '.join(toolchains)

  if options.archive and not options.tar:
    parser.error('Incompatible arguments with archive.')

  chrome_version = int(build_version.ChromeMajorVersion())
  chrome_revision = build_version.ChromeRevision()
  nacl_revision = build_version.NaClRevision()
  pepper_ver = str(chrome_version)
  pepper_old = str(chrome_version - 1)
  pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
  pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
  tarname = 'naclsdk_' + getos.GetPlatform() + '.tar.bz2'
  tarfile = os.path.join(OUT_DIR, tarname)

  if options.release:
    pepper_ver = options.release
  print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

  if 'NACL_SDK_ROOT' in os.environ:
    # We don't want the currently configured NACL_SDK_ROOT to have any effect
    # of the build.
    del os.environ['NACL_SDK_ROOT']

  if not options.skip_toolchain:
    BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
    BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
    BuildStepDownloadToolchains(toolchains)
    BuildStepUntarToolchains(pepperdir, toolchains)
    BuildStepBuildToolchains(pepperdir, toolchains)

  BuildStepUpdateHelpers(pepperdir, True)
  BuildStepUpdateUserProjects(pepperdir, toolchains,
                              options.build_experimental, True)

  BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision)

  # Ship with libraries prebuilt, so run that first.
  BuildStepBuildLibraries(pepperdir, 'src')
  GenerateNotice(pepperdir)

  # Verify the SDK contains what we expect.
  BuildStepVerifyFilelist(pepperdir)

  if options.tar:
    BuildStepTarBundle(pepper_ver, tarfile)

  if options.build_ports and getos.GetPlatform() == 'linux':
    ports_tarfile = os.path.join(OUT_DIR, 'naclports.tar.bz2')
    BuildStepSyncNaClPorts()
    BuildStepBuildNaClPorts(pepper_ver, pepperdir)
    if options.tar:
      BuildStepTarNaClPorts(pepper_ver, ports_tarfile)

  if options.build_app_engine and getos.GetPlatform() == 'linux':
    BuildStepBuildAppEngine(pepperdir, chrome_revision)

  # Archive on non-trybots.
  if options.archive:
    BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision,
                           tarfile)
    if options.build_ports and getos.GetPlatform() == 'linux':
      BuildStepArchiveBundle('naclports', pepper_ver, chrome_revision,
                             nacl_revision, ports_tarfile)
    BuildStepArchiveSDKTools()

  return 0
Example #50
0
    def __init__(self, argv=sys.argv):
	"""Initializes the Daemon."""
        Daemon.__init__(self, pidfile="/var/run/xbebroker.pid", umask=0007, name="xbebroker", user="******", group="root")
        self.server_queue = "xenbee.daemon.1"
        
        p = self.parser
        p.add_option(
            "-c", "--config", dest="config", type="string",
            help="config file to use, default: %default")
        p.add_option(
            "-u", "--uri", dest="uri", type="string",
            help="the uri through which I'am reachable")
        p.add_option(
            "--server", dest="server", type="string",
            help="the server to connect to")
        p.add_option(
            "-U", "--user-database", dest="user_db", type="string",
            help="list CNs that are allowed to use this server")
        p.add_option(
            "--pidfile", dest="pidfile", type="string",
            help="the pidfile to use")
        p.add_option(
            "-S", "--schema-dir", dest="schema_dir", type="string",
            help="path to a directory where schema definitions can be found.")
        p.add_option(
            "-l", "--logfile", dest="log_file", type="string",
            help="the logfile to use")
        p.add_option(
            "-L", "--logconf", dest="log_conf", type="string",
            help="configuration file for the logging module")
        p.add_option(
            "-D", "--no-daemonize", dest="daemonize", action="store_false",
            default=True,
            help="do not daemonize")
        p.add_option(
            "--key", dest="p_key", type="string",
            help="path to the private key")
        p.add_option(
            "--x509", dest="x509", type="string",
            help="path to the x509 certificate")
        p.add_option(
            "--ca-cert", dest="ca_cert", type="string",
            help="path to the CA x509 certificate")

        p.add_option(
            "--stomp-user", dest="stomp_user", type="string",
            help="username for the stomp connection")
        p.add_option(
            "--stomp-pass", dest="stomp_pass", type="string",
            help="password for the stomp connection")

        p.add_option(
            "--bid-timeout", dest="bid_timeout", type="int",
            help="Timeout for waiting for Auction BIDs")

        try:
            import optcomplete
        except ImportError:
            # no optcompletion available
            pass
        else:
            optcomplete.autocomplete(p)
Example #51
0
def main(args):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--qemu',
                        help='Add qemu for ARM.',
                        action='store_true')
    parser.add_argument('--tar',
                        help='Force the tar step.',
                        action='store_true')
    parser.add_argument('--archive',
                        help='Force the archive step.',
                        action='store_true')
    parser.add_argument('--release',
                        help='PPAPI release version.',
                        dest='release',
                        default=None)
    parser.add_argument('--build-app-engine',
                        help='Build AppEngine demos.',
                        action='store_true')
    parser.add_argument('--experimental',
                        help='build experimental examples and libraries',
                        action='store_true',
                        dest='build_experimental')
    parser.add_argument('--skip-toolchain',
                        help='Skip toolchain untar',
                        action='store_true')
    parser.add_argument('--no-clean',
                        dest='clean',
                        action='store_false',
                        help="Don't clean gn build directories")
    parser.add_argument(
        '--mac-sdk',
        help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.')
    parser.add_argument(
        '--no-arm-trusted',
        action='store_true',
        help='Disable building of ARM trusted components (sel_ldr, etc).')
    parser.add_argument('--no-use-sysroot',
                        action='store_true',
                        help='Disable building against sysroot.')

    # To setup bash completion for this command first install optcomplete
    # and then add this line to your .bashrc:
    #  complete -F _optcomplete build_sdk.py
    try:
        import optcomplete
        optcomplete.autocomplete(parser)
    except ImportError:
        pass

    global options
    options = parser.parse_args(args)

    buildbot_common.BuildStep('build_sdk')

    if buildbot_common.IsSDKBuilder():
        options.archive = True
        # TODO(binji): re-enable app_engine build when the linux builder stops
        # breaking when trying to git clone from github.
        # See http://crbug.com/412969.
        options.build_app_engine = False
        options.tar = True

    # NOTE: order matters here. This will be the order that is specified in the
    # Makefiles; the first toolchain will be the default.
    toolchains = ['pnacl', 'x86_glibc', 'arm_glibc', 'clang-newlib', 'host']

    print 'Building: ' + ' '.join(toolchains)
    platform = getos.GetPlatform()

    if options.archive and not options.tar:
        parser.error('Incompatible arguments with archive.')

    chrome_version = int(build_version.ChromeMajorVersion())
    chrome_revision = build_version.ChromeRevision()
    nacl_revision = build_version.NaClRevision()
    pepper_ver = str(chrome_version)
    pepper_old = str(chrome_version - 1)
    pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
    pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old)
    tarname = 'naclsdk_%s.tar.bz2' % platform
    tarfile = os.path.join(OUT_DIR, tarname)

    if options.release:
        pepper_ver = options.release
    print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision)

    if 'NACL_SDK_ROOT' in os.environ:
        # We don't want the currently configured NACL_SDK_ROOT to have any effect
        # of the build.
        del os.environ['NACL_SDK_ROOT']

    if platform == 'linux':
        # Linux-only: make sure the debian/stable sysroot image is installed
        install_script = os.path.join(SRC_DIR, 'build', 'linux',
                                      'sysroot_scripts', 'install-sysroot.py')

        buildbot_common.Run([sys.executable, install_script, '--arch=arm'])
        buildbot_common.Run([sys.executable, install_script, '--arch=i386'])
        buildbot_common.Run([sys.executable, install_script, '--arch=amd64'])

    if not options.skip_toolchain:
        BuildStepCleanPepperDirs(pepperdir, pepperdir_old)
        BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools'])
        BuildStepDownloadToolchains(toolchains)
        BuildStepUntarToolchains(pepperdir, toolchains)
        if platform == 'linux':
            buildbot_common.Move(
                os.path.join(pepperdir, 'toolchain', 'arm_trusted'),
                os.path.join(OUT_DIR, 'arm_trusted'))

    if platform == 'linux':
        # Linux-only: Copy arm libraries from the arm_trusted package.  These are
        # needed to be able to run sel_ldr_arm under qemu.
        arm_libs = [
            'lib/arm-linux-gnueabihf/librt.so.1',
            'lib/arm-linux-gnueabihf/libpthread.so.0',
            'lib/arm-linux-gnueabihf/libgcc_s.so.1',
            'lib/arm-linux-gnueabihf/libc.so.6',
            'lib/arm-linux-gnueabihf/ld-linux-armhf.so.3',
            'lib/arm-linux-gnueabihf/libm.so.6',
            'usr/lib/arm-linux-gnueabihf/libstdc++.so.6'
        ]
        arm_lib_dir = os.path.join(pepperdir, 'tools', 'lib', 'arm_trusted',
                                   'lib')
        buildbot_common.MakeDir(arm_lib_dir)
        for arm_lib in arm_libs:
            arm_lib = os.path.join(OUT_DIR, 'arm_trusted', arm_lib)
            buildbot_common.CopyFile(arm_lib, arm_lib_dir)
        buildbot_common.CopyFile(
            os.path.join(OUT_DIR, 'arm_trusted', 'qemu-arm'),
            os.path.join(pepperdir, 'tools'))

    BuildStepBuildToolchains(pepperdir, toolchains, not options.skip_toolchain,
                             options.clean)

    BuildStepUpdateHelpers(pepperdir, True)
    BuildStepUpdateUserProjects(pepperdir, toolchains,
                                options.build_experimental, True)

    BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision,
                           nacl_revision)

    # Ship with libraries prebuilt, so run that first.
    BuildStepBuildLibraries(pepperdir)
    GenerateNotice(pepperdir)

    # Verify the SDK contains what we expect.
    BuildStepVerifyFilelist(pepperdir)

    if options.tar:
        BuildStepTarBundle(pepper_ver, tarfile)

    if platform == 'linux':
        BuildStepBuildPNaClComponent(pepper_ver, chrome_revision)

    if options.build_app_engine and platform == 'linux':
        BuildStepBuildAppEngine(pepperdir, chrome_revision)

    if options.qemu:
        qemudir = os.path.join(NACL_DIR, 'toolchain', 'linux_arm-trusted')
        oshelpers.Copy(['-r', qemudir, pepperdir])

    # Archive the results on Google Cloud Storage.
    if options.archive:
        BuildStepArchiveBundle('build', pepper_ver, chrome_revision,
                               nacl_revision, tarfile)
        # Only archive sdk_tools/naclport/pnacl_component on linux.
        if platform == 'linux':
            BuildStepArchiveSDKTools()
            BuildStepArchivePNaClComponent(chrome_revision)

    return 0