// Copyright 2015 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.rules.android; import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.Type.BOOLEAN; import static com.google.devtools.build.lib.packages.Type.LABEL; import static com.google.devtools.build.lib.packages.Type.LABEL_LIST; import static com.google.devtools.build.lib.packages.Type.STRING; import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.AndroidAaptBaseRule; import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.AndroidBaseRule; import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.AndroidResourceSupportRule; import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider; import com.google.devtools.build.lib.rules.java.JavaSemantics; /** * Rule definition for the android_library rule. */ public final class AndroidLibraryBaseRule implements RuleDefinition { @Override public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) { return builder /* The list of source files that are processed to create the target. ${SYNOPSIS}
srcs
files of type .java
are compiled.
For readability's sake, it is not good to put the name of a
generated .java
source file into the srcs
.
Instead, put the depended-on rule name in the srcs
, as
described below.
srcs
files of type .srcjar
are unpacked and
compiled. (This is useful if you need to generate a set of .java files with
a genrule or build extension.)
This rule currently forces source and class compatibility with Java 7, although try with resources is not supported.
srcs
files of type .jar
are linked in.
(This is useful if you have third-party .jar
files
with no source.)
If srcs
is omitted, then any dependency specified in
deps
is exported from this rule (see
java_library's exports for more
information about exporting dependencies). However, this behavior will be
deprecated soon; try not to rely on it.
android_library
,
java_library
with android
constraint and
cc_library
wrapping or producing .so
native libraries
for the Android target platform.
*/
.override(builder.copy("deps")
.allowedRuleClasses(AndroidRuleClasses.ALLOWED_DEPENDENCIES)
.allowedFileTypes())
/*
The android_resources
target assigned to this library.
${SYNOPSIS}
If specified, the resources will be added to any android_binary
depending on this library.
Only an android_resource
rule with the attribute
inline_constants
set to 0 can be used in this case.
neverlink
will not be used in
.apk
creation. Useful if the library will be provided by the
runtime environment during execution.
*/
.add(attr("neverlink", BOOLEAN).value(false))
/*
Package-relative path to the root of the java package tree containing idl
sources included in this library.
${SYNOPSIS}
This path will be used as the import root when processing idl sources that
depend on this library. (See
examples.)
*/
.add(attr("idl_import_root", STRING))
/*
List of Android IDL definitions to translate to Java interfaces.
${SYNOPSIS}
After the Java interfaces are generated, they will be compiled together
with the contents of srcs
.
These files will be made available as imports for any
android_library
target that depends on this library, directly
or via its transitive closure.
android_library
target that depends on this library, directly
or via its transitive closure, but will not be translated to Java
or compiled.
Only .aidl
files that correspond directly to
.java
sources in this library should be included (e.g., custom
implementations of Parcelable), otherwise idl_srcs
should be
used.
android_binary
target depending on this library.
The files included here must only have idempotent rules, namely -dontnote, -dontwarn,
assumenosideeffects, and rules that start with -keep. Other options can only appear in
android_binary
's proguard_specs, to ensure non-tautological merges.
*/
.add(attr("proguard_specs", LABEL_LIST).legacyAllowAnyFileType())
.add(attr("$proguard_whitelister", LABEL).cfg(HOST).exec().value(
new Attribute.ComputedDefault() {
@Override
public Object getDefault(AttributeMap rule) {
return rule.isAttributeValueExplicitlySpecified("proguard_specs")
? env.getLabel(Constants.ANDROID_DEP_PREFIX + "proguard_whitelister")
: null;
}
}))
.add(attr("$android_manifest_merge_tool", LABEL).cfg(HOST).exec().value(env.getLabel(
AndroidRuleClasses.MANIFEST_MERGE_TOOL_LABEL)))
.advertiseProvider(JavaCompilationArgsProvider.class)
.build();
}
@Override
public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
.name("$android_library_base")
.type(RuleClassType.ABSTRACT)
.ancestors(
AndroidBaseRule.class,
AndroidAaptBaseRule.class,
AndroidResourceSupportRule.class)
.build();
}
}