Commit graph

86 commits

Author SHA1 Message Date
Colin Cross
094054ab07 Support main_class property in java_binary modules
Add a main_class property that will be used to generate a manifest
containing a Main-Class entry.

Test: m checkbuild
Change-Id: I0a59bb2b93cad915afd82fba708fa0f7eda2fe7a
2018-10-18 14:55:07 -07:00
Colin Cross
a4f08813a3 Add support for JNI libraries to android_app modules
Make android_app modules a MultiTargets module, which means the
common variant will have a list of Targets that it needs to handle.
Collect JNI libraries for each Target, and package them into or
alongside the APK.

Bug: 80095087
Test: app_test.go
Change-Id: Iabd3921e1d4c4b4cfcc7e131a0b0d9ab83b0ebbb
2018-10-08 15:20:56 -07:00
Colin Cross
1d98ee23a3 soong_zip: support globs in -f and -D arguments
-f and -D arguments can now take globs in the Soong format.

Also update the use of soong_zip that jars resources to escape the
globs in the arguments, and then shell-escape them when writing to
the rsp file so the glob escape are not intepreted by ReadRespFile.

Also remove an unused argument to the buildAAR rule that could
have contained values that needed escaping.

Relands I7f20bb169dc01f952d2a7681ec6ee9c05737ed37 with a fix for
trailing "\n" in list files, which causes a call to pathtools.Glob("")
that returns "./", which could then get incorrectly translated to
"../../../" in the zip file. Also adds tests.

Test: m checkbuild
Test: zip_test.go
Change-Id: I54b8eef9231875e6042a32c9f8bcc5c2f779922a
2018-09-28 14:01:29 -07:00
Colin Cross
7f33b81ef6 Revert "soong_zip: support globs in -f and -D arguments"
This reverts commit 08e28abc4e.

Reason for revert: inserts extra ../../ entries in the zip file.

Bug: 116737386
Change-Id: I048f94889a66fe618058e37a5827d0cf6b1a6b68
2018-09-26 21:38:07 +00:00
Colin Cross
08e28abc4e soong_zip: support globs in -f and -D arguments
-f and -D arguments can now take globs in the Soong format.

Also update the use of soong_zip that jars resources to escape the
globs in the arguments, and then shell-escape them when writing to
the rsp file so the glob escape are not intepreted by ReadRespFile.

Also remove an unused argument to the buildAAR rule that could
have contained values that needed escaping.

Test: m checkbuild
Change-Id: I7f20bb169dc01f952d2a7681ec6ee9c05737ed37
2018-09-21 16:08:16 -07:00
Colin Cross
fe4bc36f87 Allow '$' in some paths
The icu resource directories contain filenames that have '$'
characters.

Allow paths returned by the Glob functions to contain '$', on the
assumption that real paths on disk are unlikely to contain strings
that are valid ninja variables.  Fix the Build rules to escape any
paths that are passed as Path arguments.  Fix the resource rules to
manually escape the paths that are passed as strings.

Test: m checkbuild
Change-Id: Ie631bc6d96259e592adb280491a365c0df7ed0e2
2018-09-13 18:27:50 +00:00
Colin Cross
0f40a7527a Move kotlinc-build.xml out of classes directory
kotlinc-build.xml was ending up in the final jar because it was
being created in the directory where the classes were written.
Rename the variable containing the classes directory from outDir
to classesDir to discourage putting other files in there, and
move kotlinc-build.xml up a directory.

Bug: 114524493
Test: m checkbuild
Change-Id: Id2e2af0a6543499bd25b8fbd642bc59b14bd241f
2018-09-08 21:07:30 +00:00
Nan Zhang
4c819fb590 Add jetifier support in Soong.
This is a blocker for droiddoc targets migration under vendor/.

