Beispiel #1
0
 def testDefaultArch(self):
     # We default to x86_64 except in the special case where the build
     # machine is i686 hardware, in which case we default to i686.
     with patch('platform.machine', Mock(return_value='i686')):
         self.assertEqual(Configuration().arch, 'i686')
     with patch('platform.machine', Mock(return_value='dummy')):
         self.assertEqual(Configuration().arch, 'x86_64')
Beispiel #2
0
 def testParsingValid(self):
     index = package_index.PackageIndex('dummy_file', test_index)
     arm_config = Configuration('arm', 'newlib', False)
     i686_config = Configuration('i686', 'newlib', False)
     self.assertEqual(len(index.packages), 2)
     self.assertTrue(index.Contains('agg-demo', arm_config))
     self.assertTrue(index.Contains('agg-demo', i686_config))
Beispiel #3
0
    def testContains(self):
        # Create an empty package index and add a single entry to it
        index = package_index.PackageIndex('dummy_file', '')
        config_debug = Configuration('arm', 'newlib', True)
        config_release = Configuration('arm', 'newlib', False)
        self.assertFalse(index.Contains('foo', config_release))
        index.packages[('foo', config_release)] = {
            'NAME': 'dummy',
            'BUILD_SDK_VERSION': 123
        }
        with patch('naclports.util.GetSDKVersion') as mock_version:
            # Setting the mock SDK version to 123 should mean that the
            # index contains the 'foo' package and it is installable'
            mock_version.return_value = 123
            self.assertTrue(index.Contains('foo', config_release))
            self.assertTrue(index.Installable('foo', config_release))

            # Setting the mock SDK version to some other version should
            # mean the index contains that package but it is not installable.
            mock_version.return_value = 124
            self.assertTrue(index.Contains('foo', config_release))
            self.assertFalse(index.Installable('foo', config_release))

            self.assertFalse(index.Contains('foo', config_debug))
            self.assertFalse(index.Contains('bar', config_release))
Beispiel #4
0
    def testGetInstallRoot(self):
        expected = '/sdk/root/toolchain/linux_x86_newlib/x86_64-nacl/usr'
        self.assertEqual(util.GetInstallRoot(Configuration()), expected)

        expected = '/sdk/root/toolchain/linux_pnacl/le32-nacl/usr'
        self.assertEqual(util.GetInstallRoot(Configuration('pnacl')), expected)

        expected = '/emscripten/root/system/local'
        self.assertEqual(util.GetInstallRoot(Configuration('emscripten')),
                         expected)

        expected = '/sdk/root/toolchain/linux_pnacl/x86_64-nacl/usr'
        self.assertEqual(
            util.GetInstallRoot(Configuration(toolchain='clang-newlib')),
            expected)
Beispiel #5
0
 def testDefaults(self):
     config = Configuration()
     self.assertEqual(config.toolchain, 'newlib')
     self.assertEqual(config.arch, 'x86_64')
     self.assertEqual(config.debug, False)
     self.assertEqual(config.config_name, 'release')
     self.assertEqual(config.libc, 'newlib')
Beispiel #6
0
  def testDisabledArch(self):
    self.CreateTestPackage('bar', 'DISABLED_ARCH=(x86_64)')

    pkg = source_package.CreatePackage(
        'bar', config=Configuration(toolchain='clang-newlib'))
    with self.assertRaisesRegexp(error.DisabledError,
                                 'disabled for architecture: x86_64'):
      pkg.CheckInstallable()
Beispiel #7
0
  def testInfoCommand(self):
    config = Configuration()
    options = Mock()
    file_mock = common.MockFileObject('FOO=bar\n')

    with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
      with patch('__builtin__.open', Mock(return_value=file_mock), create=True):
        naclports.__main__.CmdInfo(config, options, ['foo'])
        self.assertRegexpMatches(stdout.getvalue(), "FOO=bar")
Beispiel #8
0
 def testListCommandVerbose(self):
   config = Configuration()
   pkg = Mock(NAME='foo', VERSION='0.1')
   with patch('naclports.installed_package.InstalledPackageIterator',
              Mock(return_value=[pkg])):
     with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
       options = Mock(verbosity=0, all=False)
       naclports.__main__.CmdList(config, options, [])
       lines = stdout.getvalue().splitlines()
       self.assertRegexpMatches(lines[0], "^foo$")
       self.assertEqual(len(lines), 1)
