示例#1
0
  def setUp(self):
    super(BaseTest, self).setUp()
    Goal.clear()
    Subsystem.reset()

    self.real_build_root = BuildRoot().path

    self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
    self.addCleanup(safe_rmtree, self.build_root)

    self.pants_workdir = os.path.join(self.build_root, '.pants.d')
    safe_mkdir(self.pants_workdir)

    self.options = defaultdict(dict)  # scope -> key-value mapping.
    self.options[''] = {
      'pants_workdir': self.pants_workdir,
      'pants_supportdir': os.path.join(self.build_root, 'build-support'),
      'pants_distdir': os.path.join(self.build_root, 'dist'),
      'pants_configdir': os.path.join(self.build_root, 'config'),
      'cache_key_gen_version': '0-test',
    }

    BuildRoot().path = self.build_root
    self.addCleanup(BuildRoot().reset)

    # We need a pants.ini, even if empty. get_buildroot() uses its presence.
    self.create_file('pants.ini')
    self._build_configuration = BuildConfiguration()
    self._build_configuration.register_aliases(self.alias_groups)
    self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root)
    self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
    self.build_graph = BuildGraph(address_mapper=self.address_mapper)
示例#2
0
文件: base_test.py 项目: rkstap/pants
 def reset_build_graph(self):
     """Start over with a fresh build graph with no targets in it."""
     self.address_mapper = BuildFileAddressMapper(
         self.build_file_parser,
         self.project_tree,
         build_ignore_patterns=self.build_ignore_patterns)
     self.build_graph = MutableBuildGraph(
         address_mapper=self.address_mapper)
示例#3
0
 def test_exclude_target_regexps(self):
     address_mapper_with_exclude = BuildFileAddressMapper(
         self.build_file_parser,
         self.project_tree,
         exclude_target_regexps=[r'.*:b.*'])
     self.assert_scanned(['::'],
                         expected=[':root', 'a', 'a/b:c'],
                         address_mapper=address_mapper_with_exclude)
示例#4
0
    def _init_graph(self,
                    use_engine,
                    pants_ignore_patterns,
                    build_ignore_patterns,
                    exclude_target_regexps,
                    target_specs,
                    workdir,
                    graph_helper=None,
                    subproject_build_roots=None):
        """Determine the BuildGraph, AddressMapper and spec_roots for a given run.

    :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph.
    :param list pants_ignore_patterns: The pants ignore patterns from '--pants-ignore'.
    :param list build_ignore_patterns: The build ignore patterns from '--build-ignore',
                                       applied during BUILD file searching.
    :param str workdir: The pants workdir.
    :param list exclude_target_regexps: Regular expressions for targets to be excluded.
    :param list target_specs: The original target specs.
    :param LegacyGraphHelper graph_helper: A LegacyGraphHelper to use for graph construction,
                                           if available. This would usually come from the daemon.
    :returns: A tuple of (BuildGraph, AddressMapper, opt Scheduler, spec_roots).
    """
        # N.B. Use of the daemon implies use of the v2 engine.
        if graph_helper or use_engine:
            # The daemon may provide a `graph_helper`. If that's present, use it for graph construction.
            if not graph_helper:
                native = Native.create(self._global_options)
                native.set_panic_handler()
                graph_helper = EngineInitializer.setup_legacy_graph(
                    pants_ignore_patterns,
                    workdir,
                    self._global_options.build_file_imports,
                    native=native,
                    build_file_aliases=self._build_config.registered_aliases(),
                    build_ignore_patterns=build_ignore_patterns,
                    exclude_target_regexps=exclude_target_regexps,
                    subproject_roots=subproject_build_roots,
                    include_trace_on_error=self._options.for_global_scope(
                    ).print_exception_stacktrace)

            target_roots = TargetRoots.create(
                options=self._options,
                build_root=self._root_dir,
                change_calculator=graph_helper.change_calculator)
            graph, address_mapper = graph_helper.create_build_graph(
                target_roots, self._root_dir)
            return graph, address_mapper, graph_helper.scheduler, target_roots.as_specs(
            )
        else:
            spec_roots = TargetRoots.parse_specs(target_specs, self._root_dir)
            address_mapper = BuildFileAddressMapper(
                self._build_file_parser,
                get_project_tree(self._global_options), build_ignore_patterns,
                exclude_target_regexps, subproject_build_roots)
            return MutableBuildGraph(
                address_mapper), address_mapper, None, spec_roots
  def test_build_ignore_patterns(self):
    expected_specs = [':root', 'a', 'a:b', 'a/b', 'a/b:c']

    # This bogus BUILD file gets in the way of parsing.
    self.add_to_build_file('some/dir', 'COMPLETELY BOGUS BUILDFILE)\n')
    with self.assertRaises(AddressLookupError):
      self.assert_scanned(['::'], expected=expected_specs)

    address_mapper_with_ignore = BuildFileAddressMapper(self.build_file_parser,
                                                        self.project_tree,
                                                        build_ignore_patterns=['some'])
    self.assert_scanned(['::'], expected=expected_specs, address_mapper=address_mapper_with_ignore)