Test: N/A
Bug: b/72552006
Change-Id: If85a0917c1ac0d88b9d5b488216a638b4dabd39f
2018-08-29 11:37:32 -07:00
Colin Cross
9b38aef182 Revert "Add support for renamed kotlin stdlib."
This reverts commit 66c0c4067f.

Bug: 112674805
Test: m checkbuild
Change-Id: I687888136b570f080b57af352af0130355acd216
2018-08-29 05:41:25 +00:00
Colin Cross
8144008360 Support patch_module in java modules
A few tests that have classes in the java.base module need to pass
--patch-module=java.base=<classpath> to javac.

Test: m checkbuild
Change-Id: I246bad92dcde976969b064aace5e2856e2bac971
2018-08-16 16:14:09 -07:00
Colin Cross
3063b78ea5 Make :module provide the output file for java modules
Make :module on a java_library provide the output file, which is
normally the implementation jar.  For java_library modules with
installable: true or compile_dex: true this will be the dexjar
instead.  For android_app modules this will be the apk.

Bug: 80144045
Test: no change to out/soong/build.ninja
Change-Id: I739674aee60a38bfccb859369e4414b46f293d82
2018-08-16 16:13:58 -07:00
Colin Cross
37f6d79c7e Add exclude_files and exclude_dirs properties to java_import
Prebuilt jars sometime contain files that we don't want.  In Make
we would delete everything in META-INF when importing jars, but
that caused problems when there were necessary files in there,
so we added LOCAL_DONT_DELETE_JAR_META_INF.

Soong does the opposite, keeping everything by default.  Add
properties to allow explicitly stripping unwanted files instead.

Bug: 111389216
Test: m checkbuild
Change-Id: I6d07f519ebc7d0e1bf0af93416bb569e3c2b1500
2018-07-12 16:59:59 -07:00
Sundong Ahn
24a099c3b8 Add condtion to avoid build error
If docs file which is result of javadoc is null, there is a build error
when building stubs file. To avoid build error, we don't build if srcJar
files is exist but they don't have java file list.

Bug:77577799
Test: make -j
Test: Marking @hide to all APIs in javax.obex library
      -> make -j -> check build result.
      result is success

Change-Id: I85439417a36425e89a8fa2ecbc66d1b2022bc63a
2018-06-29 10:51:48 +09:00
Colin Cross
6654810f37 Run ErrorProne in OpenJDK9
Use the OpenJDK9 javac to run ErrorProne by adding it to
-processorpath and using -Xplugin:ErrorProne.

Bug: 69485063
Test: m RUN_ERROR_PRONE=true javac-check
Change-Id: I0496006b71b70766ef16d57753cbcf037897799c
2018-06-20 21:03:16 -07:00
Colin Cross
6a77c9871c Use -processorpath for annotation processors
ErrorProne needs to be added to -processorpath, but once anything is
passed via -processorpath javac stops looking in the classpath for
annotation processors.  Move annotation processors to -processorpath
in preparation.

This reapplies Ife06b3c7432ab971f5605dcc18a558bcbd99a675 with fixes
to processorpath in errorprone rules.

Test: m java
Change-Id: I188136771386a2183fb31f4b70b50c95ac419ff8
2018-06-20 21:03:07 -07:00
Colin Cross
2f10997e6b Revert "Use -processorpath for annotation processors"
This reverts commit 6dd0bb3b77.

Reason for revert: broke RUN_ERROR_PRONE=true build

Change-Id: I23d066281e392c6e7df29c5cd4558c7cf731c1a5
2018-06-21 03:56:45 +00:00
Colin Cross
6dd0bb3b77 Use -processorpath for annotation processors
ErrorProne needs to be added to -processorpath, but once anything is
passed via -processorpath javac stops looking in the classpath for
annotation processors.  Move annotation processors to -processorpath
in preparation.

Test: m java
Change-Id: Ife06b3c7432ab971f5605dcc18a558bcbd99a675
2018-06-20 16:16:49 -07:00
Colin Cross
bafb897de7 Revert "Revert "Remove desugar support""
This reverts commit 7576916efc.

