예제 #1
0
  def setUp(self):
    self.work_dir = safe_mkdtemp()
    self.addCleanup(safe_rmtree, self.work_dir)
    self.build_root = os.path.join(self.work_dir, 'build_root')
    shutil.copytree(os.path.join(os.path.dirname(__file__), 'examples/mapper_test'),
                    self.build_root)

    subjects = Subjects()
    self._goal = 'list'
    symbol_table_cls = TargetTable

    project_tree_key = subjects.put(
        FileSystemProjectTree(self.build_root))
    address_mapper_key = subjects.put(
        AddressMapper(symbol_table_cls=symbol_table_cls,
                      parser_cls=JsonParser,
                      build_pattern=r'.+\.BUILD.json$'))
    tasks = (
        create_fs_tasks(project_tree_key) +
        create_graph_tasks(address_mapper_key, symbol_table_cls)
      )
    self.scheduler = LocalScheduler({self._goal: UnhydratedStruct},
                                    tasks,
                                    subjects,
                                    symbol_table_cls)

    self.a_b = Address.parse('a/b')
    self.a_b_target = Target(name='b',
                             dependencies=['//d:e'],
                             configurations=['//a', Struct(embedded='yes')],
                             type_alias='target')
예제 #2
0
  def create(self, build_pattern=None, parser_cls=None, inline=False):
    subjects = Subjects()
    symbol_table_cls = TestTable

    project_tree_key = subjects.put(
        FileSystemProjectTree(self._build_root))
    address_mapper_key = subjects.put(
        AddressMapper(symbol_table_cls=symbol_table_cls,
                      build_pattern=build_pattern,
                      parser_cls=parser_cls))

    tasks = (
        create_fs_tasks(project_tree_key) +
        create_graph_tasks(address_mapper_key, symbol_table_cls)
      )
    return LocalScheduler(dict(),
                          tasks,
                          subjects,
                          symbol_table_cls)
예제 #3
0
def setup_json_scheduler(build_root, debug=True):
  """Return a build graph and scheduler configured for BLD.json files under the given build root.

  :rtype :class:`pants.engine.exp.scheduler.LocalScheduler`
  """
  subjects = Subjects(debug=debug)
  symbol_table_cls = ExampleTable

  # Register "literal" subjects required for these tasks.
  # TODO: Replace with `Subsystems`.
  project_tree_key = subjects.put(
      FileSystemProjectTree(build_root))
  address_mapper_key = subjects.put(
      AddressMapper(symbol_table_cls=symbol_table_cls,
                    build_pattern=r'^BLD.json$',
                    parser_cls=JsonParser))
  source_roots_key = subjects.put(
      SourceRoots(('src/java',)))
  scrooge_tool_address_key = subjects.put(
      Address.parse('src/scala/scrooge'))

  goals = {
      'compile': Classpath,
      # TODO: to allow for running resolve alone, should split out a distinct 'IvyReport' product.
      'resolve': Classpath,
      'list': Address,
      'walk': Path,
      GenGoal.name(): GenGoal,
      'unpickleable': UnpickleableResult,
    }
  tasks = [
      # Codegen
      GenGoal.signature(),
      (JavaSources,
       [Select(ThriftSources),
        SelectVariant(ApacheThriftJavaConfiguration, 'thrift')],
       gen_apache_thrift),
      (PythonSources,
       [Select(ThriftSources),
        SelectVariant(ApacheThriftPythonConfiguration, 'thrift')],
       gen_apache_thrift),
      (ScalaSources,
       [Select(ThriftSources),
        SelectVariant(ScroogeScalaConfiguration, 'thrift'),
        SelectLiteral(scrooge_tool_address_key, Classpath)],
       gen_scrooge_thrift),
      (JavaSources,
       [Select(ThriftSources),
        SelectVariant(ScroogeJavaConfiguration, 'thrift'),
        SelectLiteral(scrooge_tool_address_key, Classpath)],
       gen_scrooge_thrift),
    ] + [
      # scala dependency inference
      (ScalaSources,
       [Select(ScalaInferredDepsSources),
        SelectDependencies(Address, ImportedJVMPackages)],
       reify_scala_sources),
      (ImportedJVMPackages,
       [SelectProjection(FilesContent, PathGlobs, ('path_globs',), ScalaInferredDepsSources)],
       extract_scala_imports),
      (Address,
       [Select(JVMPackageName),
        SelectDependencies(AddressFamily, Paths)],
       select_package_address),
      (Paths,
       [Select(JVMPackageName),
        SelectLiteral(source_roots_key, SourceRoots)],
       calculate_package_search_path),
    ] + [
      # Remote dependency resolution
      (Classpath,
       [Select(Jar)],
       ivy_resolve),
      (Jar,
       [Select(ManagedJar),
        SelectVariant(ManagedResolve, 'resolve')],
       select_rev),
    ] + [
      # Compilers
      (Classpath,
       [Select(ResourceSources)],
       isolate_resources),
      (Classpath,
       [Select(BuildPropertiesConfiguration)],
       write_name_file),
      (Classpath,
       [Select(JavaSources),
        SelectDependencies(Classpath, JavaSources)],
       javac),
      (Classpath,
       [Select(ScalaSources),
        SelectDependencies(Classpath, ScalaSources)],
       scalac),
    ] + [
      # TODO
      (UnpickleableOutput,
        [],
        unpickleable_output),
      (UnpickleableResult,
       [Select(UnpickleableOutput)],
       unpickleable_input),
    ] + (
      create_graph_tasks(address_mapper_key, symbol_table_cls)
    ) + (
      create_fs_tasks(project_tree_key)
    )

  scheduler = LocalScheduler(goals, tasks, subjects, symbol_table_cls)
  return scheduler