Beispiel #1
0
 def __init__(self,
              options,
              run_tracker,
              target_roots,
              requested_goals=None,
              target_base=None,
              build_graph=None,
              build_file_parser=None,
              address_mapper=None,
              console_outstream=None,
              scm=None,
              workspace=None,
              spec_excludes=None,
              invalidation_report=None):
     self._options = options
     self.build_graph = build_graph
     self.build_file_parser = build_file_parser
     self.address_mapper = address_mapper
     self.run_tracker = run_tracker
     self._log = self.Log(run_tracker)
     self._target_base = target_base or Target
     self._products = Products()
     self._buildroot = get_buildroot()
     self._lock = OwnerPrintingPIDLockFile(
         os.path.join(self._buildroot, '.pants.run'))
     self._java_sysprops = None  # Computed lazily.
     self.requested_goals = requested_goals or []
     self._console_outstream = console_outstream or sys.stdout
     self._scm = scm or get_scm()
     self._workspace = workspace or (ScmWorkspace(self._scm)
                                     if self._scm else None)
     self._spec_excludes = spec_excludes
     self._replace_targets(target_roots)
     self._synthetic_targets = defaultdict(list)
     self._invalidation_report = invalidation_report
Beispiel #2
0
  def __init__(self, options, run_tracker, target_roots,
               requested_goals=None, target_base=None, build_graph=None,
               build_file_parser=None, build_configuration=None,
               address_mapper=None, console_outstream=None, scm=None,
               workspace=None, invalidation_report=None, scheduler=None):
    self._options = options

    # We register a callback that will cause build graph edits to invalidate our caches, and we hold
    # a handle directly to the callback function to ensure that it is not GC'd until the context is.
    self.build_graph = build_graph
    self._clear_target_cache_handle = self._clear_target_cache
    self._targets_cache = dict()
    self.build_graph.add_invalidation_callback(self._clear_target_cache_handle)

    self._build_file_parser = build_file_parser
    self.build_configuration = build_configuration
    self.address_mapper = address_mapper
    self.run_tracker = run_tracker
    self._log = run_tracker.logger
    self._target_base = target_base or Target
    self._products = Products()
    self._buildroot = get_buildroot()
    self._source_roots = SourceRootConfig.global_instance().get_source_roots()
    self._lock = OwnerPrintingInterProcessFileLock(os.path.join(self._buildroot, '.pants.workdir.file_lock'))
    self._java_sysprops = None  # Computed lazily.
    self.requested_goals = requested_goals or []
    self._console_outstream = console_outstream or sys.stdout.buffer
    self._scm = scm or get_scm()
    self._workspace = workspace or (ScmWorkspace(self._scm) if self._scm else None)
    self._replace_targets(target_roots)
    self._invalidation_report = invalidation_report
    self._scheduler = scheduler
Beispiel #3
0
 def __init__(self,
              options,
              run_tracker,
              target_roots,
              requested_goals=None,
              target_base=None,
              build_graph=None,
              build_file_parser=None,
              address_mapper=None,
              console_outstream=None,
              scm=None,
              workspace=None,
              invalidation_report=None):
     self._options = options
     self.build_graph = build_graph
     self.build_file_parser = build_file_parser
     self.address_mapper = address_mapper
     self.run_tracker = run_tracker
     self._log = self.Log(run_tracker)
     self._target_base = target_base or Target
     self._products = Products()
     self._buildroot = get_buildroot()
     self._source_roots = SourceRootConfig.global_instance(
     ).get_source_roots()
     self._lock = OwnerPrintingInterProcessFileLock(
         os.path.join(self._buildroot, '.pants.workdir.file_lock'))
     self._java_sysprops = None  # Computed lazily.
     self.requested_goals = requested_goals or []
     self._console_outstream = console_outstream or sys.stdout
     self._scm = scm or get_scm()
     self._workspace = workspace or (ScmWorkspace(self._scm)
                                     if self._scm else None)
     self._replace_targets(target_roots)
     self._invalidation_report = invalidation_report
