示例#1
0
    def generate_targets_map(self, targets, runtime_classpath, zinc_args_for_all_targets):
        """Generates a dictionary containing all pertinent information about the target graph.

        The return dictionary is suitable for serialization by json.dumps.
        :param all_targets: The list of targets to generate the map for.
        :param runtime_classpath: ClasspathProducts containing entries for all the resolved and compiled
          dependencies.
        :param zinc_args_for_all_targets: Map from zinc compiled targets to the args used to compile them.
        """
        all_targets = self._get_all_targets(targets)
        libraries_map = self._resolve_jars_info(all_targets, runtime_classpath)

        targets_map = {}
        resource_target_map = {}

        for t in all_targets:
            for dep in t.dependencies:
                if isinstance(dep, Resources):
                    resource_target_map[dep] = t

        modulizable_targets = self._get_targets_to_make_into_modules(
            resource_target_map, runtime_classpath
        )
        non_modulizable_targets = all_targets.difference(modulizable_targets)

        for t in non_modulizable_targets:
            libraries_map[t.id] = self._make_libraries_entry(
                t, resource_target_map, runtime_classpath
            )

        flat_non_modulizable_deps_for_modulizable_targets: Dict[
            Target, FrozenOrderedSet[Target]
        ] = self._flat_non_modulizable_deps_for_modulizable_targets(modulizable_targets)

        for target in modulizable_targets:
            zinc_args_for_target = zinc_args_for_all_targets.get(target)
            if zinc_args_for_target is None:
                if not ZincCompile.select(target):
                    # Targets that weren't selected by ZincCompile also wont have zinc args.
                    zinc_args_for_target = []
                else:
                    raise TaskError(
                        f"There was an error exporting target {target} - There were no zinc arguments registered for it"
                    )
            info = self._process_target(
                target,
                modulizable_targets,
                resource_target_map,
                runtime_classpath,
                zinc_args_for_target,
                flat_non_modulizable_deps_for_modulizable_targets,
            )
            targets_map[target.address.spec] = info

        graph_info = self.initialize_graph_info()
        graph_info["targets"] = targets_map
        graph_info["libraries"] = libraries_map

        return graph_info