Example #1
0
  def setUp(self):
    super(JvmToolTaskTestBase, self).setUp()

    # Use a synthetic subclass for proper isolation when bootstrapping within the test.
    bootstrap_scope = 'bootstrap_scope'
    self.bootstrap_task_type = self.synthesize_task_subtype(BootstrapJvmTools, bootstrap_scope)
    JvmToolMixin.reset_registered_tools()

    # Set some options:

    # 1. Cap BootstrapJvmTools memory usage in tests.  The Xmx was empirically arrived upon using
    #    -Xloggc and verifying no full gcs for a test using the full gamut of resolving a multi-jar
    #    tool, constructing a fat jar and then shading that fat jar.
    #
    # 2. Allow tests to read/write tool jars from the real artifact cache, so they don't
    #    each have to resolve and shade them every single time, which is a huge slowdown.
    #    Note that local artifact cache writes are atomic, so it's fine for multiple concurrent
    #    tests to write to it.
    #
    # Note that we don't have access to the invoking pants instance's options, so we assume that
    # its artifact cache is in the standard location.  If it isn't, worst case the tests will
    # populate a second cache at the standard location, which is no big deal.
    # TODO: We really need a straightforward way for pants's own tests to get to the enclosing
    # pants instance's options values.
    artifact_caches = [os.path.join(get_pants_cachedir(), 'artifact_cache')]
    self.set_options_for_scope(bootstrap_scope, jvm_options=['-Xmx128m'])
    self.set_options_for_scope('cache.{}'.format(bootstrap_scope),
                               read_from=artifact_caches,
                               write_to=artifact_caches)

    # Tool option defaults currently point to targets in the real BUILD.tools, so we copy it
    # into our test workspace.
    shutil.copy(os.path.join(self.real_build_root, 'BUILD.tools'), self.build_root)

    Bootstrapper.reset_instance()
Example #2
0
 def setUp(self):
   super(TaskTestBase, self).setUp()
   self._testing_task_type, self.options_scope = self.synthesize_task_subtype(self.task_type())
   # We locate the workdir below the pants_workdir, which BaseTest locates within
   # the BuildRoot.
   self._tmpdir = tempfile.mkdtemp(dir=self.pants_workdir)
   self._test_workdir = os.path.join(self._tmpdir, 'workdir')
   os.mkdir(self._test_workdir)
   Bootstrapper.reset_instance()
   IvySubsystem.reset_global_instance()
 def _temp_ivy_cache_dir(self):
     # We also reset the Bootstrapper since it hangs on to a ivy subsystem.
     old_instance = Bootstrapper._INSTANCE
     try:
         with temporary_dir() as ivy_cache_dir:
             Bootstrapper.reset_instance()
             # We set a temp ivy cache to ensure that the ivy we're using won't cache the temporary jar.
             self.set_options_for_scope('ivy', cache_dir=ivy_cache_dir)
             yield ivy_cache_dir
     finally:
         Bootstrapper._INSTANCE = old_instance
Example #4
0
 def _temp_ivy_cache_dir(self):
   # We also reset the Bootstrapper since it hangs on to a ivy subsystem.
   old_instance = Bootstrapper._INSTANCE
   try:
     with temporary_dir() as ivy_cache_dir:
       Bootstrapper.reset_instance()
       # We set a temp ivy cache to ensure that the ivy we're using won't cache the temporary jar.
       self.set_options_for_scope('ivy', cache_dir=ivy_cache_dir)
       yield ivy_cache_dir
   finally:
     Bootstrapper._INSTANCE = old_instance
Example #5
0
 def setUp(self):
   super(TaskTestBase, self).setUp()
   self._testing_task_type = self.synthesize_task_subtype(self.task_type(), self.options_scope)
   # We locate the workdir below the pants_workdir, which BaseTest locates within the BuildRoot.
   # BaseTest cleans this up, so we don't need to.  We give it a stable name, so that we can
   # use artifact caching to speed up tests.
   self._test_workdir = os.path.join(self.pants_workdir, self.task_type().stable_name())
   os.mkdir(self._test_workdir)
   # TODO: Push this down to JVM-related tests only? Seems wrong to have an ivy-specific
   # action in this non-JVM-specific, high-level base class.
   Bootstrapper.reset_instance()
