Commit Graph

89 Commits

Author SHA1 Message Date
Thiébaud Weksteen
d5d033979f Require cargo_bin option
The prebuilt cargo (or more precisely, its libstd) cannot be used when
running cargo2android.py. Ensure that the upstream cargo binary is used.
This is automatically set when using the sandbox for Googlers. For
external contributors, raise an error if the option is not provided.

Test: As a googler, execute cargo2android.py directly; an error is
    raised.
Test: As a googler, use the sandbox; cargo2android.py is executed
    correctly.
Test: As an external contributor, execute cargo2android.py; an error is
    raised if cargo_bin is not provided.
Bug: 217810523
Change-Id: Id42ba777b3960b13f6ef91d36eaad94df939f48e
2022-02-09 11:25:15 +11:00
Andrew Walbran
ca9f9f2266 Add --no-presubmit option to prevent host tests being run in presubmit.
For some unknown reason the change to merge rust_test and rust_test_host
targets caused some crosvm tests to be run (and fail) in prebsubmit which
were not previously being run, so this is necessary to work around it.

Test: Ran cargo2android.py on various crosvm crates.
Change-Id: I9b94d270148d8ce5fa97f88f460d8c03eac3873c
2022-01-10 16:02:53 +00:00
Andrew Walbran
0e65bba93d Ignore clippy configuration flags.
Test: Ran ./all2android.sh under external/crosvm
Change-Id: I29a50ee242bca5111004b6ba56867b1e68ccd8f3
2022-01-07 15:12:00 +00:00
Andrew Walbran
a32a04851b Don't try to remove Cargo.lock if it doesn't exist.
Change-Id: Ibfad6d97988edb6305d7a237d038412ec5a6100f
2022-01-06 14:03:50 +00:00
Joel Galenson
54d655345d Stop generating separate rust_test_host.
With b/196306316 hopefully fixed, we should be able to use a single
rust_test entry for both device and host tests.  This modifies
cargo2android.py so it generates these shared tests.

Test: Run on crates with simple tests, those with defaults, host-only,
and device-only tests.

Change-Id: Icfe8d1fb26a61bc9ed65b8a7b116a4ebcd782ce4
2021-12-06 16:17:06 -08:00
Joel Galenson
d4b099d3fa Merge changes If5292d1d,Ib1a86d48
* changes:
  Stop cargo2android.py from printing the --cargo_bin argument.
  Revert "Enable LTO in cargo2android.py."
2021-12-02 14:46:56 +00:00
Joel Galenson
56b5f4be29 Comment out errors encountered when running cargo test.
A recent change to remove empty tests runs cargo test --list.  A few
crates produce build errors this way that they did not previously do.
This currently causes cargo2android.py to produce illegal Android.bp
files for these crates even though these should not be fatal errors.
We thus detect these errors and emit them as comments in the
Android.bp file, so developers can see them but the crate can still
compile.

Test: Run on crates with and without such errors.
Change-Id: I8664d3ca9a6b4c513ce0ef35821aa64d22949fc7
2021-11-30 10:34:14 -08:00
Joel Galenson
769c3c373f Stop cargo2android.py from printing the --cargo_bin argument.
cargo2android.py prints out all of its arguments to the top of the
Android.bp file (and into a config file if that option was set) as a
way of persisting them.  However, we do not want to persist the
--cargo_bin directory, as this is a proprety of the local setup and
not the crate itself.  Thus ensure we don't print this.

Test: Run with argument.
Change-Id: If5292d1d740b08755ba6d31654239e93232fdc49
2021-11-24 15:10:02 -08:00
Joel Galenson
903a0f8cb1 Revert "Enable LTO in cargo2android.py."
This reverts commit 4f4ac2f8f3.

