Ejemplo n.º 1
0
    def test_namespace_effective(self):
        self.create_file('src/thrift/com/foo/one.thrift',
                         contents=dedent("""
    namespace py foo.bar

    struct One {}
    """))
        one = self.make_target(spec='src/thrift/com/foo:one',
                               target_type=PythonThriftLibrary,
                               sources=['one.thrift'])
        apache_thrift_gen, synthetic_target_one = self.generate_single_thrift_target(
            one)

        self.create_file('src/thrift2/com/foo/two.thrift',
                         contents=dedent("""
    namespace py foo.baz

    struct Two {}
    """))
        two = self.make_target(spec='src/thrift2/com/foo:two',
                               target_type=PythonThriftLibrary,
                               sources=['two.thrift'])
        _, synthetic_target_two = self.generate_single_thrift_target(two)

        # Confirm separate PYTHONPATH entries, which we need to test namespace packages.
        self.assertNotEqual(synthetic_target_one.target_base,
                            synthetic_target_two.target_base)

        targets = (synthetic_target_one, synthetic_target_two)

        python_repos = global_subsystem_instance(PythonRepos)
        python_setup = global_subsystem_instance(PythonSetup)
        interpreter_cache = PythonInterpreterCache(python_setup, python_repos)
        interpreter = interpreter_cache.select_interpreter_for_targets(targets)

        pythonpath = [
            os.path.join(get_buildroot(), t.target_base) for t in targets
        ]
        for dist in resolve(
            ['thrift=={}'.format(self.get_thrift_version(apache_thrift_gen))],
                interpreter=interpreter,
                context=python_repos.get_network_context(),
                fetchers=python_repos.get_fetchers()):
            pythonpath.append(dist.location)

        process = subprocess.Popen([
            interpreter.binary, '-c',
            'from foo.bar.ttypes import One; from foo.baz.ttypes import Two'
        ],
                                   env={
                                       'PYTHONPATH':
                                       os.pathsep.join(pythonpath)
                                   },
                                   stderr=subprocess.PIPE)
        _, stderr = process.communicate()
        self.assertEqual(0, process.returncode, stderr)
Ejemplo n.º 2
0
  def test_namespace_effective(self):
    self.create_file('src/thrift/com/foo/one.thrift', contents=dedent("""
    namespace py foo.bar

    struct One {}
    """))
    one = self.make_target(spec='src/thrift/com/foo:one',
                           target_type=PythonThriftLibrary,
                           sources=['one.thrift'])
    apache_thrift_gen, synthetic_target_one = self.generate_single_thrift_target(one)

    self.create_file('src/thrift2/com/foo/two.thrift', contents=dedent("""
    namespace py foo.baz

    struct Two {}
    """))
    two = self.make_target(spec='src/thrift2/com/foo:two',
                           target_type=PythonThriftLibrary,
                           sources=['two.thrift'])
    _, synthetic_target_two = self.generate_single_thrift_target(two)

    # Confirm separate PYTHONPATH entries, which we need to test namespace packages.
    self.assertNotEqual(synthetic_target_one.target_base, synthetic_target_two.target_base)

    targets = (synthetic_target_one, synthetic_target_two)

    python_repos = global_subsystem_instance(PythonRepos)
    python_setup = global_subsystem_instance(PythonSetup)
    interpreter_cache = PythonInterpreterCache(python_setup, python_repos)
    interpreter = interpreter_cache.select_interpreter_for_targets(targets)

    # We need setuptools to import namespace packages (via pkg_resources), so we prime the
    # PYTHONPATH with interpreter extras, which Pants always populates with setuptools and wheel.
    # TODO(John Sirois): We really should be emitting setuptools in a
    # `synthetic_target_extra_dependencies` override in `ApacheThriftPyGen`:
    #   https://github.com/pantsbuild/pants/issues/5975
    pythonpath = interpreter.extras.values()
    pythonpath.extend(os.path.join(get_buildroot(), t.target_base) for t in targets)
    for dist in resolve(['thrift=={}'.format(self.get_thrift_version(apache_thrift_gen))],
                        interpreter=interpreter,
                        context=python_repos.get_network_context(),
                        fetchers=python_repos.get_fetchers()):
      pythonpath.append(dist.location)

    process = subprocess.Popen([interpreter.binary,
                                '-c',
                                'from foo.bar.ttypes import One; from foo.baz.ttypes import Two'],
                               env={'PYTHONPATH': os.pathsep.join(pythonpath)},
                               stderr=subprocess.PIPE)
    _, stderr = process.communicate()
    self.assertEqual(0, process.returncode, stderr)
