示例#1
0
  def test_disabled_toolchain_arch(self):
    self.create_mock_package('bar', 'DISABLED_TOOLCHAIN=(glibc/x86_64)')

    pkg = source_package.create_package('bar',
                                        config=Configuration(toolchain='glibc'))
    with self.assertRaisesRegexp(error.DisabledError,
                                 'cannot be built with glibc for x86_64$'):
      pkg.check_installable()

    self.create_mock_package('bar2', 'DISABLED_TOOLCHAIN=(pnacl/arm)')

    pkg = source_package.create_package('bar2')
    pkg.check_installable()
示例#2
0
    def test_disabled_toolchain_arch(self):
        self.create_mock_package('bar', 'DISABLED_TOOLCHAIN=(glibc/x86_64)')

        pkg = source_package.create_package(
            'bar', config=Configuration(toolchain='glibc'))
        with self.assertRaisesRegexp(error.DisabledError,
                                     'cannot be built with glibc for x86_64$'):
            pkg.check_installable()

        self.create_mock_package('bar2', 'DISABLED_TOOLCHAIN=(pnacl/arm)')

        pkg = source_package.create_package('bar2')
        pkg.check_installable()
示例#3
0
    def test_min_sdk_version(self):
        self.create_mock_package('foo', 'MIN_SDK_VERSION=123')
        pkg = source_package.create_package('foo')
        pkg.check_buildable()

        self.create_mock_package('foo2', 'MIN_SDK_VERSION=121')
        pkg = source_package.create_package('foo2')
        pkg.check_buildable()

        self.create_mock_package('foo3', 'MIN_SDK_VERSION=124')
        pkg = source_package.create_package('foo3')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'requires SDK version 124 or above'):
            pkg.check_buildable()
示例#4
0
  def test_min_sdk_version(self):
    self.create_mock_package('foo', 'MIN_SDK_VERSION=123')
    pkg = source_package.create_package('foo')
    pkg.check_buildable()

    self.create_mock_package('foo2', 'MIN_SDK_VERSION=121')
    pkg = source_package.create_package('foo2')
    pkg.check_buildable()

    self.create_mock_package('foo3', 'MIN_SDK_VERSION=124')
    pkg = source_package.create_package('foo3')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'requires SDK version 124 or above'):
      pkg.check_buildable()
示例#5
0
    def test_disabled_toolchain(self):
        self.create_mock_package('bar', 'DISABLED_TOOLCHAIN=(pnacl)')

        pkg = source_package.create_package('bar')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'cannot be built with pnacl$'):
            pkg.check_installable()
示例#6
0
    def test_disabled_libc(self):
        self.create_mock_package('bar', 'DISABLED_LIBC=(newlib)')

        pkg = source_package.create_package('bar')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'cannot be built with newlib$'):
            pkg.check_installable()
示例#7
0
    def test_single_arch(self):
        self.create_mock_package('bar', 'ARCH=(arm)')

        pkg = source_package.create_package('bar')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'disabled for architecture: pnacl$'):
            pkg.check_installable()
示例#8
0
 def test_download(self, mock_verify, mock_download):
     self.create_mock_package('foo', 'URL=foo/bar.tar.gz\nSHA1=X123')
     pkg = source_package.create_package('foo')
     pkg.download()
     expected_filename = os.path.join(paths.CACHE_ROOT, 'bar.tar.gz')
     mock_download.assert_called_once_with(expected_filename, mock.ANY)
     mock_verify.assert_called_once_with(expected_filename, 'X123')
示例#9
0
  def test_disabled_toolchain(self):
    self.create_mock_package('bar', 'DISABLED_TOOLCHAIN=(pnacl)')

    pkg = source_package.create_package('bar')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'cannot be built with pnacl$'):
      pkg.check_installable()
示例#10
0
  def test_check_buildable(self):
    self.create_mock_package('foo', 'BUILD_OS=solaris')

    pkg = source_package.create_package('foo')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'can only be built on solaris$'):
      pkg.check_buildable()
示例#11
0
  def test_single_arch(self):
    self.create_mock_package('bar', 'ARCH=(arm)')

    pkg = source_package.create_package('bar')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'disabled for architecture: pnacl$'):
      pkg.check_installable()
示例#12
0
  def test_disabled_libc(self):
    self.create_mock_package('bar', 'DISABLED_LIBC=(newlib)')

    pkg = source_package.create_package('bar')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'cannot be built with newlib$'):
      pkg.check_installable()
