Bug 853045 - Part 2: Add frontend and RecursiveMakeBackend for Android Eclipse projects. r=gps

This commit is contained in:
Nick Alexander 2014-02-13 22:19:49 -08:00
Родитель 8f1f977233
Коммит 33ec9e8af1
5 изменённых файлов: 153 добавлений и 1 удалений

Просмотреть файл

@ -23,6 +23,7 @@ import mozpack.path as mozpath
from .common import CommonBackend
from ..frontend.data import (
AndroidEclipseProjectData,
ConfigFileSubstitution,
Defines,
DirectoryTraversal,
@ -452,6 +453,8 @@ class RecursiveMakeBackend(CommonBackend):
# automated.
if isinstance(obj.wrapped, JavaJarData):
self._process_java_jar_data(obj.wrapped, backend_file)
elif isinstance(obj.wrapped, AndroidEclipseProjectData):
self._process_android_eclipse_project_data(obj.wrapped, backend_file)
else:
return
@ -1097,6 +1100,28 @@ class RecursiveMakeBackend(CommonBackend):
backend_file.write('%s_JAVAC_FLAGS := %s\n' %
(target, ' '.join(jar.javac_flags)))
def _process_android_eclipse_project_data(self, project, backend_file):
# We add a single target to the backend.mk corresponding to
# the moz.build defining the Android Eclipse project. This
# target depends on some targets to be fresh, and installs a
# manifest generated by the Android Eclipse build backend. The
# manifests for all projects live in $TOPOBJDIR/android_eclipse
# and are installed into subdirectories thereof.
project_directory = mozpath.join(self.environment.topobjdir, 'android_eclipse', project.name)
manifest_path = mozpath.join(self.environment.topobjdir, 'android_eclipse', '%s.manifest' % project.name)
fragment = Makefile()
rule = fragment.create_rule(targets=['ANDROID_ECLIPSE_PROJECT_%s' % project.name])
rule.add_dependencies(project.recursive_make_targets)
args = ['--no-remove',
'--no-remove-all-directory-symlinks',
'--no-remove-empty-directories',
project_directory,
manifest_path]
rule.add_commands(['$(call py_action,process_install_manifest,%s)' % ' '.join(args)])
fragment.dump(backend_file.fh, removal_guard=False)
def _process_library_definition(self, libdef, backend_file):
backend_file.write('LIBRARY_NAME = %s\n' % libdef.basename)
thisobjdir = libdef.objdir

Просмотреть файл

@ -557,3 +557,64 @@ class InstallationTarget(SandboxDerived):
return FinalTargetValue(dict(
XPI_NAME=self.xpiname,
DIST_SUBDIR=self.subdir)) == self.target
class ClassPathEntry(object):
"""Represents a classpathentry in an Android Eclipse project."""
__slots__ = (
'dstdir',
'srcdir',
'path',
'exclude_patterns',
'ignore_warnings',
)
def __init__(self):
self.dstdir = None
self.srcdir = None
self.path = None
self.exclude_patterns = []
self.ignore_warnings = False
class AndroidEclipseProjectData(object):
"""Represents an Android Eclipse project."""
__slots__ = (
'name',
'package_name',
'is_library',
'res',
'assets',
'libs',
'manifest',
'recursive_make_targets',
'extra_jars',
'included_projects',
'referenced_projects',
'_classpathentries',
)
def __init__(self, name):
self.name = name
self.is_library = False
self.manifest = None
self.res = None
self.assets = None
self.libs = []
self.recursive_make_targets = []
self.extra_jars = []
self.included_projects = []
self.referenced_projects = []
self._classpathentries = []
def add_classpathentry(self, path, srcdir, dstdir, exclude_patterns=[], ignore_warnings=False):
cpe = ClassPathEntry()
cpe.srcdir = srcdir
cpe.dstdir = dstdir
cpe.path = path
cpe.exclude_patterns = list(exclude_patterns)
cpe.ignore_warnings = ignore_warnings
self._classpathentries.append(cpe)
return cpe

Просмотреть файл

@ -421,6 +421,9 @@ class TreeMetadataEmitter(LoggingMixin):
for name, jar in sandbox.get('JAVA_JAR_TARGETS', {}).items():
yield SandboxWrapped(sandbox, jar)
for name, data in sandbox.get('ANDROID_ECLIPSE_PROJECT_TARGETS', {}).items():
yield SandboxWrapped(sandbox, data)
if passthru.variables:
yield passthru

Просмотреть файл

@ -44,6 +44,7 @@ from mozpack.files import FileFinder
import mozpack.path as mozpath
from .data import (
AndroidEclipseProjectData,
JavaJarData,
)
@ -244,13 +245,41 @@ class MozbuildSandbox(Sandbox):
raise Exception('Java JAR names must not include slashes or'
' .jar: %s' % name)
if self['JAVA_JAR_TARGETS'].has_key(name):
if name in self['JAVA_JAR_TARGETS']:
raise Exception('Java JAR has already been registered: %s' % name)
jar = JavaJarData(name)
self['JAVA_JAR_TARGETS'][name] = jar
return jar
# Not exposed to the sandbox.
def add_android_eclipse_project_helper(self, name):
"""Add an Android Eclipse project target."""
if not name:
raise Exception('Android Eclipse project cannot be registered without a name')
if name in self['ANDROID_ECLIPSE_PROJECT_TARGETS']:
raise Exception('Android Eclipse project has already been registered: %s' % name)
data = AndroidEclipseProjectData(name)
self['ANDROID_ECLIPSE_PROJECT_TARGETS'][name] = data
return data
def _add_android_eclipse_project(self, name, manifest):
if not manifest:
raise Exception('Android Eclipse project must specify a manifest')
data = self.add_android_eclipse_project_helper(name)
data.manifest = manifest
data.is_library = False
return data
def _add_android_eclipse_library_project(self, name):
data = self.add_android_eclipse_project_helper(name)
data.manifest = None
data.is_library = True
return data
def _add_tier_directory(self, tier, reldir, static=False, external=False):
"""Register a tier directory with the build."""
if isinstance(reldir, text_type):

Просмотреть файл

@ -77,6 +77,13 @@ VARIABLES = {
directory and merge into an APK file.
""", 'export'),
'ANDROID_ECLIPSE_PROJECT_TARGETS': (dict, dict,
"""Defines Android Eclipse project targets.
This variable should not be populated directly. Instead, it should
populated by calling add_android_eclipse{_library}_project().
""", 'export'),
'SOURCES': (StrictOrderingOnAppendListWithFlagsFactory({'no_pgo': bool}), list,
"""Source code files.
@ -726,6 +733,33 @@ FUNCTIONS = {
:py:class:`mozbuild.frontend.data.JavaJarData`.
"""),
'add_android_eclipse_project': ('_add_android_eclipse_project', (str, str),
"""Declare an Android Eclipse project.
This is one of the supported ways to populate the
ANDROID_ECLIPSE_PROJECT_TARGETS variable.
The parameters are:
* name - project name.
* manifest - path to AndroidManifest.xml.
This returns a rich Android Eclipse project type, described at
:py:class:`mozbuild.frontend.data.AndroidEclipseProjectData`.
"""),
'add_android_eclipse_library_project': ('_add_android_eclipse_library_project', (str,),
"""Declare an Android Eclipse library project.
This is one of the supported ways to populate the
ANDROID_ECLIPSE_PROJECT_TARGETS variable.
The parameters are:
* name - project name.
This returns a rich Android Eclipse project type, described at
:py:class:`mozbuild.frontend.data.AndroidEclipseProjectData`.
"""),
'add_tier_dir': ('_add_tier_directory', (str, [str, list], bool, bool),
"""Register a directory for tier traversal.