Ejemplo n.º 3
0
  def test_namespace_effective(self):
    self.create_file('src/thrift/com/foo/one.thrift', contents=dedent("""
    namespace py foo.bar

    struct One {}
    """))
    one = self.make_target(spec='src/thrift/com/foo:one',
                           target_type=PythonThriftLibrary,
                           sources=['one.thrift'])
    apache_thrift_gen, synthetic_target_one = self.generate_single_thrift_target(one)

    self.create_file('src/thrift2/com/foo/two.thrift', contents=dedent("""
    namespace py foo.baz

    struct Two {}
    """))
    two = self.make_target(spec='src/thrift2/com/foo:two',
                           target_type=PythonThriftLibrary,
                           sources=['two.thrift'])
    _, synthetic_target_two = self.generate_single_thrift_target(two)

    # Confirm separate PYTHONPATH entries, which we need to test namespace packages.
    self.assertNotEqual(synthetic_target_one.target_base, synthetic_target_two.target_base)

    targets = (synthetic_target_one, synthetic_target_two)

    python_repos = global_subsystem_instance(PythonRepos)
    python_setup = global_subsystem_instance(PythonSetup)
    interpreter_cache = PythonInterpreterCache(python_setup, python_repos)
    interpreter = interpreter_cache.select_interpreter_for_targets(targets)

    # We need setuptools to import namespace packages (via pkg_resources), so we prime the
    # PYTHONPATH with interpreter extras, which Pants always populates with setuptools and wheel.
    # TODO(John Sirois): We really should be emitting setuptools in a
    # `synthetic_target_extra_dependencies` override in `ApacheThriftPyGen`:
    #   https://github.com/pantsbuild/pants/issues/5975
    pythonpath = interpreter.extras.values()
    pythonpath.extend(os.path.join(get_buildroot(), t.target_base) for t in targets)
    for dist in resolve(['thrift=={}'.format(self.get_thrift_version(apache_thrift_gen))],
                        interpreter=interpreter,
                        context=python_repos.get_network_context(),
                        fetchers=python_repos.get_fetchers()):
      pythonpath.append(dist.location)

    process = subprocess.Popen([interpreter.binary,
                                '-c',
                                'from foo.bar.ttypes import One; from foo.baz.ttypes import Two'],
                               env={'PYTHONPATH': os.pathsep.join(pythonpath)},
                               stderr=subprocess.PIPE)
    _, stderr = process.communicate()
    self.assertEqual(0, process.returncode, stderr)
Ejemplo n.º 4
0
    def test_gcc_version(self):
        scheduler = self._sched()

        platform = Platform.create()

        gcc_subsystem = global_subsystem_instance(GCC)
        gcc_version = gcc_subsystem.version()

        gcc_c_compiler = self.execute_expecting_one_result(
            scheduler, GCCCCompiler, self.toolchain).value
        gcc = gcc_c_compiler.c_compiler
        gcc_version_out = self._invoke_capturing_output(
            [gcc.exe_filename, '--version'],
            env=gcc.get_invocation_environment_dict(platform))

        gcc_version_regex = re.compile('^gcc.*{}$'.format(
            re.escape(gcc_version)),
                                       flags=re.MULTILINE)
        self.assertIsNotNone(gcc_version_regex.search(gcc_version_out))

        gcc_cpp_compiler = self.execute_expecting_one_result(
            scheduler, GCCCppCompiler, self.toolchain).value
        gpp = gcc_cpp_compiler.cpp_compiler
        gpp_version_out = self._invoke_capturing_output(
            [gpp.exe_filename, '--version'],
            env=gpp.get_invocation_environment_dict(platform))

        gpp_version_regex = re.compile(r'^g\+\+.*{}$'.format(
            re.escape(gcc_version)),
                                       flags=re.MULTILINE)
        self.assertIsNotNone(gpp_version_regex.search(gpp_version_out))
Ejemplo n.º 5
0
    def test_clang_version(self):
        scheduler = self._sched()

        platform = Platform.create()

        llvm_subsystem = global_subsystem_instance(LLVM)
        llvm_version = llvm_subsystem.version()
        llvm_version_regex = re.compile('^clang version {}'.format(
            re.escape(llvm_version)),
                                        flags=re.MULTILINE)

        llvm_c_compiler = self.execute_expecting_one_result(
            scheduler, LLVMCCompiler, self.toolchain).value
        clang = llvm_c_compiler.c_compiler
        llvm_version_out = self._invoke_capturing_output(
            [clang.exe_filename, '--version'],
            env=clang.get_invocation_environment_dict(platform))

        self.assertIsNotNone(llvm_version_regex.search(llvm_version_out))

        llvm_cpp_compiler = self.execute_expecting_one_result(
            scheduler, LLVMCppCompiler, self.toolchain).value
        clangpp = llvm_cpp_compiler.cpp_compiler
        gpp_version_out = self._invoke_capturing_output(
            [clangpp.exe_filename, '--version'],
            env=clangpp.get_invocation_environment_dict(platform))

        self.assertIsNotNone(llvm_version_regex.search(gpp_version_out))