Beispiel #9
0
  def testDisabledToolchainArch(self):
    self.CreateTestPackage('bar', 'DISABLED_TOOLCHAIN=(glibc/x86_64)')

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

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

    pkg = source_package.CreatePackage('bar2')
    pkg.CheckInstallable()
Beispiel #10
0
    def __init__(self, pkg_root, config=None):
        if config is None:
            config = Configuration()
        for key in naclports.VALID_KEYS:
            setattr(self, key, None)
        self.config = config
        self.DEPENDS = []
        self.CONFLICTS = []

        self.root = os.path.abspath(pkg_root)
        self.info = os.path.join(self.root, 'pkg_info')
        if not os.path.isdir(self.root) or not os.path.exists(self.info):
            raise Error('Invalid package folder: %s' % pkg_root)

        # Parse pkg_info file
        info = naclports.ParsePkgInfoFile(self.info)

        # Set attributres based on pkg_info setttings.
        for key, value in info.items():
            setattr(self, key, value)

        if '_' in self.NAME:
            raise Error('%s: package NAME cannot contain underscores' %
                        self.info)
        if self.NAME != self.NAME.lower():
            raise Error(
                '%s: package NAME cannot contain uppercase characters' %
                self.info)
        if '_' in self.VERSION:
            raise Error('%s: package VERSION cannot contain underscores' %
                        self.info)
        if self.NAME != os.path.basename(self.root):
            raise Error('%s: package NAME must match directory name' %
                        self.info)
        if self.DISABLED_ARCH is not None and self.ARCH is not None:
            raise Error('%s: contains both ARCH and DISABLED_ARCH' % self.info)
        if self.DISABLED_LIBC is not None and self.LIBC is not None:
            raise Error('%s: contains both LIBC and DISABLED_LIBC' % self.info)
Beispiel #11
0
 def testInvalidArch(self):
     expected_error = 'Invalid arch: not_arch'
     with self.assertRaisesRegexp(error.Error, expected_error):
         Configuration('not_arch')
Beispiel #12
0
 def testConfigEquality(self):
     config1 = Configuration('arm', 'newlib', True)
     config2 = Configuration('arm', 'newlib', True)
     config3 = Configuration('arm', 'newlib', False)
     self.assertEqual(config1, config2)
     self.assertNotEqual(config1, config3)
Beispiel #13
0
 def testConfigStringForm(self):
     config = Configuration('arm', 'newlib', True)
     self.assertEqual(str(config), 'arm/newlib/debug')
     self.assertRegexpMatches(repr(config), '<Configuration .*>')
Beispiel #14
0
    def testGetInstallRoot(self):
        expected = '/sdk/root/toolchain/linux_x86_newlib/x86_64-nacl/usr'
        self.assertEqual(util.GetInstallRoot(Configuration()), expected)

        expected = '/sdk/root/toolchain/linux_pnacl/usr/local'
        self.assertEqual(util.GetInstallRoot(Configuration('pnacl')), expected)
Beispiel #15
0
 def testCleanAll(self, mock_rmtree):
   config = Configuration()
   naclports.__main__.CleanAll(config)
   mock_rmtree.assert_any_call('/package/install/path')