Example #6
0
 def setUp(self):
   super(TaskTestBase, self).setUp()
   self._testing_task_type, self.options_scope = self.synthesize_task_subtype(self.task_type())
   # We locate the workdir below the pants_workdir, which BaseTest locates within
   # the BuildRoot.
   self._tmpdir = tempfile.mkdtemp(dir=self.pants_workdir)
   self._test_workdir = os.path.join(self._tmpdir, 'workdir')
   os.mkdir(self._test_workdir)
   # TODO: Push this down to JVM-related tests only? Seems wrong to have an ivy-specific
   # action in this non-JVM-specific, high-level base class.
   Bootstrapper.reset_instance()
Example #7
0
 def setUp(self):
   super(TaskTestBase, self).setUp()
   self.options_scope = 'test_scope'
   self._testing_task_type = self.synthesize_task_subtype(self.task_type(), self.options_scope)
   # We locate the workdir below the pants_workdir, which BaseTest locates within the BuildRoot.
   # BaseTest cleans this up, so we don't need to.  We give it a stable name, so that we can
   # use artifact caching to speed up tests.
   self._test_workdir = os.path.join(self.pants_workdir, self.task_type().stable_name())
   os.mkdir(self._test_workdir)
   # TODO: Push this down to JVM-related tests only? Seems wrong to have an ivy-specific
   # action in this non-JVM-specific, high-level base class.
   Bootstrapper.reset_instance()
Example #8
0
    def setUp(self):
        """
        :API: public
        """
        super().setUp()

        # Use a synthetic subclass for proper isolation when bootstrapping within the test.
        bootstrap_scope = "bootstrap_scope"
        self.bootstrap_task_type = self.synthesize_task_subtype(
            BootstrapJvmTools, bootstrap_scope)
        JvmToolMixin.reset_registered_tools()

        # Set some options:

        # 1. Cap BootstrapJvmTools memory usage in tests.  The Xmx was empirically arrived upon using
        #    -Xloggc and verifying no full gcs for a test using the full gamut of resolving a multi-jar
        #    tool, constructing a fat jar and then shading that fat jar.
        #
        # 2. Allow tests to read/write tool jars from the real artifact cache, so they don't
        #    each have to resolve and shade them every single time, which is a huge slowdown.
        #    Note that local artifact cache writes are atomic, so it's fine for multiple concurrent
        #    tests to write to it.
        #
        # Note that we don't have access to the invoking pants instance's options, so we assume that
        # its artifact cache is in the standard location.  If it isn't, worst case the tests will
        # populate a second cache at the standard location, which is no big deal.
        # TODO: We really need a straightforward way for pants's own tests to get to the enclosing
        # pants instance's options values.
        artifact_caches = [
            os.path.join(get_pants_cachedir(), "artifact_cache")
        ]
        self.set_options_for_scope(
            bootstrap_scope,
            execution_strategy=NailgunTask.ExecutionStrategy.subprocess,
            jvm_options=["-Xmx128m"],
        )
        self.set_options_for_scope(f"cache.{bootstrap_scope}",
                                   read_from=artifact_caches,
                                   write_to=artifact_caches)

        # Copy into synthetic build-root
        shutil.copy("BUILD.tools", self.build_root)
        build_root_third_party = os.path.join(self.build_root, "3rdparty")
        safe_mkdir(build_root_third_party)
        shutil.copy(os.path.join("3rdparty", "BUILD"), build_root_third_party)

        Bootstrapper.reset_instance()
  def setUp(self):
    super(JvmToolTaskTestBase, self).setUp()

    # Use a synthetic subclass for proper isolation when bootstrapping within the test.
    bootstrap_scope = 'bootstrap_scope'
    self.bootstrap_task_type = self.synthesize_task_subtype(BootstrapJvmTools, bootstrap_scope)
    JvmToolMixin.reset_registered_tools()

    # Cap BootstrapJvmTools memory usage in tests.  The Xmx was empirically arrived upon using
    # -Xloggc and verifying no full gcs for a test using the full gamut of resolving a multi-jar
    # tool, constructing a fat jar and then shading that fat jar.
    self.set_options_for_scope(bootstrap_scope, jvm_options=['-Xmx128m'])

    # Tool option defaults currently point to targets in the real BUILD.tools, so we copy it
    # into our test workspace.
    shutil.copy(os.path.join(self.real_build_root, 'BUILD.tools'), self.build_root)

    Bootstrapper.reset_instance()