Ejemplo n.º 6
0
 def test_ivy_classifiers(self):
     with self.temporary_workdir() as workdir:
         test_target = 'testprojects/tests/java/org/pantsbuild/testproject/ivyclassifier:ivyclassifier'
         json_data = self.run_export(test_target, workdir, load_libs=True)
         ivy_subsystem = global_subsystem_instance(IvySubsystem)
         ivy_cache_dir = ivy_subsystem.get_options().cache_dir
         avro_lib_info = json_data.get('libraries').get(
             'org.apache.avro:avro:1.7.7')
         self.assertIsNotNone(avro_lib_info)
         self.assertEquals(
             avro_lib_info.get('default'),
             os.path.join(ivy_cache_dir,
                          'org.apache.avro/avro/jars/avro-1.7.7.jar'))
         self.assertEquals(
             avro_lib_info.get('tests'),
             os.path.join(ivy_cache_dir,
                          'org.apache.avro/avro/jars/avro-1.7.7-tests.jar'))
         self.assertEquals(
             avro_lib_info.get('javadoc'),
             os.path.join(
                 ivy_cache_dir,
                 'org.apache.avro/avro/javadocs/avro-1.7.7-javadoc.jar'))
         self.assertEquals(
             avro_lib_info.get('sources'),
             os.path.join(
                 ivy_cache_dir,
                 'org.apache.avro/avro/sources/avro-1.7.7-sources.jar'))
Ejemplo n.º 7
0
 def _jar_dependency_management(self, **flags):
     Subsystem.reset()
     options = {
         JarDependencyManagement.options_scope: flags,
     }
     return global_subsystem_instance(JarDependencyManagement,
                                      options=options)
Ejemplo n.º 8
0
 def _init_manager(self, **jar_dependency_management_options):
     options = {
         JarDependencyManagement.options_scope:
         jar_dependency_management_options
     }
     return global_subsystem_instance(JarDependencyManagement,
                                      options=options)
Ejemplo n.º 9
0
  def setUp(self):
    super(TestNativeToolchain, self).setUp()

    init_subsystems([LibcDev, NativeToolchain], options={
      'libc': {
        'enable_libc_search': True,
      },
    })

    self.platform = Platform.create()
    self.toolchain = global_subsystem_instance(NativeToolchain)
    self.rules = native_backend_rules()

    gcc_subsystem = global_subsystem_instance(GCC)
    self.gcc_version = gcc_subsystem.version()
    llvm_subsystem = global_subsystem_instance(LLVM)
    self.llvm_version = llvm_subsystem.version()
Ejemplo n.º 10
0
  def execute_junit_runner(self, content, create_some_resources=True, **kwargs):
    # Create the temporary base test directory
    test_rel_path = 'tests/java/org/pantsbuild/foo'
    test_abs_path = self.create_dir(test_rel_path)

    # Generate the temporary java test source code.
    test_java_file_rel_path = os.path.join(test_rel_path, 'FooTest.java')
    test_java_file_abs_path = self.create_file(test_java_file_rel_path, content)

    # Create the temporary classes directory under work dir
    test_classes_abs_path = self.create_workdir_dir(test_rel_path)

    # Invoke ivy to resolve classpath for junit.
    classpath_file_abs_path = os.path.join(test_abs_path, 'junit.classpath')
    ivy_subsystem = global_subsystem_instance(IvySubsystem)
    distribution = DistributionLocator.cached(jdk=True)
    ivy = Bootstrapper(ivy_subsystem=ivy_subsystem).ivy()
    ivy.execute(args=['-cachepath', classpath_file_abs_path,
                      '-dependency', 'junit', 'junit-dep', '4.10'],
                executor=SubprocessExecutor(distribution=distribution))

    with open(classpath_file_abs_path) as fp:
      classpath = fp.read()

    # Now directly invoking javac to compile the test java code into java class
    # so later we can inject the class into products mapping for JUnitRun to execute
    # the test on.
    javac = distribution.binary('javac')
    subprocess.check_call(
      [javac, '-d', test_classes_abs_path, '-cp', classpath, test_java_file_abs_path])

    # If a target_name is specified create a target with it, otherwise create a java_tests target.
    if 'target_name' in kwargs:
      target = self.target(kwargs['target_name'])
    else:
      target = self.create_library(test_rel_path, 'java_tests', 'foo_test', ['FooTest.java'])

    target_roots = []
    if create_some_resources:
      # Create a synthetic resource target.
      target_roots.append(self.make_target('some_resources', Resources))
    target_roots.append(target)

    # Set the context with the two targets, one java_tests target and
    # one synthetic resources target.
    # The synthetic resources target is to make sure we won't regress
    # in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
    # in that bug, the resources target must be the first one in the list.
    context = self.context(target_roots=target_roots)

    # Before we run the task, we need to inject the "runtime_classpath" with
    # the compiled test java classes that JUnitRun will know which test
    # classes to execute. In a normal run, this "runtime_classpath" will be
    # populated by java compilation step.
    self.populate_runtime_classpath(context=context, classpath=[test_classes_abs_path])

    # Finally execute the task.
    self.execute(context)
  def test_namespace_effective(self):
    self.create_file('src/thrift/com/foo/one.thrift', contents=dedent("""
    namespace py foo.bar

    struct One {}
    """))
    one = self.make_target(spec='src/thrift/com/foo:one',
                           target_type=PythonThriftLibrary,
                           sources=['one.thrift'])
    apache_thrift_gen, synthetic_target_one = self.generate_single_thrift_target(one)

    self.create_file('src/thrift2/com/foo/two.thrift', contents=dedent("""
    namespace py foo.baz

    struct Two {}
    """))
    two = self.make_target(spec='src/thrift2/com/foo:two',
                           target_type=PythonThriftLibrary,
                           sources=['two.thrift'])
    _, synthetic_target_two = self.generate_single_thrift_target(two)

    # Confirm separate PYTHONPATH entries, which we need to test namespace packages.
    self.assertNotEqual(synthetic_target_one.target_base, synthetic_target_two.target_base)

    targets = (synthetic_target_one, synthetic_target_two)

    python_repos = global_subsystem_instance(PythonRepos)
    python_setup = global_subsystem_instance(PythonSetup)
    interpreter_cache = PythonInterpreterCache(python_setup, python_repos)
    interpreter = interpreter_cache.select_interpreter_for_targets(targets)

    pythonpath = [os.path.join(get_buildroot(), t.target_base) for t in targets]
    for dist in resolve(['thrift=={}'.format(self.get_thrift_version(apache_thrift_gen))],
                        interpreter=interpreter,
                        context=python_repos.get_network_context(),
                        fetchers=python_repos.get_fetchers()):
      pythonpath.append(dist.location)

    process = subprocess.Popen([interpreter.binary,
                                '-c',
                                'from foo.bar.ttypes import One; from foo.baz.ttypes import Two'],
                               env={'PYTHONPATH': os.pathsep.join(pythonpath)},
                               stderr=subprocess.PIPE)
    _, stderr = process.communicate()
    self.assertEqual(0, process.returncode, stderr)