Beispiel #16
0
def run_main(args):
  usage = 'Usage: %prog [options] <command> [<package_dir>]'
  parser = optparse.OptionParser(prog='naclports', description=__doc__,
                                 usage=usage)
  parser.add_option('-v', '--verbose', action='store_true',
                    help='Output extra information.')
  parser.add_option('-V', '--verbose-build', action='store_true',
                    help='Make the build itself version (e.g. pass V=1 to make')
  parser.add_option('--all', action='store_true',
                    help='Perform action on all known ports.')
  parser.add_option('-f', '--force', action='store_const', const='build',
                    help='Force building specified targets, '
                    'even if timestamps would otherwise skip it.')
  parser.add_option('--from-source', action='store_true',
                    help='Always build from source rather than downloading '
                    'prebuilt packages.')
  parser.add_option('-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_option('--no-deps', dest='build_deps', action='store_false',
                    default=True,
                    help='Disable automatic building of dependencies.')
  parser.add_option('--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_option('--toolchain',
                    help='Set toolchain to use when building (newlib, glibc, or'
                    ' pnacl)"')
  parser.add_option('--debug',
                    help='Build debug configuration (release is the default)')
  parser.add_option('--arch',
                    help='Set architecture to use when building (x86_64,'
                    ' x86_32, arm, pnacl)')
  options, args = parser.parse_args(args)
  if not args:
    parser.error('You must specify a sub-command. See --help.')

  command = args[0]
  args = args[1:]

  lock_file = GetLock()

  naclports.verbose = options.verbose or os.environ.get('VERBOSE') == '1'
  if options.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 not NACL_SDK_ROOT:
    raise Error('$NACL_SDK_ROOT not set')

  if not os.path.isdir(NACL_SDK_ROOT):
    raise Error('$NACL_SDK_ROOT does not exist: %s' % NACL_SDK_ROOT)

  sentinel = os.path.join(NACL_SDK_ROOT, 'tools', 'getos.py')
  if not os.path.exists(sentinel):
    raise Error("$NACL_SDK_ROOT (%s) doesn't look right. "
                "Couldn't find sentinel file (%s)" % (NACL_SDK_ROOT, sentinel))

  config = Configuration(options.arch, options.toolchain, options.debug)

  base_commands = {
    'list': CmdList,
    'info': CmdInfo,
    'contents': CmdContents
  }

  pkg_commands = {
    'download': CmdPkgDownload,
    'check': CmdPkgCheck,
    'build': CmdPkgBuild,
    'uninstall': CmdPkgUninstall,
    'install': CmdPkgInstall,
    'verify': CmdPkgVerify,
    'clean': CmdPkgClean,
  }

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

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

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

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

  def DoCmd(package):
    try:
      pkg_commands[command](package, options)
    except DisabledError as e:
      if options.ignore_disabled:
        naclports.Log('naclports: %s' % e)
      else:
        raise e

  def rmtree(path):
    naclports.Log('removing %s' % path)
    if os.path.exists(path):
      shutil.rmtree(path)

  if options.all:
    options.ignore_disabled = True
    if command == 'clean':
      rmtree(naclports.STAMP_DIR)
      rmtree(naclports.BUILD_ROOT)
      rmtree(naclports.PUBLISH_ROOT)
      rmtree(naclports.package.PACKAGES_ROOT)
      rmtree(naclports.GetInstallStampRoot(config))
      rmtree(naclports.GetInstallRoot(config))
    else:
      for p in PackageIterator():
        if not p.DISABLED:
          DoCmd(p)
  else:
    for package_dir in package_dirs:
      p = naclports.package.CreatePackage(package_dir, config)
      DoCmd(p)
Beispiel #17
0
 def testConfigString(self):
   config = Configuration('arm', 'newlib', True)
   self.assertEqual(str(config), 'arm/newlib/debug')
Beispiel #18
0
 def testDownload(self, download_file_mock):
     index = package_index.PackageIndex('dummy_file', test_index)
     arm_config = Configuration('arm', 'newlib', False)
     index.Download('agg-demo', arm_config)
     self.assertEqual(download_file_mock.call_count, 1)
Beispiel #19
0
    def testEnvironmentVariables(self):
        with patch.dict('os.environ', {'NACL_ARCH': 'arm'}):
            self.assertEqual(Configuration().arch, 'arm')

        with patch.dict('os.environ', {'NACL_DEBUG': '1'}):
            self.assertEqual(Configuration().debug, True)
Beispiel #20
0
 def testMainCleanAll(self, clean_all_mock):
   naclports.__main__.RunMain(['clean', '--all'])
   clean_all_mock.assert_called_once_with(Configuration())
Beispiel #21
0
 def testDefaultToolchain(self):
     self.assertEqual(Configuration(arch='pnacl').toolchain, 'pnacl')
     self.assertEqual(Configuration(arch='arm').libc, 'newlib')
Beispiel #22
0
 def testDefaultLibc(self):
     self.assertEqual(Configuration(toolchain='pnacl').libc, 'newlib')
     self.assertEqual(Configuration(toolchain='newlib').libc, 'newlib')
     self.assertEqual(Configuration(toolchain='glibc').libc, 'glibc')
     self.assertEqual(Configuration(toolchain='bionic').libc, 'bionic')
Beispiel #23
0
 def testGetToolchainRoot(self):
     expected = '/sdk/root/toolchain/linux_x86_newlib/x86_64-nacl'
     self.assertEqual(util.GetToolchainRoot(Configuration()), expected)