Beispiel #4
0
    def __init__(self,
                 config,
                 options,
                 run_tracker,
                 target_roots,
                 requested_goals=None,
                 lock=None,
                 log=None,
                 target_base=None,
                 build_graph=None,
                 build_file_parser=None):
        self._config = config
        self._options = options
        self.build_graph = build_graph
        self.build_file_parser = build_file_parser
        self.run_tracker = run_tracker
        self._lock = lock or Lock.unlocked()
        self._log = log or Context.Log(run_tracker)
        self._target_base = target_base or Target

        self._state = {}
        self._products = Products()
        self._buildroot = get_buildroot()
        self._java_sysprops = None  # Computed lazily.
        self.requested_goals = requested_goals or []

        self.replace_targets(target_roots)
Beispiel #5
0
    def __init__(self,
                 config,
                 options,
                 run_tracker,
                 target_roots,
                 requested_goals=None,
                 lock=None,
                 log=None,
                 target_base=None,
                 build_graph=None,
                 build_file_parser=None,
                 address_mapper=None,
                 console_outstream=None,
                 scm=None,
                 workspace=None):
        self._config = config
        self._options = options
        self.build_graph = build_graph
        self.build_file_parser = build_file_parser
        self.address_mapper = address_mapper
        self.run_tracker = run_tracker
        self._lock = lock or Lock.unlocked()
        self._log = log or Context.Log(run_tracker)
        self._target_base = target_base or Target
        self._products = Products()
        self._buildroot = get_buildroot()
        self._java_sysprops = None  # Computed lazily.
        self.requested_goals = requested_goals or []
        self._console_outstream = console_outstream or sys.stdout
        self._scm = scm or get_scm()
        self._workspace = workspace or (ScmWorkspace(self._scm)
                                        if self._scm else None)

        self.replace_targets(target_roots)
Beispiel #6
0
    def __init__(self,
                 options,
                 run_tracker,
                 target_roots,
                 requested_goals=None,
                 target_base=None,
                 build_graph=None,
                 build_file_parser=None,
                 address_mapper=None,
                 console_outstream=None,
                 scm=None,
                 workspace=None,
                 spec_excludes=None,
                 invalidation_report=None):
        """
    :API: public
    """
        deprecated_conditional(
            lambda: spec_excludes is not None, '0.0.75',
            'Use address_mapper#build_ignore_patterns instead.')

        self._options = options
        self.build_graph = build_graph
        self.build_file_parser = build_file_parser
        self.address_mapper = address_mapper
        self.run_tracker = run_tracker
        self._log = self.Log(run_tracker)
        self._target_base = target_base or Target
        self._products = Products()
        self._buildroot = get_buildroot()
        self._source_roots = SourceRootConfig.global_instance(
        ).get_source_roots()
        self._lock = OwnerPrintingPIDLockFile(
            os.path.join(self._buildroot, '.pants.run'))
        self._java_sysprops = None  # Computed lazily.
        self.requested_goals = requested_goals or []
        self._console_outstream = console_outstream or sys.stdout
        self._scm = scm or get_scm()
        self._workspace = workspace or (ScmWorkspace(self._scm)
                                        if self._scm else None)
        self._spec_excludes = spec_excludes
        self._replace_targets(target_roots)
        self._invalidation_report = invalidation_report
