Exemplo n.º 1
0
    def dumped_chroot(self, targets):
        python_repos = create_subsystem(PythonRepos)

        with subsystem_instance(IvySubsystem) as ivy_subsystem:
            ivy_bootstrapper = Bootstrapper(ivy_subsystem=ivy_subsystem)

            with subsystem_instance(
                    ThriftBinary.Factory) as thrift_binary_factory:
                interpreter_cache = PythonInterpreterCache(
                    self.python_setup, python_repos)
                interpreter_cache.setup()
                interpreters = list(
                    interpreter_cache.matches(
                        [self.python_setup.interpreter_requirement]))
                self.assertGreater(len(interpreters), 0)
                interpreter = interpreters[0]

                with temporary_dir() as chroot:
                    pex_builder = PEXBuilder(path=chroot,
                                             interpreter=interpreter)

                    python_chroot = PythonChroot(
                        python_setup=self.python_setup,
                        python_repos=python_repos,
                        ivy_bootstrapper=ivy_bootstrapper,
                        thrift_binary_factory=thrift_binary_factory.create,
                        interpreter=interpreter,
                        builder=pex_builder,
                        targets=targets,
                        platforms=['current'])
                    try:
                        python_chroot.dump()
                        yield pex_builder, python_chroot
                    finally:
                        python_chroot.delete()
Exemplo n.º 2
0
  def dumped_chroot(self, targets):
    # TODO(benjy): We shouldn't need to mention DistributionLocator here, as IvySubsystem
    # declares it as a dependency. However if we don't then test_antlr() below fails on
    # uninitialized options for that subsystem.  Hopefully my pending (as of 9/2016) change
    # to clean up how we initialize and create instances of subsystems in tests will make
    # this problem go away.
    self.context(for_subsystems=[PythonRepos, PythonSetup, IvySubsystem,
                                 DistributionLocator, ThriftBinary.Factory, BinaryUtil.Factory])
    python_repos = PythonRepos.global_instance()
    ivy_bootstrapper = Bootstrapper(ivy_subsystem=IvySubsystem.global_instance())
    thrift_binary_factory = ThriftBinary.Factory.global_instance().create

    interpreter_cache = PythonInterpreterCache(self.python_setup, python_repos)
    interpreter = interpreter_cache.select_interpreter_for_targets(targets)
    self.assertIsNotNone(interpreter)

    with temporary_dir() as chroot:
      pex_builder = PEXBuilder(path=chroot, interpreter=interpreter)

      python_chroot = PythonChroot(python_setup=self.python_setup,
                                   python_repos=python_repos,
                                   ivy_bootstrapper=ivy_bootstrapper,
                                   thrift_binary_factory=thrift_binary_factory,
                                   interpreter=interpreter,
                                   builder=pex_builder,
                                   targets=targets,
                                   platforms=['current'])
      try:
        python_chroot.dump()
        yield pex_builder, python_chroot
      finally:
        python_chroot.delete()
Exemplo n.º 3
0
  def execute_junit_runner(self, content):

    # Create the temporary base test directory
    test_rel_path = 'tests/java/org/pantsbuild/foo'
    test_abs_path = os.path.join(self.build_root, test_rel_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 = os.path.join(self.build_root, test_java_file_rel_path)
    self.create_file(test_java_file_rel_path, content)

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

    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_abs_path, '-cp', classpath, test_java_file_abs_path])

    # Create a java_tests target and a synthetic resource target.
    java_tests = self.create_library(test_rel_path, 'java_tests', 'foo_test', ['FooTest.java'])
    resources = self.make_target('some_resources', Resources)

    # 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=[resources, java_tests])

    # Before we run the task, we need to inject the "classes_by_target" with
    # the compiled test java classes that JUnitRun will know which test
    # classes to execute. In a normal run, this "classes_by_target" will be
    # populated by java compiling step.
    class_products = context.products.get_data(
      'classes_by_target', lambda: defaultdict(MultipleRootedProducts))
    java_tests_products = MultipleRootedProducts()
    java_tests_products.add_rel_paths(test_abs_path, ['FooTest.class'])
    class_products[java_tests] = java_tests_products

    # Also we need to add the FooTest.class's classpath to the compile_classpath
    # products data mapping so JUnitRun will be able to add that into the final
    # classpath under which the junit will be executed.
    self.populate_compile_classpath(context=context, classpath=[test_abs_path])

    # Finally execute the task.
    self.execute(context)
Exemplo n.º 4
0
 def test_simple(self):
   ivy_subsystem = IvySubsystem.global_instance()
   bootstrapper = Bootstrapper(ivy_subsystem=ivy_subsystem)
   ivy = bootstrapper.ivy()
   self.assertIsNotNone(ivy.ivy_resolution_cache_dir)
   self.assertIsNone(ivy.ivy_settings)
   bootstrap_jar_path = os.path.join(ivy_subsystem.get_options().pants_bootstrapdir,
                                     'tools', 'jvm', 'ivy', 'bootstrap.jar')
   self.assertTrue(os.path.exists(bootstrap_jar_path))
Exemplo n.º 5
0
 def test_simple(self):
     ivy_subsystem = IvySubsystem.global_instance()
     bootstrapper = Bootstrapper(ivy_subsystem=ivy_subsystem)
     ivy = bootstrapper.ivy()
     self.assertIsNotNone(ivy.ivy_resolution_cache_dir)
     self.assertIsNone(ivy.ivy_settings)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def ivy_bootstrapper(self):
     return Bootstrapper(ivy_subsystem=IvySubsystem.global_instance())