This allows you to give cargo2android.py a list of test files to ignore.
Test: Use on a couple crates.
Change-Id: Id9422c496de6693029754f32d9805f1cb92d33cb
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
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
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
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
This commit adds an --apex-available option to cargo2android.py. It
takes in multiple strings that are included in the generated block.
It also adds --min-sdk-version.
Test: Use flags.
Change-Id: I319a32fc5e8be11015ba4484b0ab1665ee457326
The command-line options to c2a are already long and will only get
longer as new arguments are added. This allows it to load them from a
config file. For simplicity of implementation, the config file
supplements the command-line arguments and uses the same format they
do, although it ideally will replace them over time.
This also adds an option to dump the current set of command-line
arguments to a config file and exit. This is intended to ease
migration over to the config file: for a given crate, we can call c2a
with its command-line arguments plus this new flag to generate the
config file and then use just that instead.
Test: Dump and load some config files.
Change-Id: I63b29dd20bcff5d5832dbd380d7c6eb273547ed0
Generating a TEST_MAPPING file uses Bazel, which can be quite slow
(multiple minutes). Add a flag to allow skipping it. This is off by
default as it ideally will only be used for debugging.
Test: Run all four configurations of --tests and this flag.
Change-Id: I08bde29ea298fcf677addd86f6d953b6695e147f
The code that preserves license blocks currently also preserves
genrules if they come before a rust_ rule, causing them to be
duplicated. Let's fix that.
Test: Upgrade some crates
Change-Id: Ie4f62cd04c2f1dd0de788db0ca5e77502fb3b4c8
Allow this script to accept a path to the crate being updated.
This allows it to be run separately from cargo2android.
Also, fail gracefully on error. TEST_MAPPING update failures should
not block crate updates.
Test: tools/external_updater/updater.sh update rust/crates/libc
Bug: 179132533
Change-Id: I3a4229f479ab3d2793df16b470f0a0632b9ee495
This is important because:
1. Some crates do not have their own tests enabled in presubmit.
2. As much as possible, we try to stick with one version of each
crate. This often results in using different versions of
dependencies than a crate has specified in its Cargo.toml.
Ensuring that a crate's tests continue to pass when its dependencies
are upgraded improves our confidence that the update is safe.
The underlying implementation uses the new Bazel queryview
to query modules and reverse dependencies.
Bug: 168167373
Test: Run cargo2android.py on a number of crates including rusqlite,
scopeguard, lock_api.
Change-Id: Id24f2d3267cf8d5e0369ece2442f8971d4ab1343
Followup to aosp/1548356 to remove the now unused host parameter to add_test.
Test: Manually run script and verify the output.
Change-Id: Id00e56a2dc5523a44dc3cb473702c1ae8785d3db
Instead of generating TEST_MAPPING entries for host tests, we add a
test_options section to its Android.bp entry.
Fixes: 176097100
Test: Manually run cargo2android on a few crates and verify the output
Change-Id: Ia57a53dad6910410c7e7aab6d592fba79720f998
We no longer have the rust_library_shared and rust_library_static module
types. They've been renamed to rust_ffi_* instead. This brings
cargo2android.py up to date.
Bug: 175155132
Test: cargo2android's Android.bp for libquiche contains rust_ffi modules
Change-Id: I01bb8b4e56c41d36481ffd363f96aecb770d7cb8
"host: true" entry should go before "name:" to match the output of
json writers which sort by alphabetical order. This will help and
avoid unnecesary changes when adding new tests to TEST_MAPPING - e.g.
aosp/1488728
Bug: 168167373
Test: cargo2android.py --run --tests
verify output
Change-Id: Id346a7f8a2cd910115e7fcc448c589363209bee9
* Suggest --copy-out if it is not used, cargo output files are found,
and env!("CARGO_OUT") is found in .rs files.
* Expect to see this warning for libsqlite3-sys and grpcio-sys,
which fit to the use case of --copy-out but they have locally
defined .bp files and non-original output files.
* Fix one pylint warning of extra long line.
Bug: 172299436
Test: run cargo with same flags for all rust/crates/*
Test: run cargo without --copy-out for anyhow, protobuf, clang-sys, etc.
Change-Id: Ic346c8e1146b1bb77e63c4cb12947f202b0f458e
* The given patch file will be applied to ./Android.bp.
* Use --ignore-cargo-errors when it is impossible to
use the patch file to fix the error messages in Android.bp.
Bug: 172093078
Test: apply on external/rust/crates/*, some with this flag
Change-Id: Ibca2fd4c63e46a32f32c61afedbba960a684f5d7
* Save Cargo.lock before calling cargo, and restore it after the run.
* Use the --use-cargo-lock flag if the latest dependent crates failed
to build the current crate. In this case, the published Cargo.lock
will be used, but the generated .bp might not work with the other
latest dependent crates in external/rust/crates.
* Fix one gpylint warning.
Bug: 172016745
Test: run through all external/rust/crates/*
Change-Id: I1874a706ac15b74c1dd5a606983b107284d9b28a
* When --copy-out is used:
* copy build.rs output files to ./out
* add a genrule module to copy ./out/* files to its output dir
* add this copy-out genrule module into the srcs list
This makes include! with $OUT_DIR path work without local patch.
This only works for the root directory (package).
* Upgrade to python3 for some required shutil and glob functions.
* Unified dump_srcs_list for defaults and non-defaults modules.
* dump_android_property_list output only one line for a single item list.
Bug: 171659849
Test: regenerate all .bp files in rust/crates/*
Change-Id: Ia7dde0ccede2bcc068f23a046e85304c6f50b0b0
* Now a host cargo build uses the same --target flag as a default
device build.
* When --device is given without --no-host or other device flag,
we can use one cargo build to get the required rustc flags for
both host and device builds.
* We still need merge_host_device because cargo build --test could
recompile a library and create duplicated calls to rustc.
* Fix a gpylint warning missing-function-docstring.
* This change also detected a bug in
external/rust/crates/structopt-derive/Android.bp
The cargo build --tests for device was optimized out
and the device test module was missing in Android.bp.
Bug: 169872957
Test: regenerate all .bp files in external/rust/crates
Change-Id: Ieabdc5a99534a60e4d459c9a966f7a867104c785
* Problem to solve:
When cargo2android.py is run under external/crosvm,
it does not generate .bp file in some subdirectories like kvm.
* Use --add_workspace flag to append [workspace] in Cargo.toml
temporarily to generate correct relative source file paths.
Otherwise, the path will be based on parent/root package
such as external/crosvm.
* Use --global_defaults=default_name flag to insert a global
default module name like "crosvm_defaults" in every module.
* Use --no-subdir flag to generate .bp file in one directory,
and skip all changes to subdirectories.
* Sort the option names so they show up in order with --help.
* Use relative path for local dependent packages.
* Example: run in external/crosvm with flags;
--run --tests --dependencies --no-subdir
fix-up external/crosvm/Android.bp file,
and then run in each subdirectory with flags:
--run --tests --dependencies --add_workspace
--global_defaults=crosvm_defaults
* Add rename mapping:
libminijail ==> libminijail_rust
Bug: 161716839
Test: regen .bp files in external/crosvm subdirectories
Test: make && atest -m -c --include-subdirs external/crosvm
Change-Id: I0c08d358cc2f88f66e99b59032613d2a5b4ea5eb
* Accept both "-C flag" and "-Cflag" syntax.
* Newer cargo uses "-Cembed-bitcode=no".
* Some -C flags are filtered out, not used in .bp file,
because they are meaningless in .bp file build system.
* Remaining -C flags are passed to rustc in .bp files,
which was missing before this change.
* Look up cargo in the prebuilts directory.
* Now limit this script to run only on linux.
* Try to find cargo/rust version from
build/soong/rust/config/global.go first.
* Otherwise, use the latest (largest) version in prebuilt.
* Add a new --cargo_bin flag to use any user-selected cargo.
* Add the selected cargo directory to PATH before calling cargo,
so it can find rustc in the same directory.
Bug: 161825397
Bug: 161927172
Test: regenerate and check .bp files in external/rust/crates
Change-Id: Ica46f536c2b37b62238d1245ced59685deebad33
* Share srcs in rust_defaults if len(srcs) is 1.
Test: regenerate .bp and TEST_MAPPING files in external/rust/crates
Test: make
Test: atest -c --include-subdirs external/rust/crates
Bug: 161259631
Change-Id: I22a1d567ccabcd945e4cac870049ac3ce7a3049a
* protobuf_bin_gen_rust_do_not_use is in EXCLUDED_CRATES
* build_default_name returns a short and readable name
for a rust_defaults module, from the following choices:
(1) root_pkg + '_defaults',
(2) root_pkg + '_defaults_' + crate_name
(3) root_pkg + '_defaults_' + main_src_basename_path
(4) root_pkg + '_defaults_' + a_positive_sequence_number
Test: regen external/rust/crates/*/Android.bp
Change-Id: I6aa16a8a6c7ea05744a31a9d4ff0c4524ef91fea
* Add a --no-host option.
* Add a --host-first-multilib option.
* Add special renaming for protoc_gen_rust.
* Dump a rust_defaults module to be shared by rust_test modules.
* Every test source file is in a rust_test module.
* Add RENAME_DEFAULTS_MAP for altered rust_defaults names.
* Suppress old error message on --extern proc_macro.
Test: regenerate Android.bp files and check differences
Bug: 161090277
Bug: 161089524
Change-Id: I8c70f568facf58d282ea2a2e72b60c8a2972b27d
* The old deny_warnings is replaced with a comment to remind the users.
Test: regenerate Android.bp files and check differences
Bug: 161001041
Bug: 161001220
Change-Id: I96c43cff83edcb7b50e6beee972c9157d20c8dc9
This makes it clear exactly how a build file was generated and how to
reproduce it.
Bug: 158290206
Change-Id: Icf28a66bf0da708a3fcd0fe3d49893191fb1a8f1
* Do not emit relative_install_path;
use default unique module name.
* Copy errors in cargo output to Android.bp.
Some Rust packages are incomplete at crates.io
and fail to run through cargo test.
* Apply pyformat.
Bug: 156014698
Test: in external/rust/crates/*, cargo2android.py --run --tests
Change-Id: Ide77ca34e47048a8bc03b18eebbe92fb17666784
* Change crate_type string to crate_types list.
In dump_android_module, iterate over crate_types and
call dump_one_android_module for each crate type.
* In decide_one_module_type, add mapping of Rust crate types:
lib => rlib (no change)
rlib => rlib (new)
dylib => dylib (new)
cdylib => shared (changed)
staticlib => static (new)
Maybe we should change and map 'lib' to 'lib',
but before that, crate_types should not contain
both 'lib' and 'rlib'.
* Accept new cargo output format, which can
call rustc with the main source file name after
other flags, not always after the "--crate-name" flag.
* Work around duplicated test module name problem;
call self.runner.claim_module_name for every named test module.
Bug: 153118477
Test: fetch quiche-0.3.0, bindgen-0.53.2 and other Rust crates
Test: cargo2android.py --run --vv --device --tests
Change-Id: Id65c3929b5c593df73f26f1510ad7e89194b209e
* When --features is specified,
pass --no-default-features to cargo.
* When a dependent Rust package is imported to AOSP,
if not all "default" features are needed, run
cargo2android.py with empty or a list of specific features.
Test: cargo2android.py --run # use default features
Test: cargo2android.py --run --features='' # no default
Test: cargo2android.py --run --features='default,std'
Change-Id: I854f1ecb7d7466490ff34e229ec14a07c1273c6d
* Usage note and help for command flags in the script.
* Run cargo -v multiple times and collect output in cargo.out.
* Use target.tmp as temporary working directory.
* Generate multiple Android.bp files into subdirectories.
* Simplified package names, without version number.
* Merged Android.bp modules.
* Use --device flag to generate both host and device build targets
in a combined module.
* Use --tests flag to generate rust_test modules, with auto_gen_config,
and multiple unit tests merged in one module.
* Generate cc_library_static modules for rust packages that call
'cc' and 'ar' to build static C/C++ libraries.
* Use the --vv flag to call cargo with -vv.
* Limitations:
* Cargo.toml and its build scripts might need fix for Android first.
* Depending on user given cargo parameters.
* TODOs:
* Handle multiple crate types in one rustc command line.
* Smart merge of host and device rust_test modules,
to handle device tests that depend on dynamic libraries.
* Handle special Rust packages that use only build scripts
and C/C++ compilers to generate included files.
Bug: 142209566
Test: In rust project directories: cargo2android.py --run
Change-Id: Id54652b1e0a6e5fc16619cd05f5b057eee79d610