示例#13
0
 def test_download(self, mock_verify, mock_download):
   self.create_mock_package('foo', 'URL=foo/bar.tar.gz\nSHA1=X123')
   pkg = source_package.create_package('foo')
   pkg.download()
   expected_filename = os.path.join(paths.CACHE_ROOT, 'bar.tar.gz')
   mock_download.assert_called_once_with(expected_filename, mock.ANY)
   mock_verify.assert_called_once_with(expected_filename, 'X123')
示例#14
0
    def test_check_buildable(self):
        self.create_mock_package('foo', 'BUILD_OS=solaris')

        pkg = source_package.create_package('foo')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'can only be built on solaris$'):
            pkg.check_buildable()
示例#15
0
  def test_check_installable_depends(self):
    self.create_mock_package('foo', 'DEPENDS=(bar)')
    self.create_mock_package('bar', 'DISABLED=1')

    pkg = source_package.create_package('foo')
    with self.assertRaisesRegexp(error.DisabledError,
                                 'bar: package is disabled$'):
      pkg.check_installable()
示例#16
0
  def test_disabled_arch(self):
    self.create_mock_package('bar', 'DISABLED_ARCH=(x86_64)')

    pkg = source_package.create_package(
        'bar', config=Configuration(toolchain='clang-newlib'))
    with self.assertRaisesRegexp(error.DisabledError,
                                 'disabled for architecture: x86_64'):
      pkg.check_installable()
示例#17
0
    def test_disabled_arch(self):
        self.create_mock_package('bar', 'DISABLED_ARCH=(x86_64)')

        pkg = source_package.create_package(
            'bar', config=Configuration(toolchain='clang-newlib'))
        with self.assertRaisesRegexp(error.DisabledError,
                                     'disabled for architecture: x86_64'):
            pkg.check_installable()
示例#18
0
    def test_check_installable_depends(self):
        self.create_mock_package('foo', 'DEPENDS=(bar)')
        self.create_mock_package('bar', 'DISABLED=1')

        pkg = source_package.create_package('foo')
        with self.assertRaisesRegexp(error.DisabledError,
                                     'bar: package is disabled$'):
            pkg.check_installable()
示例#19
0
 def test_download_missing_sha1(self, mock_download):
     self.create_mock_package('foo', 'URL=foo/bar')
     pkg = source_package.create_package('foo')
     with self.assertRaisesRegexp(error.Error, 'missing SHA1 attribute'):
         pkg.download()
示例#20
0
 def test_create_package_invalid(self):
     with self.assertRaisesRegexp(error.Error, 'Package not found: foo'):
         source_package.create_package('foo')
示例#21
0
 def test_create_package_invalid(self):
   with self.assertRaisesRegexp(error.Error, 'Package not found: foo'):
     source_package.create_package('foo')
