This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add android_library target and unpack_library task
This review is part 1 of splitting review pantsbuild#2040. This adds android_library and android_dependency targets as well as an unpack_libraries task. This is not integrated with the rest of the android backend, that will be part 2. An android_dependency can be a jar or aar library artifact, in a repo or from the SDK. Those artifacts have to be unpacked and then repacked into the final android application. Each library is unpacked exactly once. The includes/excludes will be handled in the repacking. That keeps us from having to repeatedly unpack common dependencies. They all have a common base so this treats the unpacked source as this common starting point. If the library is an aar file, it needs to add targets to the graph based on the aar's contents, as seen in UnpackLibraries. The follow up will integrate the tasks/targets into the other tasks and finish up adding the testing harness. If you'd like to see how it runs or what the BUILD files will look like, you can check pantsbuild#2040. references pantsbuild#1390 Testing Done: Passes local ci.sh and travis. Bugs closed: 1800 Reviewed at https://rbcommons.com/s/twitter/r/2467/
- Loading branch information
Showing
27 changed files
with
793 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/python/pants/backend/android/targets/android_dependency.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
from pants.backend.jvm.targets.jar_library import JarLibrary | ||
|
||
|
||
class AndroidDependency(JarLibrary): | ||
"""A set of artifacts that may be depended upon by Android targets.""" |
57 changes: 57 additions & 0 deletions
57
src/python/pants/backend/android/targets/android_library.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import os | ||
|
||
from pants.backend.android.android_manifest_parser import AndroidManifestParser | ||
from pants.backend.android.targets.android_target import AndroidTarget | ||
from pants.backend.jvm.targets.import_jars_mixin import ImportJarsMixin | ||
from pants.base.payload import Payload | ||
from pants.base.payload_field import PrimitiveField | ||
from pants.util.memo import memoized_property | ||
|
||
|
||
class AndroidLibrary(ImportJarsMixin, AndroidTarget): | ||
"""Android library projects that access Android API or Android resources. | ||
""" | ||
def __init__(self, payload=None, libraries=None, | ||
include_patterns=None, exclude_patterns=None, **kwargs): | ||
""" | ||
:param list libraries: List of addresses of `android_dependency <#android_dependency>`_ | ||
targets. | ||
:param list include_patterns: fileset patterns to include from the archive | ||
:param list exclude_patterns: fileset patterns to exclude from the archive | ||
""" | ||
|
||
# TODO(mateor) Perhaps add a BUILD file attribute to force archive type: one of (jar, aar). | ||
payload = payload or Payload() | ||
payload.add_fields({ | ||
'library_specs': PrimitiveField(libraries or ()) | ||
}) | ||
self.libraries = libraries | ||
self.include_patterns = include_patterns or [] | ||
self.exclude_patterns = exclude_patterns or [] | ||
|
||
super(AndroidLibrary, self).__init__(payload=payload, **kwargs) | ||
|
||
@property | ||
def imported_jar_library_specs(self): | ||
"""List of JarLibrary specs to import. | ||
Required to implement the ImportJarsMixin. | ||
""" | ||
return self.payload.library_specs | ||
|
||
@memoized_property | ||
def manifest(self): | ||
"""The manifest of the AndroidLibrary, if one exists.""" | ||
# Libraries may not have a manifest, so self.manifest can be None for android_libraries. | ||
if self._manifest_file is None: | ||
return None | ||
else: | ||
manifest_path = os.path.join(self._spec_path, self._manifest_file) | ||
return AndroidManifestParser.parse_manifest(manifest_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.