Ejemplo n.º 12
0
    def setUp(self):
        super(TestNativeToolchain, self).setUp()

        init_subsystems([LibcDev, NativeToolchain],
                        options={
                            'libc': {
                                'enable_libc_search': True,
                            },
                        })

        self.platform = Platform.create()
        self.toolchain = global_subsystem_instance(NativeToolchain)
        self.rules = native_backend_rules()

        gcc_subsystem = global_subsystem_instance(GCC)
        self.gcc_version = gcc_subsystem.version()
        llvm_subsystem = global_subsystem_instance(LLVM)
        self.llvm_version = llvm_subsystem.version()
Ejemplo n.º 13
0
 def test_parse_proxy_string(self):
   ivy_subsystem = global_subsystem_instance(IvySubsystem)
   self.assertEquals(('example.com', 1234),
                     ivy_subsystem._parse_proxy_string('http://example.com:1234'))
   self.assertEquals(('secure-example.com', 999),
                     ivy_subsystem._parse_proxy_string('http://secure-example.com:999'))
   # trailing slash is ok
   self.assertEquals(('example.com', 1234),
                     ivy_subsystem._parse_proxy_string('http://example.com:1234/'))
Ejemplo n.º 14
0
 def test_parse_proxy_string(self):
   ivy_subsystem = global_subsystem_instance(IvySubsystem)
   self.assertEqual(('example.com', 1234),
                     ivy_subsystem._parse_proxy_string('http://example.com:1234'))
   self.assertEqual(('secure-example.com', 999),
                     ivy_subsystem._parse_proxy_string('http://secure-example.com:999'))
   # trailing slash is ok
   self.assertEqual(('example.com', 1234),
                     ivy_subsystem._parse_proxy_string('http://example.com:1234/'))
Ejemplo n.º 15
0
  def setUp(self):
    init_subsystems([LibcDev], options={
      'libc': {
        'enable_libc_search': True,
        'host_compiler': 'this_executable_does_not_exist',
      },
    })

    self.libc = global_subsystem_instance(LibcDev)
    self.platform = Platform.current
Ejemplo n.º 16
0
  def setUp(self):
    init_subsystems([LibcDev], options={
      'libc': {
        'enable_libc_search': False,
        'libc_dir': '/does/not/exist',
      },
    })

    self.libc = global_subsystem_instance(LibcDev)
    self.platform = Platform.current
Ejemplo n.º 17
0
  def setUp(self):
    init_subsystems([LibcDev], options={
      'libc': {
        'enable_libc_search': False,
        'libc_dir': '/does/not/exist',
      },
    })

    self.libc = global_subsystem_instance(LibcDev)
    self.platform = Platform.current
Ejemplo n.º 18
0
  def setUp(self):
    init_subsystems([LibcDev], options={
      'libc': {
        'enable_libc_search': True,
        'host_compiler': 'this_executable_does_not_exist',
      },
    })

    self.libc = global_subsystem_instance(LibcDev)
    self.platform = Platform.current
