Exemplo n.º 1
0
def create_graph_tasks(address_mapper, symbol_table_cls):
    """Creates tasks used to parse Structs from BUILD files.

  :param address_mapper_key: The subject key for an AddressMapper instance.
  :param symbol_table_cls: A SymbolTable class to provide symbols for Address lookups.
  """
    symbol_table_constraint = symbol_table_cls.constraint()
    return [
        # Support for resolving Structs from Addresses
        (symbol_table_constraint, [
            Select(UnhydratedStruct),
            SelectDependencies(symbol_table_constraint,
                               UnhydratedStruct,
                               field_types=(Address, ))
        ], hydrate_struct),
        (UnhydratedStruct, [
            SelectProjection(AddressFamily, Dir, ('spec_path', ), Address),
            Select(Address)
        ], resolve_unhydrated_struct),
    ] + [
        # BUILD file parsing.
        (AddressFamily, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(Dir),
            SelectProjection(FilesContent, Files, ('files', ), BuildFiles)
        ], parse_address_family),
        (BuildFiles, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(DirectoryListing)
        ], filter_buildfile_paths),
    ] + [
        # Simple spec handling.
        (Addresses, [
            SelectProjection(AddressFamily, Dir,
                             ('directory', ), SingleAddress),
            Select(SingleAddress)
        ], address_from_address_family),
        (Addresses, [
            SelectProjection(AddressFamily, Dir,
                             ('directory', ), SiblingAddresses)
        ], addresses_from_address_family),
    ] + [
        # Recursive spec handling: locate directories that contain build files, and request
        # AddressFamilies for each of them.
        (Addresses, [
            SelectDependencies(AddressFamily, BuildDirs, field_types=(Dir, ))
        ], addresses_from_address_families),
        (BuildDirs,
         [SelectLiteral(address_mapper, AddressMapper),
          Select(Files)], filter_build_dirs),
        (PathGlobs, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(DescendantAddresses)
        ], descendant_addresses_to_globs),
        (PathGlobs, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(AscendantAddresses)
        ], ascendant_addresses_to_globs),
    ]
Exemplo n.º 2
0
def create_graph_tasks(address_mapper, symbol_table_cls):
    """Creates tasks used to parse Structs from BUILD files.

  :param address_mapper_key: The subject key for an AddressMapper instance.
  :param symbol_table_cls: A SymbolTable class to provide symbols for Address lookups.
  """
    return [
        # Support for resolving Structs from Addresses
        (Struct, [
            Select(UnhydratedStruct),
            SelectDependencies(Struct, UnhydratedStruct)
        ], hydrate_struct),
        (UnhydratedStruct, [
            SelectProjection(AddressFamily, Dir, ('spec_path', ), Address),
            Select(Address)
        ], resolve_unhydrated_struct),
    ] + [
        # BUILD file parsing.
        (AddressFamily, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(Dir),
            SelectProjection(FilesContent, Files, ('files', ), BuildFiles)
        ], parse_address_family),
        (BuildFiles, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(DirectoryListing)
        ], filter_buildfile_paths),
    ] + [
        # Addresses for user-defined products might possibly be resolvable from BLD files. These tasks
        # define that lookup for each literal product.
        (product, [Select(Struct)], identity)
        for product in symbol_table_cls.table().values()
        if product is not Struct
    ] + [
        # Simple spec handling.
        (Addresses, [
            SelectProjection(AddressFamily, Dir,
                             ('directory', ), SingleAddress),
            Select(SingleAddress)
        ], address_from_address_family),
        (Addresses, [
            SelectProjection(AddressFamily, Dir,
                             ('directory', ), SiblingAddresses)
        ], addresses_from_address_family),
    ] + [
        # Recursive spec handling: locate directories that contain build files, and request
        # AddressFamilies for each of them.
        (Addresses, [SelectDependencies(AddressFamily, BuildDirs)
                     ], addresses_from_address_families),
        (BuildDirs, [Select(Files)], filter_build_dirs),
        (PathGlobs, [
            SelectLiteral(address_mapper, AddressMapper),
            Select(DescendantAddresses)
        ], descendant_addresses_to_globs),
    ]
Exemplo n.º 3
0
  def test_select_literal(self):
    literally_a = A()
    rules = [
      (B, (SelectLiteral(literally_a, A),), noop)
    ]

    graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
      root_subject_fns=_suba_root_subject_fns)
    subgraph = graphmaker.generate_subgraph(SubA(), requested_product=B)

    self.assert_equal_with_printing(dedent("""
                               {
                                 root_subject_types: (SubA,)
                                 root_rules: (B, (SelectLiteral(A(), A),), noop) of SubA
                                 (B, (SelectLiteral(A(), A),), noop) of SubA => (Literal(A(), A),)
                               }""").strip(), subgraph)