Beispiel #7
0
 def __init__(self,
              config,
              options,
              run_tracker,
              target_roots,
              requested_goals=None,
              log=None,
              target_base=None,
              build_graph=None,
              build_file_parser=None,
              address_mapper=None,
              console_outstream=None,
              scm=None,
              workspace=None,
              spec_excludes=None):
     self._config = config
     self._options = options
     self.build_graph = build_graph
     self.build_file_parser = build_file_parser
     self.address_mapper = address_mapper
     self.run_tracker = run_tracker
     self._log = log or Context.Log(run_tracker)
     self._target_base = target_base or Target
     self._products = Products()
     self._buildroot = get_buildroot()
     self._lock = OwnerPrintingPIDLockFile(
         os.path.join(self._buildroot, '.pants.run'))
     self._java_sysprops = None  # Computed lazily.
     self.requested_goals = requested_goals or []
     self._console_outstream = console_outstream or sys.stdout
     self._scm = scm or get_scm()
     self._workspace = workspace or (ScmWorkspace(self._scm)
                                     if self._scm else None)
     self._spec_excludes = spec_excludes
     self._target_roots_have_been_accessed = False
     self.replace_targets(target_roots)
Beispiel #8
0
 def setUp(self):
     super().setUp()
     self.products = Products()
Beispiel #9
0
class ProductsTest(TestBase):
    def setUp(self):
        super().setUp()
        self.products = Products()

    def test_require(self):
        self.products.require('foo')

        self.assertTrue(self.products.isrequired('foo'))
        self.assertFalse(self.products.isrequired('bar'))

        # require should not cross-contaminate require_data
        self.assertFalse(self.products.is_required_data('foo'))
        self.assertFalse(self.products.is_required_data('bar'))

    def test_get(self):
        foo_product_mapping1 = self.products.get('foo')
        foo_product_mapping2 = self.products.get('foo')

        self.assertIsInstance(foo_product_mapping1, Products.ProductMapping)
        self.assertIs(foo_product_mapping1, foo_product_mapping2)

    def test_get_does_not_require(self):
        self.assertFalse(self.products.isrequired('foo'))
        self.products.get('foo')
        self.assertFalse(self.products.isrequired('foo'))
        self.products.require('foo')
        self.assertTrue(self.products.isrequired('foo'))

    def test_require_data(self):
        self.products.require_data('foo')

        self.assertTrue(self.products.is_required_data('foo'))
        self.assertFalse(self.products.is_required_data('bar'))

        # require_data should not cross-contaminate require
        self.assertFalse(self.products.isrequired('foo'))
        self.assertFalse(self.products.isrequired('bar'))

    def test_get_data(self):
        self.assertIsNone(self.products.get_data('foo'))

        data1 = self.products.get_data('foo', dict)
        data2 = self.products.get_data('foo', dict)

        self.assertIsInstance(data1, dict)
        self.assertIs(data1, data2)

    def test_get_data_does_not_require_data(self):
        self.assertFalse(self.products.is_required_data('foo'))
        self.products.get_data('foo')
        self.assertFalse(self.products.is_required_data('foo'))
        self.products.require_data('foo')
        self.assertTrue(self.products.is_required_data('foo'))

    def test_register_data(self):
        data = {}
        self.assertIs(data, self.products.register_data('foo', data))
        with self.assertRaises(ProductError):
            self.products.register_data('foo', data)

    def test_empty_products(self):
        foo_product_mapping = self.products.get('foo')
        self.assertFalse(foo_product_mapping)

    @contextmanager
    def add_products(self, context_products, product_type, target, *products):
        product_mapping = context_products.get(product_type)
        with temporary_dir() as outdir:

            def create_product(product):
                with safe_open(os.path.join(outdir, product), mode='w') as fp:
                    fp.write(product)
                return product

            product_mapping.add(
                target, outdir,
                [create_product(product) for product in products])
            yield temporary_dir

    def test_non_empty_products(self):
        target = self.make_target('c')
        with self.add_products(self.products, 'foo', target, 'a.class'):
            foo_product_mapping = self.products.get('foo')
            self.assertTrue(foo_product_mapping)

    def test_empty_data(self):
        foo_product_mapping = self.products.get_data('foo')
        self.assertFalse(foo_product_mapping)

    @contextmanager
    def add_data(self, context_products, data_type, target, *products):
        make_products = lambda: defaultdict(MultipleRootedProducts)
        data_by_target = context_products.get_data(data_type, make_products)
        with temporary_dir() as outdir:

            def create_product(product):
                abspath = os.path.join(outdir, product)
                with safe_open(abspath, mode='w') as fp:
                    fp.write(product)
                return abspath

            data_by_target[target].add_abs_paths(
                outdir, [create_product(product) for product in products])
            yield temporary_dir

    def test_non_empty_data(self):
        target = self.make_target('c')
        with self.add_data(self.products, 'foo', target, 'a.class'):
            foo_product_mapping = self.products.get_data('foo')
            self.assertTrue(foo_product_mapping)