示例#22
0
def run_main(args):
    base_commands = {
        'list': cmd_list,
        'info': cmd_info,
        'check': cmd_check,
    }

    pkg_commands = {
        'download': cmd_pkg_download,
        'uscan': cmd_pkg_uscan,
        'check': cmd_pkg_check,
        'build': cmd_pkg_build,
        'install': cmd_pkg_install,
        'clean': cmd_pkg_clean,
        'uninstall': cmd_pkg_uninstall,
        'contents': cmd_pkg_contents,
        'depends': cmd_pkg_list_deps,
        'updatepatch': cmd_pkg_update_patch,
        'extract': cmd_pkg_extract,
        'patch': cmd_pkg_patch
    }

    installed_pkg_commands = ['contents', 'uninstall']

    all_commands = dict(
        list(base_commands.items()) + list(pkg_commands.items()))

    epilog = "The following commands are available:\n"
    for name, function in all_commands.items():
        epilog += '  %-12s - %s\n' % (name, function.__doc__)

    parser = argparse.ArgumentParser(
        prog='webports',
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=epilog)
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbosity',
                        action='count',
                        default=0,
                        help='Output extra information.')
    parser.add_argument('-V',
                        '--verbose-build',
                        action='store_true',
                        help='Make builds verbose (e.g. pass V=1 to make')
    parser.add_argument('--skip-sdk-version-check',
                        action='store_true',
                        help="Disable the NaCl SDK version check on startup.")
    parser.add_argument('--all',
                        action='store_true',
                        help='Perform action on all known ports.')
    parser.add_argument('--color',
                        choices=('always', 'never', 'auto'),
                        help='Enabled color terminal output',
                        default='auto')
    parser.add_argument('-f',
                        '--force',
                        action='store_const',
                        const='build',
                        help='Force building specified targets, '
                        'even if timestamps would otherwise skip it.')
    parser.add_argument(
        '--from-source',
        action='store_true',
        help='Always build from source rather than downloading '
        'prebuilt packages.')
    parser.add_argument(
        '-F',
        '--force-all',
        action='store_const',
        const='all',
        dest='force',
        help='Force building target and all '
        'dependencies, even if timestamps would otherwise skip '
        'them.')
    parser.add_argument('--no-deps',
                        dest='build_deps',
                        action='store_false',
                        default=True,
                        help='Disable automatic building of dependencies.')
    parser.add_argument(
        '--ignore-disabled',
        action='store_true',
        help='Ignore attempts to build disabled packages.\n'
        'Normally attempts to build such packages will result\n'
        'in an error being returned.')
    parser.add_argument(
        '-t',
        '--toolchain',
        help='Set toolchain to use when building (newlib, glibc, '
        'or pnacl)')
    # use store_const rather than store_true since we want to default for
    # debug to be None (which then falls back to checking the NACL_DEBUG
    # environment variable.
    parser.add_argument(
        '-d',
        '--debug',
        action='store_const',
        const=True,
        help='Build debug configuration (release is the default)')
    parser.add_argument('-a',
                        '--arch',
                        help='Set architecture to use when building (x86_64,'
                        ' x86_32, arm, pnacl)')
    parser.add_argument('command', help="sub-command to run")
    parser.add_argument('pkg', nargs='*', help="package name or directory")
    args = parser.parse_args(args)

    if not args.verbosity and os.environ.get('VERBOSE') == '1':
        args.verbosity = 1

    util.set_log_level(util.LOG_INFO + args.verbosity)

    if args.verbose_build:
        os.environ['VERBOSE'] = '1'
    else:
        if 'VERBOSE' in os.environ:
            del os.environ['VERBOSE']
        if 'V' in os.environ:
            del os.environ['V']

    if args.skip_sdk_version_check:
        util.MIN_SDK_VERSION = -1

    if args.toolchain is not None:
        util.current_toolchain = args.toolchain
    else:
        util.current_toolchain = os.environ['TOOLCHAIN']

    util.check_sdk_root()
    config = configuration.Configuration(args.arch, args.toolchain, args.debug)
    util.color_mode = args.color
    if args.color == 'never':
        util.colorize.enabled = False
    elif args.color == 'always':
        util.colorize.enabled = True

    if args.command in base_commands:
        base_commands[args.command](config, args, args.pkg)
        return 0

    if args.command not in pkg_commands:
        parser.error("Unknown subcommand: '%s'\n"
                     'See --help for available commands.' % args.command)

    if len(args.pkg) and args.all:
        parser.error('Package name(s) and --all cannot be specified together')

    if args.pkg:
        package_names = args.pkg
    else:
        package_names = [os.getcwd()]

    def do_cmd(package):
        try:
            pkg_commands[args.command](package, args)
        except error.DisabledError as e:
            if args.ignore_disabled:
                util.log('webports: %s' % e)
            else:
                raise e

    if args.all:
        args.ignore_disabled = True
        if args.command == 'clean':
            clean_all(config)
        else:
            if args.command in installed_pkg_commands:
                package_iterator = installed_package.installed_package_iterator(
                    config)
            else:
                package_iterator = source_package.source_package_iterator()
            for p in package_iterator:
                do_cmd(p)
    else:
        for package_name in package_names:
            if args.command in installed_pkg_commands:
                p = installed_package.create_installed_package(
                    package_name, config)
            else:
                p = source_package.create_package(package_name, config)
            do_cmd(p)
示例#23
0
 def test_download_missing_sha1(self, mock_download):
   self.create_mock_package('foo', 'URL=foo/bar')
   pkg = source_package.create_package('foo')
   with self.assertRaisesRegexp(error.Error, 'missing SHA1 attribute'):
     pkg.download()