Ejemplo n.º 19
0
  def test_validate_live(self):
    with self.assertRaises(Distribution.Error):
      Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='999.9.9').validate()
    with self.assertRaises(Distribution.Error):
      Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='0.0.1').validate()

    Distribution(bin_path=os.path.dirname(self.JAVA)).validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1').validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='999.999.999').validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1',
                 maximum_version='999.999.999').validate()
    locator = global_subsystem_instance(DistributionLocator)
    locator.cached(jdk=False)
Ejemplo n.º 20
0
  def test_validate_live(self):
    with self.assertRaises(Distribution.Error):
      Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='999.9.9').validate()
    with self.assertRaises(Distribution.Error):
      Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='0.0.1').validate()

    Distribution(bin_path=os.path.dirname(self.JAVA)).validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1').validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='999.999.999').validate()
    Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1',
                 maximum_version='999.999.999').validate()
    locator = global_subsystem_instance(DistributionLocator)
    locator.cached(jdk=False)
Ejemplo n.º 21
0
 def requirements(cls, tools):
   sdk_home = os.environ.get('ANDROID_HOME')
   android_sdk = os.path.abspath(sdk_home) if sdk_home else None
   if android_sdk:
     for tool in tools:
       if not os.path.isfile(os.path.join(android_sdk, tool)):
         return False
   else:
     return False
   try:
     locator = global_subsystem_instance(DistributionLocator)
     locator.cached(minimum_version=cls.JAVA_MIN, maximum_version=cls.JAVA_MAX)
   except Distribution.Error:
     return False
   return True
Ejemplo n.º 22
0
 def test_go_compile_simple(self):
   with self.temporary_workdir() as workdir:
     args = ['compile',
             'contrib/go/examples/src/go/libA']
     pants_run = self.run_pants_with_workdir(args, workdir)
     self.assert_success(pants_run)
     go_dist = global_subsystem_instance(GoDistribution)
     goos = go_dist.create_go_cmd('env', args=['GOOS']).check_output().strip()
     goarch = go_dist.create_go_cmd('env', args=['GOARCH']).check_output().strip()
     expected_files = set('contrib.go.examples.src.go.{libname}.{libname}/'
                          'pkg/{goos}_{goarch}/{libname}.a'
                          .format(libname=libname, goos=goos, goarch=goarch)
                          for libname in ('libA', 'libB', 'libC', 'libD', 'libE'))
     self.assertTrue(contains_exact_files(os.path.join(workdir, 'compile', 'go'),
                                          expected_files, ignore_links=True))
Ejemplo n.º 23
0
 def test_interpreter_constraints_parsing(self):
   python_setup = global_subsystem_instance(PythonSetup)
   target_adaptors = [
     # NB: This target will use the global --python-setup-interpreter-constraints.
     PythonTargetAdaptor(compatibility=None),
     PythonTargetAdaptor(compatibility=["CPython>=400"]),
   ]
   self.assertEqual(
     parse_interpreter_constraints(python_setup, target_adaptors),
     [
       "--interpreter-constraint", "CPython>=2.7,<3",
       "--interpreter-constraint", "CPython>=3.6,<4",
       "--interpreter-constraint", "CPython>=400"
     ]
   )
Ejemplo n.º 24
0
 def test_go_compile_simple(self):
   with self.temporary_workdir() as workdir:
     args = ['compile',
             'contrib/go/examples/src/go/libA']
     pants_run = self.run_pants_with_workdir(args, workdir)
     self.assert_success(pants_run)
     go_dist = global_subsystem_instance(GoDistribution)
     goos = go_dist.create_go_cmd('env', args=['GOOS']).check_output().decode().strip()
     goarch = go_dist.create_go_cmd('env', args=['GOARCH']).check_output().decode().strip()
     expected_files = set('contrib.go.examples.src.go.{libname}.{libname}/'
                          'pkg/{goos}_{goarch}/{libname}.a'
                          .format(libname=libname, goos=goos, goarch=goarch)
                          for libname in ('libA', 'libB', 'libC', 'libD', 'libE'))
     self.assertTrue(contains_exact_files(os.path.join(workdir, 'compile', 'go'),
                                          expected_files, ignore_links=True))
Ejemplo n.º 25
0
  def test_proxy_from_env(self):
    ivy_subsystem = global_subsystem_instance(IvySubsystem)
    self.assertIsNone(ivy_subsystem.http_proxy())
    self.assertIsNone(ivy_subsystem.https_proxy())

    with environment_as(HTTP_PROXY='http://proxy.example.com:456',
                        HTTPS_PROXY='https://secure-proxy.example.com:789'):
      self.assertEquals('http://proxy.example.com:456', ivy_subsystem.http_proxy())
      self.assertEquals('https://secure-proxy.example.com:789', ivy_subsystem.https_proxy())

      self.assertEquals([
        '-Dhttp.proxyHost=proxy.example.com',
        '-Dhttp.proxyPort=456',
        '-Dhttps.proxyHost=secure-proxy.example.com',
        '-Dhttps.proxyPort=789',
      ], ivy_subsystem.extra_jvm_options())