This did not work for all crates (specifically, those with build.rs,
as they don't get passed RUSTFLAGS, as well as proc-macros, since they
get the flag but can't use LTO), so we're using a different approach
where this is not desired.

Test: Run script
Change-Id: Ib1a86d4822f51978cd8ec15ad657eb25c84e01a4
2021-11-24 15:09:45 -08:00
Joel Galenson
4f4ac2f8f3 Enable LTO in cargo2android.py.
The latest compiler roll also enabled LTO.  This broke
cargo2android.py, as the test prebuit uses LTO and so cannot be linked
with code built without.  We fix this by enabling it in
cargo2android.py (and ensuring it doesn't add the flag into
Android.bp).

Test: Run
Change-Id: I6c6a813ff58a9e5064752aa59b78247c4af77a26
2021-11-22 15:22:45 -08:00
Joel Galenson
0038349332 Merge "Document the expectations of two arguments." 2021-10-25 16:45:04 +00:00
Joel Galenson
493c26a8d4 Document the expectations of two arguments.
To work with the updater, these files must have a certain prefix.

Test: Run with --help and upgrade a crate.
Change-Id: Icdc492479223865c39d6c6f10b84fe3d762f5d1d
2021-10-18 15:54:41 -07:00
Joel Galenson
7cfc6fe5de Do not generate empty Rust tests.
cargo2android.py currently builds whatever cargo does, which includes
empty tests.  We can filter those out by parsing the output of "cargo
test" and looking for things with no tests.

Fixes: 159039990
Test: Run on a crate with empty integration tests, one with empty unit
tests, and one with no empty tests.

Change-Id: If8b1126d82ce6c2851b90de738ea24b129b81feb
2021-10-15 13:35:41 -07:00
Joel Galenson
f78de4f942 Merge "Do not generate cargo_pkg_version when --no-pkg-vers is passed" 2021-10-08 21:12:41 +00:00
Joel Galenson
308f3521dd Handle versions of the form -a.b.c+foo.
Previously we would keep the +x.y.z part, which caused errors in Soong.

See the diff between the first two patchsets in aosp/1833319 for an
example.

Test: Fix the above CL and run on a crate without a +.
Change-Id: I791c85545e67b54e2c8952428211688e7bbf580d
2021-10-01 15:19:45 -07:00
Joel Galenson
94b8a8d40c Do not generate cargo_pkg_version when --no-pkg-vers is passed
If you passed --no-pkg-vers to cargo2android.py, it would still
generate cargo_pkg_version with an empty string.  Instead, simply
don't generate anything.

Test: Use with and without argument.
Change-Id: I544e4789312ccc3481da73c78f0f2cae2ad6619c
2021-09-28 11:53:51 -07:00
Jason Macnak
7b3f02465b Merge "Suffix libash with _rust to avoid name conflict" 2021-09-08 16:43:34 +00:00
Jason Macnak
051340de9e Suffix libash with _rust to avoid name conflict
Bug: b/189133061
Test: presubmit with attached topic
Change-Id: I6619857a7f632fe7ab0576dd0dd0fe4dacf677b1
2021-09-04 11:04:26 -07:00
Joel Galenson
b06c42a03c Generate cargo_pkg_version and cargo_env_compat for defaults.
The existing code only adds it to things without defaults.  This adds
it to the defaults module itself, which should not overlap the
existing code.

Test: Run and see new entries.
Change-Id: Iaf3d0b47193bb1f54cdc605c88c2cd68034d963a
2021-08-31 14:28:48 -07:00
Joel Galenson
c3bfaf8a1e Fully remove deprecated --no-test-mapping argument.
This argument has already been deprecated, but now there should be no
more uses of it.  Let's remove it and the remaining logic.

Test: Run the updater.
Change-Id: I8ab6f6fadba3b462567237d18ddc02cc4c22e62f
2021-08-18 09:39:36 -07:00
Joel Galenson
a4648dfcba Merge "Do not dump the --config argument." 2021-08-18 15:04:38 +00:00
Joel Galenson
9a82ad9d47 Do not dump the --config argument.
When generating a config file from a commandline, cargo2android.py
should not dump the --config argument, as the point of the dump is to
generate a config file to use.  This would not normally matter, but it
could help in scripts.

Test: Run and do not see --config in the dumped file.
Change-Id: Idc2911ba674e67272c9cf836c89607e10ca0dddd
2021-08-17 17:52:04 -07:00
Matthew Maurer
70182e44f0 cargo2android: Don't emit image support for tests
Image support doesn't make sense for test modules.

Bug: 178565008
Test: Generate rustc-demangle-capi
Change-Id: Ie5a1d85f9828e0c105c3a3e994b22ef7664fe1db
2021-08-17 15:36:38 -07:00
Matthew Maurer
062709c3b3 cargo2android: Support exported C headers
staticlib and cdylib crate types generally want to export header files
for use by C code. Allow the location of these headers to be provided to
c2a for inclusion in blueprint.

Bug: 178565008
Test: Generate rustc-demangle-capi
Change-Id: I0aa9acfb081ea39a7e13315bfc8029d06b8f55d3
2021-08-17 15:06:34 -07:00
Matthew Maurer
9e4b781de9 cargo2android: Emit apex_available + min_sdk_version for native libs
Previously, we only emitted apex_available + min_sdk_version for 'lib'
type crates. That ignored:
* Explicit rlib
* Explicit dylib
* cdylib
* staticlib

Bug: 178565008
Test: Generated Android.bp for rustc-demangle-capi
Change-Id: I19f0abe385b9c13ac731b7f2c978052ffa6b92f7
2021-08-17 15:06:34 -07:00
Matthew Maurer
ac67725422 cargo2android: Add support for various image types
Test: Generated rustc-demangle's Android.bp with it
Bug: 178565008
Change-Id: I0877e2d7d9e309105610b4d87f2a6d45ef67903f
2021-08-17 15:06:34 -07:00
Joel Galenson
833848cea6 Deprecate the --dependencies argument.
We no longer use the --dependencies argument, but it is still used in
a number of places.  Let's remove its functionality but keep the
command-line option as a no-op so we can remove the uses over time.

Test: Run on crate that uses the option.
Change-Id: I954f68faf11d1a926f0ccf070afa8332385e3671
2021-08-17 10:50:42 -07:00
Joel Galenson
69ba807921 Improve package version logic
Only run cargo metadata on the main crate, not all of its dependencies.

Pass it the --format-version argument to avoid a warning and be
future-proof.

Test: Run.
Change-Id: Icdf88bc3b633d18266772ae813fc04b529b95765
2021-08-16 11:31:29 -07:00
Joel Galenson
c51865074b Fixes for getting package version
Older versions of Python's subprocess do not have capture_output, so
just get stdout directly.

Also pass the full path to cargo in case it is not on PATH.

Test: Run
Change-Id: I368e905a93b344bca6635c6ab7a60def809e88d5
2021-08-16 11:22:47 -07:00
Ivan Lozano
26aa1c30d2 cargo2android: Improve package version logic
If there are multiple packages present in the workspace, attempt
to determine what the current package is by checking the emitted
crate_name value against the package name. If this still fails, a new
`--no-pkg-vers` flag is added to skip this behavior.

Bug: 196803495
Test: New logic finds package if package.name is used for crate_name
Test: New flag prevents emitting the pkg version.
Change-Id: I152e94a0520f09f37622a6cec340ae35842d56ea
2021-08-16 11:37:28 -04:00
Ivan Lozano
cc660f1d75 cargo2android.py: Support cargo_pkg_version flag.
This parses a module's Cargo.toml file for package version number,
setting it to cargo_pkg_version. Also sets cargo_env_compat true by
default.

Bug: 171011485
Test: generated Android.bp includes cargo_env_compat, cargo_pkg_version.
Change-Id: Ibb8021633719650e2021b90806374a5d3c6a161a
2021-08-12 13:04:25 -04:00
Joel Galenson
e4f5388cf3 Let cargo2android.py generate data properties for tests.
Some tests load data from files.  These files thus need to be copied
to the correct location on the host/device so that the tests can
access them.  This adds an option to cargo2android.py so that it can
generate these data properties.

Bug: 171710847
Test: Use for a crate.
Change-Id: I14a1ad8aca4625cc5f09807d19ffd7499fcf3689
2021-07-19 12:18:21 -07:00
Ivan Lozano
9192086c9c cargo2android.py:vendor and vendor_ramdisk flags.
Adds flags to emit vendor_available and vendor_ramdisk_available flags
to generated modules.

Bug: 194078853
Test: Calling script with new flags generates intended properties.
Change-Id: I4f7a6870b4f210b6627054c98962f50e98bc3e03
2021-07-19 15:18:11 +00:00
Joel Galenson
14b71a757b Merge "When merging tests, prefer non-blocklisted ones." 2021-07-16 17:27:59 +00:00
Jooyung Han
a427c9b64f cargo2android: rename libxml to libxml_rust
Bug: 193808832
Test: m
Change-Id: Ib3acfdda03197e8b773cbec500cadcc94d1a52a3
2021-07-16 08:53:14 +09:00
Joel Galenson
57fa23a5db When merging tests, prefer non-blocklisted ones.
The test blocklist was failing when multiple tests were merged into
one.  To fix this, when merging tests we prefer ones that are not
blocklisted.

Fixes: 193790055
Test: Run on the previously failing crate and another.
Change-Id: I53d1179bebef824ce80ac4f977015b04a26f8607
2021-07-15 10:53:24 -07:00
Joel Galenson
1353136072 Merge "Rename rust_defaults that contain tests." 2021-07-14 16:14:48 +00:00
Joel Galenson
d37d7e6d2c Rename rust_defaults that contain tests.
This patch ensures that rust_defaults for tests have _tests in the
name.  This can make the Android.bp file a bit more readable.

Test: Run on a crate and build it.
Change-Id: I5d034c456052b892bd01c3c041b2572bc9364692
2021-07-13 09:03:01 -07:00
Joel Galenson
12467e54a7 Let cargo2android ensure some libraries are whole_static_libs.
Test: Use on a crate.
Change-Id: I1d6a3bdb47141d5d20af3c118fd7a05bef223a48
2021-07-13 08:55:17 -07:00
Treehugger Robot
5b65b9117d Merge "cargo2android.py: remove TEST_MAPPING generation" 2021-07-02 15:49:52 +00:00
Thiébaud Weksteen
198e93f61b cargo2android.py: remove TEST_MAPPING generation
Do not generate TEST_MAPPING when running cargo2android.py. Still accept
the command line argument so current users/wrappers continue working.

Bug: 192348260
Test: Run cargo2android.py manually on ahash
Change-Id: I1975119f8fdd3ae850649b105678dec92fa67518
2021-07-02 16:30:31 +02:00
Luke Huang
a1371afd29 Add name mapping for base64
Test: TH
Bug: 155855709
Change-Id: I1e411e2f831ede6f48822352774f6e44db5d409d
2021-06-29 18:57:33 +08:00
Joel Galenson
5664f2af26 Allow adding blocks of texts to the Android.bp file.
You can either add the blocks to the toplevel of the file or into the
main module.  The blocks are given in separate files.

Test: Use both for some crates.
Change-Id: I74204867d4e348c83c7adc2a833be166956bfb7e
2021-06-14 13:44:58 -07:00
Joel Galenson
cb5f2f0bd7 Add a lib blocklist and an option to force rust_library_rlib.
Test: Use in some crates.
Change-Id: I5d098ce9b0f1fc37c5d8408524c0755869657992
2021-06-08 15:08:29 -07:00
Joel Galenson
3d6d1e78b5 Allow blocklisting cfgs.
Test: Use it for a crate.
Change-Id: I72e383ce58f64c7e545db3049376feea8ac006d1
2021-06-07 15:00:24 -07:00
Joel Galenson
f6b3c91d21 Allow blocklisting tests.
This allows you to give cargo2android.py a list of test files to ignore.

Test: Use on a couple crates.
Change-Id: Id9422c496de6693029754f32d9805f1cb92d33cb
2021-06-03 16:00:54 -07:00
Joel Galenson
97e414af12 Allow blocklisting dependencies.
A few crates have patches that manually remove a dependency that
cargo2android.py adds.  This option can allow us to remove those
patches.

Test: Use when running on a few crates.
Change-Id: Ie8337789ab232fb726ccfe361df489acfdd31b20
2021-06-02 15:49:04 -07:00
Joel Galenson
7e8247e2eb Abort cargo2android.py if the patch fails.
This allows the external_updater to understand that an error occurred.

The pre-patched version of the file will still exist.

Test: Run when a patch fails.
Change-Id: I59cc12eeaa751b5e3e2956060f58981d27875748
2021-05-24 15:31:08 -07:00
Joel Galenson
6bf54e3abb When cargo errors, print an error about cargo.out.
Currently if cargo produces an error it's not obvious how to debug it.
Add a message telling the user to look at the cargo.out file, which
has its output.

Test: Ran on crates with and without errors
Change-Id: Ib681a8e87f60467c7425aed5f7e5277a0603bcc8
2021-05-17 10:54:50 -07:00
Joel Galenson
367360cdaf Do not write out the --no-test-mapping option.
This option is only intended to be temporary, so if it is used it
should not "propagate" itself by being added to the Android.bp header
or the config file.

Test: Do not see it in the header or config file.
Change-Id: Ibb18c76bdab26aa47b38ac75ea3c410ddc612856
2021-04-29 14:33:13 -07:00