示例#6
0
    def __init__(self,
                 root_dir,
                 options,
                 build_config,
                 run_tracker,
                 reporting,
                 exiter=sys.exit):
        """
    :param str root_dir: The root directory of the pants workspace (aka the "build root").
    :param Options options: The global, pre-initialized Options instance.
    :param BuildConfiguration build_config: A pre-initialized BuildConfiguration instance.
    :param Runtracker run_tracker: The global, pre-initialized/running RunTracker instance.
    :param Reporting reporting: The global, pre-initialized Reporting instance.
    :param func exiter: A function that accepts an exit code value and exits (for tests, Optional).
    """
        self._root_dir = root_dir
        self._options = options
        self._build_config = build_config
        self._run_tracker = run_tracker
        self._reporting = reporting
        self._exiter = exiter

        self._goals = []
        self._targets = []
        self._requested_goals = self._options.goals
        self._target_specs = self._options.target_specs
        self._help_request = self._options.help_request

        self._global_options = options.for_global_scope()
        self._tag = self._global_options.tag
        self._fail_fast = self._global_options.fail_fast
        # Will be provided through context.address_mapper.build_ignore_patterns.
        self._spec_excludes = None
        self._explain = self._global_options.explain
        self._kill_nailguns = self._global_options.kill_nailguns

        self._project_tree = self._get_project_tree(
            self._global_options.build_file_rev)
        self._build_file_parser = BuildFileParser(self._build_config,
                                                  self._root_dir)
        build_ignore_patterns = self._global_options.ignore_patterns or []
        build_ignore_patterns.extend(
            BuildFile._spec_excludes_to_gitignore_syntax(
                self._root_dir, self._global_options.spec_excludes))
        self._address_mapper = BuildFileAddressMapper(self._build_file_parser,
                                                      self._project_tree,
                                                      build_ignore_patterns)
        self._build_graph = BuildGraph(self._address_mapper)
        self._spec_parser = CmdLineSpecParser(
            self._root_dir,
            self._address_mapper,
            spec_excludes=self._spec_excludes,
            exclude_target_regexps=self._global_options.exclude_target_regexp)
    def test_build_ignore_patterns(self):
        expected_specs = [':root', 'a', 'a:b', 'a/b', 'a/b:c']

        # This bogus BUILD file gets in the way of parsing.
        self.add_to_build_file('some/dir', 'COMPLETELY BOGUS BUILDFILE)\n')
        with self.assertRaises(CmdLineSpecParser.BadSpecError):
            self.assert_parsed_list(cmdline_spec_list=['::'],
                                    expected=expected_specs)

        address_mapper_with_ignore = BuildFileAddressMapper(
            self.build_file_parser,
            self.project_tree,
            build_ignore_patterns=['some'])
        self.spec_parser = CmdLineSpecParser(self.build_root,
                                             address_mapper_with_ignore)
        self.assert_parsed_list(cmdline_spec_list=['::'],
                                expected=expected_specs)
示例#8
0
    def setUp(self):
        """
    :API: public
    """
        super(BaseTest, self).setUp()
        Goal.clear()
        Subsystem.reset()

        self.real_build_root = BuildRoot().path

        self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
        self.subprocess_dir = os.path.join(self.build_root, '.pids')
        self.addCleanup(safe_rmtree, self.build_root)

        self.pants_workdir = os.path.join(self.build_root, '.pants.d')
        safe_mkdir(self.pants_workdir)

        self.options = defaultdict(dict)  # scope -> key-value mapping.
        self.options[''] = {
            'pants_workdir': self.pants_workdir,
            'pants_supportdir': os.path.join(self.build_root, 'build-support'),
            'pants_distdir': os.path.join(self.build_root, 'dist'),
            'pants_configdir': os.path.join(self.build_root, 'config'),
            'pants_subprocessdir': self.subprocess_dir,
            'cache_key_gen_version': '0-test',
        }
        self.options['cache'] = {
            'read_from': [],
            'write_to': [],
        }

        BuildRoot().path = self.build_root
        self.addCleanup(BuildRoot().reset)

        self._build_configuration = BuildConfiguration()
        self._build_configuration.register_aliases(self.alias_groups)
        self.build_file_parser = BuildFileParser(self._build_configuration,
                                                 self.build_root)
        self.project_tree = FileSystemProjectTree(self.build_root)
        self.address_mapper = BuildFileAddressMapper(
            self.build_file_parser,
            self.project_tree,
            build_ignore_patterns=self.build_ignore_patterns)
        self.build_graph = MutableBuildGraph(
            address_mapper=self.address_mapper)
示例#9
0
 def reset_build_graph(self):
   """Start over with a fresh build graph with no targets in it."""
   self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
   self.build_graph = BuildGraph(address_mapper=self.address_mapper)
示例#10
0
 def reset_build_graph(self):
     """Start over with a fresh build graph with no targets in it."""
     self.address_mapper = BuildFileAddressMapper(
         self.build_file_parser, FileSystemProjectTree(self.build_root))
     self.build_graph = MutableBuildGraph(
         address_mapper=self.address_mapper)
示例#11
0
 def build_file_address_mapper(self):
     return BuildFileAddressMapper(self.build_file_parser,
                                   FileSystemProjectTree(self.build_root))
示例#12
0
 def build_file_address_mapper(self):
     return BuildFileAddressMapper(self.build_file_parser,
                                   FileSystemProjectTree(self.build_root),
                                   build_ignore_patterns=['subdir'])