Ejemplo n.º 26
0
  def test_proxy_from_env(self):
    ivy_subsystem = global_subsystem_instance(IvySubsystem)
    self.assertIsNone(ivy_subsystem.http_proxy())
    self.assertIsNone(ivy_subsystem.https_proxy())

    with environment_as(HTTP_PROXY='http://proxy.example.com:456',
                        HTTPS_PROXY='https://secure-proxy.example.com:789'):
      self.assertEqual('http://proxy.example.com:456', ivy_subsystem.http_proxy())
      self.assertEqual('https://secure-proxy.example.com:789', ivy_subsystem.https_proxy())

      self.assertEqual([
        '-Dhttp.proxyHost=proxy.example.com',
        '-Dhttp.proxyPort=456',
        '-Dhttps.proxyHost=secure-proxy.example.com',
        '-Dhttps.proxyPort=789',
      ], ivy_subsystem.extra_jvm_options())
Ejemplo n.º 27
0
    def test_ignore_dir(self):
        """Verify that passing --repro-ignore option ignores the directory"""

        # Buildroot is is based on your cwd so we need to step into a fresh
        # directory for repro to look at.
        root_instance = BuildRoot()
        with temporary_dir() as build_root:
            with root_instance.temporary(build_root):
                with pushd(build_root):
                    with temporary_dir() as capture_dir:
                        add_file = partial(self.add_file, build_root)
                        add_file('pants.ini', '')
                        add_file('.git/foo', 'foo')
                        add_file('dist/bar', 'bar')
                        add_file('foo/bar', 'baz')
                        add_file('src/test1', 'test1')
                        add_file('src/test2', 'test1')

                        repro_file = os.path.join(capture_dir, 'repro.tar.gz')
                        options = {
                            Reproducer.options_scope:
                            dict(
                                capture=repro_file,
                                ignore=['src'],
                            )
                        }
                        repro_sub = global_subsystem_instance(Reproducer,
                                                              options=options)
                        repro = repro_sub.create_repro(
                        )  # This is normally called in pants_exe.
                        repro.capture(run_info_dict={})

                        extract_loc = os.path.join(capture_dir, 'extract')
                        TGZ.extract(repro_file, extract_loc)

                        assert_file = partial(self.assert_file, extract_loc)
                        assert_file('foo/bar', 'baz')

                        assert_not_exists = partial(self.assert_not_exists,
                                                    extract_loc)
                        assert_not_exists('.git')
                        assert_not_exists('src')
Ejemplo n.º 28
0
 def test_export_jar_path(self):
     with self.temporary_workdir() as workdir:
         test_target = 'examples/tests/java/org/pantsbuild/example/usethrift:usethrift'
         json_data = self.run_export(test_target, workdir, load_libs=True)
         ivy_subsystem = global_subsystem_instance(IvySubsystem)
         ivy_cache_dir = ivy_subsystem.get_options().cache_dir
         common_lang_lib_info = json_data.get('libraries').get(
             'junit:junit:4.12')
         self.assertIsNotNone(common_lang_lib_info)
         self.assertEquals(
             common_lang_lib_info.get('default'),
             os.path.join(ivy_cache_dir, 'junit/junit/jars/junit-4.12.jar'))
         self.assertEquals(
             common_lang_lib_info.get('javadoc'),
             os.path.join(ivy_cache_dir,
                          'junit/junit/javadocs/junit-4.12-javadoc.jar'))
         self.assertEquals(
             common_lang_lib_info.get('sources'),
             os.path.join(ivy_cache_dir,
                          'junit/junit/sources/junit-4.12-sources.jar'))
Ejemplo n.º 29
0
 def test_export_jar_path(self):
   with self.temporary_workdir() as workdir:
     test_target = 'examples/tests/java/org/pantsbuild/example/usethrift:usethrift'
     json_data = self.run_export(test_target, workdir, load_libs=True)
     ivy_subsystem = global_subsystem_instance(IvySubsystem)
     ivy_cache_dir = ivy_subsystem.get_options().cache_dir
     common_lang_lib_info = json_data.get('libraries').get('junit:junit:4.12')
     self.assertIsNotNone(common_lang_lib_info)
     self.assertEquals(
       common_lang_lib_info.get('default'),
       os.path.join(ivy_cache_dir, 'junit/junit/jars/junit-4.12.jar')
     )
     self.assertEquals(
       common_lang_lib_info.get('javadoc'),
       os.path.join(ivy_cache_dir,
                    'junit/junit/javadocs/junit-4.12-javadoc.jar')
     )
     self.assertEquals(
       common_lang_lib_info.get('sources'),
       os.path.join(ivy_cache_dir,
                    'junit/junit/sources/junit-4.12-sources.jar')
     )