Example #10
0
 def test_reset(self):
     bootstrapper1 = Bootstrapper.instance()
     Bootstrapper.reset_instance()
     bootstrapper2 = Bootstrapper.instance()
     self.assertNotEqual(bootstrapper1, bootstrapper2)
Example #11
0
 def test_reset(self):
   bootstrapper1 = Bootstrapper.instance()
   Bootstrapper.reset_instance()
   bootstrapper2 = Bootstrapper.instance()
   self.assertNotEqual(bootstrapper1, bootstrapper2)
  def setUp(self):
    # TODO(Eric Ayers): this is the old way
    # Ensure we get a read of the real pants.ini config
    Config.reset_default_bootstrap_option_values()
    real_config = Config.from_cache()

    super(JvmToolTaskTestBase, self).setUp()

    # Use a synthetic subclass for bootstrapping within the test, to isolate this from
    # any bootstrapping the pants run executing the test might need.
    self.bootstrap_task_type, bootstrap_scope = self.synthesize_task_subtype(BootstrapJvmTools)
    JvmToolMixin.reset_registered_tools()

    # Cap BootstrapJvmTools memory usage in tests.  The Xmx was empirically arrived upon using
    # -Xloggc and verifying no full gcs for a test using the full gamut of resolving a multi-jar
    # tool, constructing a fat jar and then shading that fat jar.
    self.set_options_for_scope(bootstrap_scope, jvm_options=['-Xmx128m'])

    def link_or_copy(src, dest):
      try:
        os.link(src, dest)
      except OSError as e:
        if e.errno == errno.EXDEV:
          shutil.copy(src, dest)
        else:
          raise e

    def link(path, optional=False, force=False):
      src = os.path.join(self.real_build_root, path)
      if not optional or os.path.exists(src):
        dest = os.path.join(self.build_root, path)
        safe_mkdir(os.path.dirname(dest))
        try:
          link_or_copy(src, dest)
        except OSError as e:
          if force and e.errno == errno.EEXIST:
            os.unlink(dest)
            link_or_copy(src, dest)
          else:
            raise e
        return dest

    def link_tree(path, optional=False, force=False):
      src = os.path.join(self.real_build_root, path)
      if not optional or os.path.exists(src):
        for abspath, dirs, files in safe_walk(src):
          for f in files:
            link(os.path.relpath(os.path.join(abspath, f), self.real_build_root), force=force)

    # TODO(John Sirois): Find a way to do this cleanly
    link('pants.ini', force=True)

    # TODO(pl): Note that this pulls in a big chunk of the hairball to every test that
    # depends on it, because BUILD contains source_roots that specify a variety of types
    # from different backends.
    link('BUILD', force=True)

    link('BUILD.tools', force=True)
    support_dir = real_config.getdefault('pants_supportdir')
    link_tree(os.path.relpath(os.path.join(support_dir, 'ivy'), self.real_build_root), force=True)
    bootstrap_option_values = OptionsBootstrapper().get_bootstrap_options().for_global_scope()
    self.set_bootstrap_options(bootstrap_option_values)
    safe_mkdir(os.path.join(bootstrap_option_values.pants_supportdir, 'ivy'))
    settings_file = os.path.join(bootstrap_option_values.pants_supportdir, 'ivy', 'ivysettings.xml')
    if not os.path.exists(settings_file):
      shutil.copy('build-support/ivy/ivysettings.xml',
                  os.path.join(bootstrap_option_values.pants_supportdir, 'ivy'))
    Bootstrapper.reset_instance()
Example #13
0
 def test_reset(self):
     with subsystem_instance(IvySubsystem):
         bootstrapper1 = Bootstrapper.instance()
         Bootstrapper.reset_instance()
         bootstrapper2 = Bootstrapper.instance()
         self.assertIsNot(bootstrapper1, bootstrapper2)
Example #14
0
 def test_reset(self):
   with subsystem_instance(IvySubsystem):
     bootstrapper1 = Bootstrapper.instance()
     Bootstrapper.reset_instance()
     bootstrapper2 = Bootstrapper.instance()
     self.assertIsNot(bootstrapper1, bootstrapper2)