Reason for revert: includes art veridex fix this time

Change-Id: Ia8da00b5ec8ed3dc3ce2a2521f0a7b2b2b131960
2018-06-06 21:46:32 +00:00
Colin Cross
7576916efc Revert "Remove desugar support"
This reverts commit 000280bb0e.

Reason for revert: broke art veridex build

Change-Id: I9f7d7cdbe8e34671614687ac0b34c0338ef240e7
2018-06-06 21:42:39 +00:00
Colin Cross
000280bb0e Remove desugar support
Desugaring is always handled by d8 now.

Test: m checkbuild
Change-Id: I29e8f68e51b194a4090866acc63f19f0605e318d
2018-06-06 10:05:06 -07:00
Przemyslaw Szczepaniak
66c0c4067f Add support for renamed kotlin stdlib.
Added new CompilerProperty flag, rename_kotlin_stdlib, which
allow to build kotlin libraries/binaries that use platform internal
version of kotlin stdlib (com.android.kotlin.*). This way, app-provided
kotlin standard library won't collide with version used internaly.

+ remove kotlinc-build.xml after compilation so it won't end up in the
result jar file

+ remove *.kotlin_module and *.kotlin_bultin filesfrom result jar file.
These files are needed only by kotlin-reflect library and
need more work to support kotlin-stdlib renaming.

Bug: 73281388
Test: java_test.go
Change-Id: Iae7ccb919e2ae9853b3f30f3dd447ebd01a1bed0
2018-03-20 12:55:19 +00:00
Colin Cross
436b76564d Replace extract-srcjars.sh with zipsync tool
extract_srcjars.sh uses zipinfo and unzip, which fail with an
error on an empty zip file.  Instead of trying to hack around
this (which is hard to make guarantees for since they are
non-hermetic host tools), replace them with a go tool to unzip
a set of zip files into a directory.

Bug: 73885582
Test: m checkbuild
Change-Id: I151fed347ed5196726e36866ffc27bc831799afb
2018-03-15 16:42:43 -07:00
Colin Cross
924a0aa7d5 Update turbine command line flags
The latest version of turbine requires a -- after the javac
options, and uses multiple --bootclasspath arguments instead
of a javac-style colon separated list.

Test: m javac-check
Bug: 74339924
Change-Id: Ib7096294a43e9bd30abc36751299bfac7879f765
2018-03-13 22:22:49 -07:00
Colin Cross
6981f658ef Use turbine's native source jar support
Turbine doesn't need extract_srcjars.sh, just pass the source jars
with --source_jars.

Bug: 74339924
Test: m checkbuild
Change-Id: Ie7fe06f5a9f5e29287cf79c2d46b23a676a03d41
2018-03-07 15:14:50 -08:00
Dan Willemsen
ab9f4268c0 Add proto.canonical_path_from_root
Historically, we've always passed '-I .' as the first argument to
protoc, essentially treating all proto file package names as their full
path in the android source tree. This would make sense in a monorepo
world, but it makes less sense when we're pulling in external projects
with established package names.

So keep the same default (for now), but allow individual builds to opt
into using local paths as the default names with
'canonical_path_from_root: false'. A cleanup effort and/or large scale
change in the future could change the default to false.

As part of this, run protoc once per input proto file, since the flags
may need to change per-file. We'll also need this in order to specify
--dependency_out in the future.

Bug: 70704330
Test: aosp/master build-aosp_arm.ninja is identical
Test: aosp/master soong/build.ninja has expected changes
Test: m
Test: Build protobuf test
Change-Id: I9d6de9fd630326bbcced1c62a4a7e9546429b0ce
2018-02-22 16:48:35 -08:00
Nan Zhang
581fd21e91 Droiddoc Support in Soong
Support Droiddoc to Soong based on core/droiddoc.mk. The non-std doclet
based droiddoc compilation output is a "real" stubs.jar instead of a
directory of java files and a timestamp file.