Beispiel #10
0
 def setUp(self):
   super(ProductsTest, self).setUp()
   self.products = Products()
Beispiel #11
0
 def setUp(self):
   super(ProductsTest, self).setUp()
   self.products = Products()
Beispiel #12
0
class ProductsTest(BaseTest):
  def setUp(self):
    super(ProductsTest, self).setUp()
    self.products = Products()

  def test_require(self):
    self.products.require('foo')

    self.assertTrue(self.products.isrequired('foo'))
    self.assertFalse(self.products.isrequired('bar'))

    # require should not cross-contaminate require_data
    self.assertFalse(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

  def test_get(self):
    foo_product_mapping1 = self.products.get('foo')
    foo_product_mapping2 = self.products.get('foo')

    self.assertIsInstance(foo_product_mapping1, Products.ProductMapping)
    self.assertIs(foo_product_mapping1, foo_product_mapping2)

  def test_get_does_not_require(self):
    self.assertFalse(self.products.isrequired('foo'))
    self.products.get('foo')
    self.assertFalse(self.products.isrequired('foo'))
    self.products.require('foo')
    self.assertTrue(self.products.isrequired('foo'))

  def test_require_data(self):
    self.products.require_data('foo')

    self.assertTrue(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

    # require_data should not cross-contaminate require
    self.assertFalse(self.products.isrequired('foo'))
    self.assertFalse(self.products.isrequired('bar'))

  def test_get_data(self):
    self.assertIsNone(self.products.get_data('foo'))

    data1 = self.products.get_data('foo', dict)
    data2 = self.products.get_data('foo', dict)

    self.assertIsInstance(data1, dict)
    self.assertIs(data1, data2)

  def test_get_data_does_not_require_data(self):
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.get_data('foo')
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.require_data('foo')
    self.assertTrue(self.products.is_required_data('foo'))

  def test_empty_products(self):
    foo_product_mapping = self.products.get('foo')
    self.assertFalse(foo_product_mapping)

  def test_non_empty_products(self):
    target = self.make_target('c')
    with self.add_products(self.products, 'foo', target, 'a.class'):
      foo_product_mapping = self.products.get('foo')
      self.assertTrue(foo_product_mapping)

  def test_empty_data(self):
    foo_product_mapping = self.products.get_data('foo')
    self.assertFalse(foo_product_mapping)

  def test_non_empty_data(self):
    target = self.make_target('c')
    with self.add_data(self.products, 'foo', target, 'a.class'):
      foo_product_mapping = self.products.get_data('foo')
      self.assertTrue(foo_product_mapping)
Beispiel #13
0
class ProductsTest(TestBase):
  def setUp(self):
    super(ProductsTest, self).setUp()
    self.products = Products()

  def test_require(self):
    self.products.require('foo')

    self.assertTrue(self.products.isrequired('foo'))
    self.assertFalse(self.products.isrequired('bar'))

    # require should not cross-contaminate require_data
    self.assertFalse(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

  def test_get(self):
    foo_product_mapping1 = self.products.get('foo')
    foo_product_mapping2 = self.products.get('foo')

    self.assertIsInstance(foo_product_mapping1, Products.ProductMapping)
    self.assertIs(foo_product_mapping1, foo_product_mapping2)

  def test_get_does_not_require(self):
    self.assertFalse(self.products.isrequired('foo'))
    self.products.get('foo')
    self.assertFalse(self.products.isrequired('foo'))
    self.products.require('foo')
    self.assertTrue(self.products.isrequired('foo'))

  def test_require_data(self):
    self.products.require_data('foo')

    self.assertTrue(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

    # require_data should not cross-contaminate require
    self.assertFalse(self.products.isrequired('foo'))
    self.assertFalse(self.products.isrequired('bar'))

  def test_get_data(self):
    self.assertIsNone(self.products.get_data('foo'))

    data1 = self.products.get_data('foo', dict)
    data2 = self.products.get_data('foo', dict)

    self.assertIsInstance(data1, dict)
    self.assertIs(data1, data2)

  def test_get_data_does_not_require_data(self):
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.get_data('foo')
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.require_data('foo')
    self.assertTrue(self.products.is_required_data('foo'))

  def test_register_data(self):
    data = {}
    self.assertIs(data, self.products.register_data('foo', data))
    with self.assertRaises(ProductError):
      self.products.register_data('foo', data)

  def test_empty_products(self):
    foo_product_mapping = self.products.get('foo')
    self.assertFalse(foo_product_mapping)

  @contextmanager
  def add_products(self, context_products, product_type, target, *products):
    product_mapping = context_products.get(product_type)
    with temporary_dir() as outdir:
      def create_product(product):
        with safe_open(os.path.join(outdir, product), mode='w') as fp:
          fp.write(product)
        return product
      product_mapping.add(target, outdir, [create_product(product) for product in products])
      yield temporary_dir

  def test_non_empty_products(self):
    target = self.make_target('c')
    with self.add_products(self.products, 'foo', target, 'a.class'):
      foo_product_mapping = self.products.get('foo')
      self.assertTrue(foo_product_mapping)

  def test_empty_data(self):
    foo_product_mapping = self.products.get_data('foo')
    self.assertFalse(foo_product_mapping)

  @contextmanager
  def add_data(self, context_products, data_type, target, *products):
    make_products = lambda: defaultdict(MultipleRootedProducts)
    data_by_target = context_products.get_data(data_type, make_products)
    with temporary_dir() as outdir:
      def create_product(product):
        abspath = os.path.join(outdir, product)
        with safe_open(abspath, mode='w') as fp:
          fp.write(product)
        return abspath
      data_by_target[target].add_abs_paths(outdir, [create_product(product) for product in products])
      yield temporary_dir

  def test_non_empty_data(self):
    target = self.make_target('c')
    with self.add_data(self.products, 'foo', target, 'a.class'):
      foo_product_mapping = self.products.get_data('foo')
      self.assertTrue(foo_product_mapping)
Beispiel #14
0
class ProductsTest(BaseTest):
    def setUp(self):
        super(ProductsTest, self).setUp()
        self.products = Products()

    def test_require(self):
        self.products.require('foo')

        self.assertTrue(self.products.isrequired('foo'))
        self.assertFalse(self.products.isrequired('bar'))

        # require should not cross-contaminate require_data
        self.assertFalse(self.products.is_required_data('foo'))
        self.assertFalse(self.products.is_required_data('bar'))

    def test_get(self):
        foo_product_mapping1 = self.products.get('foo')
        foo_product_mapping2 = self.products.get('foo')

        self.assertIsInstance(foo_product_mapping1, Products.ProductMapping)
        self.assertIs(foo_product_mapping1, foo_product_mapping2)

    def test_get_does_not_require(self):
        self.assertFalse(self.products.isrequired('foo'))
        self.products.get('foo')
        self.assertFalse(self.products.isrequired('foo'))
        self.products.require('foo')
        self.assertTrue(self.products.isrequired('foo'))

    def test_require_data(self):
        self.products.require_data('foo')

        self.assertTrue(self.products.is_required_data('foo'))
        self.assertFalse(self.products.is_required_data('bar'))

        # require_data should not cross-contaminate require
        self.assertFalse(self.products.isrequired('foo'))
        self.assertFalse(self.products.isrequired('bar'))

    def test_get_data(self):
        self.assertIsNone(self.products.get_data('foo'))

        data1 = self.products.get_data('foo', dict)
        data2 = self.products.get_data('foo', dict)

        self.assertIsInstance(data1, dict)
        self.assertIs(data1, data2)

    def test_get_data_does_not_require_data(self):
        self.assertFalse(self.products.is_required_data('foo'))
        self.products.get_data('foo')
        self.assertFalse(self.products.is_required_data('foo'))
        self.products.require_data('foo')
        self.assertTrue(self.products.is_required_data('foo'))

    def test_empty_products(self):
        foo_product_mapping = self.products.get('foo')
        self.assertFalse(foo_product_mapping)

    def test_non_empty_products(self):
        target = self.make_target('c')
        with self.add_products(self.products, 'foo', target, 'a.class'):
            foo_product_mapping = self.products.get('foo')
            self.assertTrue(foo_product_mapping)

    def test_empty_data(self):
        foo_product_mapping = self.products.get_data('foo')
        self.assertFalse(foo_product_mapping)

    def test_non_empty_data(self):
        target = self.make_target('c')
        with self.add_data(self.products, 'foo', target, 'a.class'):
            foo_product_mapping = self.products.get_data('foo')
            self.assertTrue(foo_product_mapping)
Beispiel #15
0
 def setUp(self):
   self.products = Products()
Beispiel #16
0
class ProductsTest(unittest.TestCase):
  def setUp(self):
    self.products = Products()

  def test_require(self):
    self.products.require('foo')

    predicate = self.products.isrequired('foo')
    self.assertIsNotNone(predicate)
    self.assertFalse(predicate(42))

    self.assertIsNone(self.products.isrequired('bar'))

    # require should not cross-contaminate require_data
    self.assertFalse(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

  def test_require_predicate(self):
    self.products.require('foo', predicate=lambda x: x == 42)

    predicate = self.products.isrequired('foo')
    self.assertIsNotNone(predicate)
    self.assertTrue(predicate(42))
    self.assertFalse(predicate(0))

  def test_require_multiple_predicates(self):
    self.products.require('foo', predicate=lambda x: x == 1)
    self.products.require('foo', predicate=lambda x: x == 2)
    self.products.require('foo', predicate=lambda x: x == 3)

    predicate = self.products.isrequired('foo')
    self.assertIsNotNone(predicate)
    self.assertFalse(predicate(0))
    self.assertTrue(predicate(1))
    self.assertTrue(predicate(2))
    self.assertTrue(predicate(3))
    self.assertFalse(predicate(4))

  def test_get(self):
    foo_product_mapping1 = self.products.get('foo')
    foo_product_mapping2 = self.products.get('foo')

    self.assertIsInstance(foo_product_mapping1, Products.ProductMapping)
    self.assertIs(foo_product_mapping1, foo_product_mapping2)

  def test_get_does_not_require(self):
    self.assertIsNone(self.products.isrequired('foo'))
    self.products.get('foo')
    self.assertIsNone(self.products.isrequired('foo'))
    self.products.require('foo')
    self.assertIsNotNone(self.products.isrequired('foo'))

  def test_require_data(self):
    self.products.require_data('foo')

    self.assertTrue(self.products.is_required_data('foo'))
    self.assertFalse(self.products.is_required_data('bar'))

    # require_data should not cross-contaminate require
    self.assertIsNone(self.products.isrequired('foo'))
    self.assertIsNone(self.products.isrequired('bar'))

  def test_get_data(self):
    self.assertIsNone(self.products.get_data('foo'))

    data1 = self.products.get_data('foo', dict)
    data2 = self.products.get_data('foo', dict)

    self.assertIsInstance(data1, dict)
    self.assertIs(data1, data2)

  def test_get_data_does_not_require_data(self):
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.get_data('foo')
    self.assertFalse(self.products.is_required_data('foo'))
    self.products.require_data('foo')
    self.assertTrue(self.products.is_required_data('foo'))