Ejemplo n.º 30
0
  def test_ignore_dir(self):
    """Verify that passing --repro-ignore option ignores the directory"""

    # Buildroot is is based on your cwd so we need to step into a fresh
    # directory for repro to look at.
    root_instance = BuildRoot()
    with temporary_dir() as build_root:
      with root_instance.temporary(build_root):
        with pushd(build_root):
          with temporary_dir() as capture_dir:
            add_file = partial(self.add_file, build_root)
            add_file('pants.ini', '')
            add_file('.git/foo', 'foo')
            add_file('dist/bar', 'bar')
            add_file('foo/bar', 'baz')
            add_file('src/test1', 'test1')
            add_file('src/test2', 'test1')

            repro_file = os.path.join(capture_dir, 'repro.tar.gz')
            options = {
              Reproducer.options_scope: dict(
                capture=repro_file,
                ignore=['src'],
            )}
            repro_sub = global_subsystem_instance(Reproducer, options=options)
            repro = repro_sub.create_repro()  # This is normally called in pants_exe.
            repro.capture(run_info_dict={})

            extract_loc = os.path.join(capture_dir, 'extract')
            TGZ.extract(repro_file, extract_loc)

            assert_file = partial(self.assert_file, extract_loc)
            assert_file('foo/bar', 'baz')

            assert_not_exists = partial(self.assert_not_exists, extract_loc)
            assert_not_exists('.git')
            assert_not_exists('src')
Ejemplo n.º 31
0
 def test_ivy_classifiers(self):
   with self.temporary_workdir() as workdir:
     test_target = 'testprojects/tests/java/org/pantsbuild/testproject/ivyclassifier:ivyclassifier'
     json_data = self.run_export(test_target, workdir, load_libs=True)
     ivy_subsystem = global_subsystem_instance(IvySubsystem)
     ivy_cache_dir = ivy_subsystem.get_options().cache_dir
     avro_lib_info = json_data.get('libraries').get('org.apache.avro:avro:1.7.7')
     self.assertIsNotNone(avro_lib_info)
     self.assertEquals(
       avro_lib_info.get('default'),
       os.path.join(ivy_cache_dir, 'org.apache.avro/avro/jars/avro-1.7.7.jar')
     )
     self.assertEquals(
       avro_lib_info.get('tests'),
       os.path.join(ivy_cache_dir, 'org.apache.avro/avro/jars/avro-1.7.7-tests.jar')
     )
     self.assertEquals(
       avro_lib_info.get('javadoc'),
       os.path.join(ivy_cache_dir, 'org.apache.avro/avro/javadocs/avro-1.7.7-javadoc.jar')
     )
     self.assertEquals(
       avro_lib_info.get('sources'),
       os.path.join(ivy_cache_dir, 'org.apache.avro/avro/sources/avro-1.7.7-sources.jar')
     )
Ejemplo n.º 32
0
 def setUp(self):
     # Capture PythonSetup with the real BUILD_ROOT before that is reset to a tmpdir by super.
     self.python_setup = global_subsystem_instance(PythonSetup)
     super(PythonChrootTest, self).setUp()
Ejemplo n.º 33
0
 def distribution(self):
   factory = global_subsystem_instance(GoDistribution.Factory)
   return factory.create()
Ejemplo n.º 34
0
 def setUp(self):
   super(TestNativeToolchain, self).setUp()
   self.toolchain = global_subsystem_instance(NativeToolchain)
Ejemplo n.º 35
0
 def test_validate_live_jdk(self):
   Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).validate()
   Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).binary('javap')
   locator = global_subsystem_instance(DistributionLocator)
   locator.cached(jdk=True)
Ejemplo n.º 36
0
    def setUp(self):
        super(TestNativeToolchain, self).setUp()

        self.platform = Platform.create()
        self.toolchain = global_subsystem_instance(NativeToolchain)
        self.rules = native_backend_rules()
 def _init_manager(self, **jar_dependency_management_options):
   options = {JarDependencyManagement.options_scope: jar_dependency_management_options}
   return global_subsystem_instance(JarDependencyManagement, options=options)
def _distribution_locator(distribution_locator_options=None):
  options = {
    DistributionLocator.options_scope: distribution_locator_options or {}
  }
  yield global_subsystem_instance(DistributionLocator, options=options)
Ejemplo n.º 39
0
def _distribution_locator(distribution_locator_options=None):
  options = {
    DistributionLocator.options_scope: distribution_locator_options or {}
  }
  yield global_subsystem_instance(DistributionLocator, options=options)
Ejemplo n.º 40
0
 def setUp(self):
   # Capture PythonSetup with the real BUILD_ROOT before that is reset to a tmpdir by super.
   self.python_setup = global_subsystem_instance(PythonSetup)
   super(PythonChrootTest, self).setUp()
Ejemplo n.º 41
0
 def get_thrift_version(apache_thrift_gen):
   thrift = global_subsystem_instance(Thrift).scoped_instance(apache_thrift_gen)
   return thrift.get_options().version
Ejemplo n.º 42
0
 def watchman_launcher(self, options=None):
   options = options or {}
   return global_subsystem_instance(WatchmanLauncher.Factory, options=options).create()