示例#24
0
def run_main(args):
  base_commands = {
      'list': cmd_list,
      'info': cmd_info,
      'check': cmd_check,
  }

  pkg_commands = {
      'download': cmd_pkg_download,
      'uscan': cmd_pkg_uscan,
      'check': cmd_pkg_check,
      'build': cmd_pkg_build,
      'install': cmd_pkg_install,
      'clean': cmd_pkg_clean,
      'uninstall': cmd_pkg_uninstall,
      'contents': cmd_pkg_contents,
      'depends': cmd_pkg_list_deps,
      'updatepatch': cmd_pkg_update_patch,
      'extract': cmd_pkg_extract,
      'patch': cmd_pkg_patch
  }

  installed_pkg_commands = ['contents', 'uninstall']

  all_commands = dict(base_commands.items() + pkg_commands.items())

  epilog = "The following commands are available:\n"
  for name, function in all_commands.iteritems():
    epilog += '  %-12s - %s\n' % (name, function.__doc__)

  parser = argparse.ArgumentParser(prog='webports', description=__doc__,
      formatter_class=argparse.RawDescriptionHelpFormatter, epilog=epilog)
  parser.add_argument('-v', '--verbose', dest='verbosity', action='count',
                      default=0, help='Output extra information.')
  parser.add_argument('-V', '--verbose-build', action='store_true',
                      help='Make builds verbose (e.g. pass V=1 to make')
  parser.add_argument('--skip-sdk-version-check', action='store_true',
                      help="Disable the NaCl SDK version check on startup.")
  parser.add_argument('--all', action='store_true',
                      help='Perform action on all known ports.')
  parser.add_argument('--color', choices=('always', 'never', 'auto'),
                      help='Enabled color terminal output', default='auto')
  parser.add_argument('-f', '--force', action='store_const', const='build',
                      help='Force building specified targets, '
                      'even if timestamps would otherwise skip it.')
  parser.add_argument('--from-source', action='store_true',
                      help='Always build from source rather than downloading '
                      'prebuilt packages.')
  parser.add_argument('-F', '--force-all', action='store_const', const='all',
                      dest='force', help='Force building target and all '
                      'dependencies, even if timestamps would otherwise skip '
                      'them.')
  parser.add_argument('--no-deps', dest='build_deps', action='store_false',
                      default=True,
                      help='Disable automatic building of dependencies.')
  parser.add_argument('--ignore-disabled', action='store_true',
                      help='Ignore attempts to build disabled packages.\n'
                      'Normally attempts to build such packages will result\n'
                      'in an error being returned.')
  parser.add_argument('-t', '--toolchain',
                      help='Set toolchain to use when building (newlib, glibc, '
                      'or pnacl)')
  # use store_const rather than store_true since we want to default for
  # debug to be None (which then falls back to checking the NACL_DEBUG
  # environment variable.
  parser.add_argument('-d', '--debug', action='store_const', const=True,
                      help='Build debug configuration (release is the default)')
  parser.add_argument('-a', '--arch',
                      help='Set architecture to use when building (x86_64,'
                      ' x86_32, arm, pnacl)')
  parser.add_argument('command', help="sub-command to run")
  parser.add_argument('pkg', nargs='*', help="package name or directory")
  args = parser.parse_args(args)

  if not args.verbosity and os.environ.get('VERBOSE') == '1':
    args.verbosity = 1

  util.set_log_level(util.LOG_INFO + args.verbosity)

  if args.verbose_build:
    os.environ['VERBOSE'] = '1'
  else:
    if 'VERBOSE' in os.environ:
      del os.environ['VERBOSE']
    if 'V' in os.environ:
      del os.environ['V']

  if args.skip_sdk_version_check:
    util.MIN_SDK_VERSION = -1

  util.check_sdk_root()
  config = configuration.Configuration(args.arch, args.toolchain, args.debug)
  util.color_mode = args.color
  if args.color == 'never':
    util.colorize.enabled = False
  elif args.color == 'always':
    util.colorize.enabled = True

  if args.command in base_commands:
    base_commands[args.command](config, args, args.pkg)
    return 0

  if args.command not in pkg_commands:
    parser.error("Unknown subcommand: '%s'\n"
                 'See --help for available commands.' % args.command)

  if len(args.pkg) and args.all:
    parser.error('Package name(s) and --all cannot be specified together')

  if args.pkg:
    package_names = args.pkg
  else:
    package_names = [os.getcwd()]

  def do_cmd(package):
    try:
      pkg_commands[args.command](package, args)
    except error.DisabledError as e:
      if args.ignore_disabled:
        util.log('webports: %s' % e)
      else:
        raise e

  if args.all:
    args.ignore_disabled = True
    if args.command == 'clean':
      clean_all(config)
    else:
      if args.command in installed_pkg_commands:
        package_iterator = installed_package.installed_package_iterator(config)
      else:
        package_iterator = source_package.source_package_iterator()
      for p in package_iterator:
        do_cmd(p)
  else:
    for package_name in package_names:
      if args.command in installed_pkg_commands:
        p = installed_package.create_installed_package(package_name, config)
      else:
        p = source_package.create_package(package_name, config)
      do_cmd(p)