The std doclet based javadoc compilation output is a "empty" stubs.jar
instead of a timestamp file.

The stubs.jar will be exported to
out/target/common/obj/JAVA_LIBRARIES/$(LOCAL_MODULE)_intermediates/classes.jar
and out/target/common/docs/$(LOCAL_MODULE)-stubs.jar

A $(LOCAL_MODULE).zip file will be generated also, and is exported to
out/target/common/docs/$(LOCAL_MODULE)-docs.zip if property: installable is not set
to false.

Bug: b/70351683
Test: unittest + convert libcore docs Android.mk to Soong manually.

Change-Id: I1cffddd138a5d9d445f86a3d4a3fd4de88a2bc0f
(cherry picked from commit 78188ec622cb1ee24171455867fc58ffab91562e)
2018-02-22 11:14:13 -08:00
Colin Cross
f7eac7a2ac Fix comment on how java rules handle unknown output files
Test: none
Change-Id: I985e7961c87dd145d6eb2bd94cb8bdc43becc360
2018-02-20 17:54:00 +00:00
Przemyslaw Szczepaniak
4b5fe9d1b4 Add rsp and srcjar support to kotlinc build rule
Rsp files are supported through helper script (gen-kotlin-build-file.sh)
that generates the kotlinc module/build xml file.

Since rsp files are supported, I've added ExtractSrcJarsCmd step
to handle srcjars extraction.

Minor reorderings to make sure that TransformKotlinToClasses
recives only .java and .kt files when called from Module.compile.

Bug: 73281388
Test: make -j hidl-doc
Change-Id: I5a40b914569018dc529903a7f2864a5aeae838e5
2018-02-14 20:47:17 +00:00
Nan Zhang
674dd932d8 Add Respfile support for soong_zip.
Sometime the size of our command line passed to soong_zip go program
exceeds the cmdline size limit. So add an RespFile support with "@" special
character prefix.

The args in the cmdline will be considered together with the
args in RespFile during soong_zip running.

Test: real tests in my local machine, and compare the
res/libphonenumber.jar before and after changes.

./cmd -o test.zip '""'-C -> [./cmd,-o,test.zip,""-C]
./cmd -o test.zip '-C -f -> [./cmd,-o,test.zip,-C -f]
./cmd -o test.zip '\"'-C -f -> [./cmd,-o,test.zip,\"-C -f]
./cmd -o test.zip '\\'-C -f -> [./cmd,-o,test.zip,\\-C -f]
./cmd -o test.zip '\a'-C -f -> [./cmd,-o,test.zip,\a-C -f]

./cmd -o test.zip \'-C -> [./cmd,-o,test.zip,'-C]
./cmd -o test.zip \\-C -> [./cmd,-o,test.zip,\-C]
./cmd -o test.zip \"-C -> [./cmd,-o,test.zip,"-C]