Ejemplo n.º 43
0
 def setUp(self):
   self.distribution = global_subsystem_instance(NodeDistribution.Factory).create()
Ejemplo n.º 44
0
 def _jar_dependency_management(self, **flags):
   Subsystem.reset()
   options = {
     JarDependencyManagement.options_scope: flags,
   }
   return global_subsystem_instance(JarDependencyManagement, options=options)
Ejemplo n.º 45
0
 def distribution(self):
   return global_subsystem_instance(GoDistribution)
Ejemplo n.º 46
0
 def fetcher(self, import_path):
   fetcher_factory = global_subsystem_instance(FetcherFactory)
   return fetcher_factory.get_fetcher(import_path)
Ejemplo n.º 47
0
 def setUp(self):
     self.distribution = global_subsystem_instance(NodeDistribution)
Ejemplo n.º 48
0
    def _execute_junit_runner(self,
                              list_of_filename_content_tuples,
                              create_some_resources=True,
                              target_name=None):
        # Create the temporary base test directory
        test_rel_path = 'tests/java/org/pantsbuild/foo'
        test_abs_path = self.create_dir(test_rel_path)

        # Create the temporary classes directory under work dir
        test_classes_abs_path = self.create_workdir_dir(test_rel_path)

        test_java_file_abs_paths = []
        # Generate the temporary java test source code.
        for filename, content in list_of_filename_content_tuples:
            test_java_file_rel_path = os.path.join(test_rel_path, filename)
            test_java_file_abs_path = self.create_file(test_java_file_rel_path,
                                                       content)
            test_java_file_abs_paths.append(test_java_file_abs_path)

        # Invoke ivy to resolve classpath for junit.
        classpath_file_abs_path = os.path.join(test_abs_path,
                                               'junit.classpath')
        ivy_subsystem = global_subsystem_instance(IvySubsystem)
        distribution = DistributionLocator.cached(jdk=True)
        ivy = Bootstrapper(ivy_subsystem=ivy_subsystem).ivy()
        ivy.execute(args=[
            '-cachepath', classpath_file_abs_path, '-dependency', 'junit',
            'junit-dep', '4.10'
        ],
                    executor=SubprocessExecutor(distribution=distribution))

        with open(classpath_file_abs_path) as fp:
            classpath = fp.read()

        # Now directly invoke javac to compile the test java code into classfiles that we can later
        # inject into a product mapping for JUnitRun to execute against.
        javac = distribution.binary('javac')
        subprocess.check_call(
            [javac, '-d', test_classes_abs_path, '-cp', classpath] +
            test_java_file_abs_paths)

        # If a target_name is specified create a target with it, otherwise create a junit_tests target.
        if target_name:
            target = self.target(target_name)
        else:
            target = self.create_library(test_rel_path, 'junit_tests',
                                         'foo_test', ['FooTest.java'])

        target_roots = []
        if create_some_resources:
            # Create a synthetic resource target.
            target_roots.append(self.make_target('some_resources', Resources))
        target_roots.append(target)

        # Set the context with the two targets, one junit_tests target and
        # one synthetic resources target.
        # The synthetic resources target is to make sure we won't regress
        # in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
        # in that bug, the resources target must be the first one in the list.
        context = self.context(target_roots=target_roots)

        # Before we run the task, we need to inject the "runtime_classpath" with
        # the compiled test java classes that JUnitRun will know which test
        # classes to execute. In a normal run, this "runtime_classpath" will be
        # populated by java compilation step.
        self.populate_runtime_classpath(context=context,
                                        classpath=[test_classes_abs_path])

        # Finally execute the task.
        self.execute(context)
Ejemplo n.º 49
0
 def setUp(self):
   self.distribution = global_subsystem_instance(NodeDistribution)
Ejemplo n.º 50
0
 def setUp(self):
   self.distribution = global_subsystem_instance(NodeDistribution.Factory).create()
Ejemplo n.º 51
0
 def subprocess(self):
   return global_subsystem_instance(Subprocess.Factory).create()
Ejemplo n.º 52
0
 def test_validate_live_jdk(self):
   Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).validate()
   Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).binary('javap')
   locator = global_subsystem_instance(DistributionLocator)
   locator.cached(jdk=True)
Ejemplo n.º 53
0
 def pants_daemon_launcher(self):
   factory = global_subsystem_instance(PantsDaemonLauncher.Factory)
   pdl = factory.create(None)
   pdl.pantsd = self.mock_pantsd
   pdl.watchman_launcher = self.mock_watchman_launcher
   return pdl
Ejemplo n.º 54
0
 def get_thrift_version(apache_thrift_gen):
   thrift = global_subsystem_instance(Thrift).scoped_instance(apache_thrift_gen)
   return thrift.get_options().version
Ejemplo n.º 55
0
 def create_subsystem(subsystem_type, options=None):
     return global_subsystem_instance(
         subsystem_type,
         options={subsystem_type.options_scope: options or {}})