Exemplo n.º 4
0
  def test_select_literal(self):
    literally_a = A()
    rules = [
      (B, (SelectLiteral(literally_a, A),), noop)
    ]

    subgraph = self.create_subgraph(B, rules, SubA())

    self.assert_equal_with_printing(dedent("""
                     digraph {
                       // root subject types: SubA
                       // root entries
                         "Select(B) for SubA" [color=blue]
                         "Select(B) for SubA" -> {"(B, (SelectLiteral(A(), A),), noop) of SubA"}
                       // internal entries
                         "(B, (SelectLiteral(A(), A),), noop) of SubA" -> {"Literal(A(), A)"}
                     }""").strip(),
      subgraph)
Exemplo n.º 5
0
  def test_javac_compilation_example(self):
    sources = PathGlobs.create('', include=['scheduler_inputs/src/java/simple/Simple.java'])

    scheduler = self.mk_scheduler_in_example_fs([
      SnapshottedProcess.create(ClasspathEntry,
                                Javac,
                                (Select(Snapshot), SelectLiteral(JavaOutputDir('build'), JavaOutputDir)),
                                java_sources_to_javac_args,
                                process_result_to_classpath_entry),
      [Javac, [], Javac]
    ])

    request = scheduler.execution_request(
      [ClasspathEntry],
      [sources])
    LocalSerialEngine(scheduler).reduce(request)

    root_entries = scheduler.root_entries(request).items()
    self.assertEquals(1, len(root_entries))
    state = self.assertFirstEntryIsReturn(root_entries, scheduler)
    classpath_entry = state.value
    self.assertIsInstance(classpath_entry, ClasspathEntry)
    self.assertTrue(os.path.exists(os.path.join(classpath_entry.path, 'simple', 'Simple.class')))
Exemplo n.º 6
0
def setup_json_scheduler(build_root, native):
  """Return a build graph and scheduler configured for BLD.json files under the given build root.

  :rtype :class:`pants.engine.scheduler.LocalScheduler`
  """

  symbol_table_cls = ExampleTable

  # Register "literal" subjects required for these tasks.
  # TODO: Replace with `Subsystems`.
  address_mapper = AddressMapper(symbol_table_cls=symbol_table_cls,
                                 build_patterns=('BLD.json',),
                                 parser_cls=JsonParser)
  source_roots = SourceRoots(('src/java','src/scala'))
  scrooge_tool_address = 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,
      GenGoal.name(): GenGoal,
      'ls': Files,
      'cat': FilesContent,
    }
  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, Classpath)],
       gen_scrooge_thrift),
      (JavaSources,
       [Select(ThriftSources),
        SelectVariant(ScroogeJavaConfiguration, 'thrift'),
        SelectLiteral(scrooge_tool_address, Classpath)],
       gen_scrooge_thrift),
    ] + [
      # scala dependency inference
      (ScalaSources,
       [Select(ScalaInferredDepsSources),
        SelectDependencies(Address, ImportedJVMPackages, field_types=(JVMPackageName,))],
       reify_scala_sources),
      (ImportedJVMPackages,
       [SelectProjection(FilesContent, PathGlobs, ('path_globs',), ScalaInferredDepsSources)],
       extract_scala_imports),
      (Address,
       [Select(JVMPackageName),
        SelectDependencies(AddressFamily, Dirs, field='stats', field_types=(Dir,))],
       select_package_address),
      (PathGlobs,
       [Select(JVMPackageName),
        SelectLiteral(source_roots, 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),
      # NB: Not sure these SelectDependencies should allow Jar, but they currently produce jars.
      (Classpath,
       [Select(JavaSources),
        SelectDependencies(Classpath, JavaSources, field_types=(Address, Jar))],
       javac),
      (Classpath,
       [Select(ScalaSources),
        SelectDependencies(Classpath, ScalaSources, field_types=(Address, Jar))],
       scalac),
    ] + (
      create_graph_tasks(address_mapper, symbol_table_cls)
    ) + (
      create_fs_tasks()
    )

  project_tree = FileSystemProjectTree(build_root)
  return LocalScheduler(goals,
                        tasks,
                        project_tree,
                        native,
                        graph_lock=None)
Exemplo n.º 7
0
 def test_select_literal(self):
     self.assert_repr("SelectLiteral(None, AClass)",
                      SelectLiteral(None, AClass))