./cmd -o test.zip "'"-C -> [./cmd,-o,test.zip,'-C]
./cmd -o test.zip "\\"-C -f -> [./cmd,-o,test.zip,\a-C -f]
./cmd -o test.zip "\""-C -f -> [./cmd,-o,test.zip,"a-C -f]

Bug: b/72484223

Change-Id: I83c3630b70c8396c8e8a3f266244d868d754c4e8
2018-02-13 15:13:01 -08:00
Colin Cross
f91a08caca Disable duplicates warnings when merging jars
There are too many duplicates warnings, disable them until someone
is actually looking at them.

Bug: 69316739
Test: m checkbuild
Change-Id: I7b3315f999dff1c01b6df37ab5ca83f7b8a60bd9
2018-02-08 01:15:39 +00:00
Andreas Gampe
f3e5b558e7 Soong: support Errorprone javacflags
Add support for an errorprone block in Java modules that accepts
additional javacflags for the errorprone build.

Sample:

    errorprone: {
        javacflags: ["-Xep:EqualsNaN:WARN"],
    },

Bug: 72004718
Test: m RUN_ERROR_PRONE=true
Test: manual - add block with ERROR to a project
Test: androidmk_test
Change-Id: I502248fe76c26aa19102f413af72a7324c35b7f4
2018-01-23 20:30:01 -08:00
Colin Cross
66dbc0bc32 Add R8 support
Add support for R8 to optimize apps and java libraries.

Test: m checkbuild
Change-Id: I2afd5d7a84912d3ab613c32c599bd1ebe60562e0
2018-01-03 14:15:57 -08:00
Colin Cross
f0056cb2ed Refactor dexing
Move dexing support into java/dex.go, including the rules and logic
from builder.go and the function from java.go.

Test: no change to build.ninja
Change-Id: I098d2a9774e28079ba44791679a0db6f876fe3e6
2018-01-02 18:23:43 -08:00
Colin Cross
7b60cdd6e5 Strip module-info.class files when combining jars
Combining static jars from dependencies may bring in module-info.class
files, which don't make sense once multiple modules have been combined,
and sometimes confuse downstream tools like desugar.  Strip them out
like make does when combining jars.

Test: m checkbuild
Change-Id: I560c5acfcc6e1be9adf604c22cf200581f92f702
2017-12-21 14:29:56 -08:00
Alan Leung
c37c6343e2 Prep D8 default instead of CompatDX in build/soong
Bug: 69329508
Test: m checkbuild tests
Change-Id: Ibaa2d787c644cf25104af78305a6eed16028dcf0
2017-12-18 23:56:30 -08:00
Colin Cross
9bc4343bea Add missing dependencies on classpath jars for kotlinc
The kotlinc build rules were missing dependencies on the jars in
the classpath.

Test: TestKotlin in java_test.go
Change-Id: I56681785289f942b1070751b7dc5944e7a995b7f
2017-12-16 06:05:38 +00:00
Joe Onorato
09e94ab074 When compiling with the lite protobuf option, pass the option to aprotoc to force the lite runtime.
Test: make
Merged-In: I450f89d144d496a6ddfccc6a6a5a679a05809595
Change-Id: I450f89d144d496a6ddfccc6a6a5a679a05809595
2017-12-15 08:40:27 -08:00
Alan Leung
9f319118e1 Add USE_D8_DESUGAR option in build/soong
Add an option to use D8's desugar instead of the standalone version.

USE_D8_DESUGAR=true m would trigger DCHECK in dex2oat unless
https://android-review.googlesource.com/c/platform/art/+/562595 is
patched in as well.

Bug: 69329508
Test: m && USE_D8_DESUGAR=false m

Change-Id: I864d88e257a2ba0b7f19aa5cced537301950e963
2017-12-11 16:05:51 -08:00
Colin Cross
6510f91a1c Replace ModuleContext.AConfig() with Config()
AConfig() now duplicates Config().  Replace the uses of AConfig()
with Config().  Leave AConfig() for now until code in other
projects is cleaned up.

Test: m checkbuild
Change-Id: Ic88be643049d21dba45dbd1a65588ed94bf43bdc
2017-11-30 00:44:18 +00:00
Tobias Thierer
96427d63bc kotlinc: Always pass -jvm-target 1.8
AOSP's current version of kotlinc only supports -jvm-target
1.8 or 1.6. Previously, we were passing the javaVersion
(the value passed to javac -target) but that would fail if
javaVersion was eg. 1.9.

This CL changes the kotlinc invocation to always pass
-jvm-target 1.8, regardless of javaVersion.

Bug: 69160377
Test: Treehugger
Change-Id: Ib12a8c2afbe908319513861a5380e70bf09d0be0
2017-11-18 04:11:59 +00:00
Colin Cross
d5dbfb78a0 Fix proto flags in java
Compute the common proto flags and pass them to the protoc invocation
when generating java files.

Test: m checkbuild
Change-Id: I0d4c23ad001d01eab03b404545383f009214106d
2017-11-17 11:22:08 -08:00
Nan Zhang
61eaedbddf Support Javac sharding in Soong.
Test: m clean && m -j java and java_test.go

Change-Id: I110a0ff029448d3319aed2788d25d90a6c1a7fa0
2017-11-06 14:23:59 -08:00
Colin Cross
715d7110f7 Fix kotlin -classpath argument
kotlinc expects -classpath, not --classpath.

Also add a test that uses only .kt files to exercise the code when
there are no java sources.

Test: java_test.go
Change-Id: Ifa5a007b460b40ea2188d0907570fbdca6c48da7
2017-10-26 14:47:40 +00:00
Colin Cross
8eadbf0aaf Fix source jars
Source jars were not working as designed because javac will only
compile files from the -sourcepath if there are references to them
starting from files on the command line.  Switch to extracting
the source jars into a directory and passing a list of the files
to javac.

Test: m checkbuild
Change-Id: I9f7d824f8538d081b2f5ad64ae3cbfd0e96213af
2017-10-26 01:00:46 +00:00
Colin Cross
ae88703df5 Move ModuleContext.ModuleBuild to ModuleContext.Build
Now that android.ModuleContext does not include blueprint.ModuleContext
we can rename android.ModuleContext.ModuleBuild to
android.ModuleContext.Build without colliding with
blueprint.ModuleContext.Build.  Leave ModuleBuild as a wrapper around
Build for now to avoid having to update all the users outside
build/soong simultaneously.

Test: m checkbuild
Change-Id: I18eb8cc04faf002049a11d9aac97e9732ff5d638
2017-10-24 10:59:00 -07:00
Nan Zhang
ed19fc3e2c Support Turbine in Soong.
If sdk jars(android_stubs_current, etc) are compiled using soong java
modules, we have to filter them when running Java build with Turbine.

TODO: provide more unit-tests.

Test: m clean && m -j32; go test java_test

Change-Id: Iad7c241b0e8b0ca760950733f513124b56c84564
2017-10-20 16:26:18 -07:00
Colin Cross
1ee2317555 Move all jar intermediates to subdirs
Make all the jar intermediates called modulename.jar, and put each
in a subdir for the tool that generated it.  This will simplify
using the jars as inputs to genrules and resources.

Test: java_test.go
Change-Id: If00e16bd7df5a4ba24ebc4b68c9ccf2cfda49544
2017-10-19 20:45:11 +00:00
Colin Cross
a482065454 Use soong_javac_wrapper in soong javac compiles
Test: m checkbuild
Change-Id: I0f9ff0a719ac550a011c2878fc51595dc3427aed
2017-10-18 17:09:54 +00:00
Colin Cross
93e8595044 Initial kotlin support
Allow java libraries to specify .kt sources, precompile them with
kotlin, and then pass them in the classpath to javac.

Bug: 65219535
Test: java_test.go
Change-Id: Ife22b6ef82ced9ec26a9e5392b2dadacbb16546f
2017-10-17 16:25:22 -07:00
Colin Cross
59149b6df5 Use jars containg sources for java generators
srcFileLists was an ill-fated attempt to deal with generators that
produce a set of java sources that is not known ahead of time.
For example, the list of files produced by protoc depends on the
package statement in the .proto file.  srcFileLists put the list
of generated files into a file, which was then passed to javac
using the @file syntax.  This worked, but it was too easy to cause
missing dependencies, and will not work well in a future distributed
build environment.

Switch to putting generated sources into a jar, and then pass them
jar to javac using -sourcepath.

Test: m checkbuild
Change-Id: Iaab7a588a6c1239f7bf46e4f1b102b3ef517619b
2017-10-16 19:39:39 -07:00