Commit graph

461 commits

Author SHA1 Message Date
Mårten Kongstad
a102909e09 aconfig: add dump protobuf format
Introduce a new protobuf format to represent the all flags parsed by
aconfig. This data in this new format is similar to that of the internal
cache object, but the protobuf is a public API for other tools to
consume and any changes to the proto spec must be backwards compatible.

When aconfig has matured more, Cache can potentially be rewritten to
work with proto structs directly, removing some of the hand-written
wrapper structs and the logic to convert to and from the proto structs.
At this point, the intermediate json format can be replaced by the
protobuf dump.

Also, teach `aconfig dump` to accept an --out <file> argument (default:
stdout).

Also, teach `aconfig dump` to read more than once cache file.

Note: the new protobuf fields refer to existing fields. It would make
sense to split the .proto file in one for input and one for output
formats, and import the common messages, but the Android build system
and cargo will need different import paths. Keep the definitions in the
same file to circumvent this problem.

Bug: 279485059
Test: atest aconfig.test
Change-Id: I55ee4a52c0fb3369d91d61406867ae03a15805c3
2023-05-09 15:27:42 +02:00
Mårten Kongstad
98b0eeb2fc aconfig: simplify argument parsing in main
Improve readability by extracting how multiple input files are
transformed from a clap argument to an Input.

Bug: 279485059
Test: atest aconfig.test
Change-Id: I299179d39eca80e107342f6978984da79ee81e34
2023-05-08 12:47:34 +02:00
Mårten Kongstad
76adff2af0 aconfig: improve flag value tracing
Improve how the flag values (state, permission) are tracked when parsing
config and override files: migrate from a raw string to a proper struct,
as this will make it easier when aconfig will output this data in some
structured format for other tools to consume.

Also, rename Cache.debug to Cache.trace.

Bug: 279485059
Test: atest aconfig.test
Change-Id: Idad57c969515f697e9065429d8a44c38d8a512d2
2023-05-08 12:47:34 +02:00
Mårten Kongstad
c68c4eabea aconfig: change flag values to enabled/disabled enum
Change the underlying type of a flag's value from bool to an explicit
enum (Disabled, Enabled): this will hopefully reduce future confusion on
how flags are intended to be used.

Bug: 279485059
Test: atest aconfig.test
Change-Id: I9535f9b23baf93ad5916ca06fb7d21277b4573eb
2023-05-05 16:20:09 +02:00
Mårten Kongstad
416330b060 aconfig: add read/write permission
Introduce the concept of flag read/write permissions: a read-only flag
can only have its value set during the build; a writable flag can by
updated in runtime.

Bug: 279485059
Test: atest aconfig.test
Change-Id: I3ec5c9571faa54de5666120ccd60090d3db9e331
2023-05-05 13:45:28 +02:00
Mårten Kongstad
2937566c55 aconfig: Source: remove unnecessary #[derive(Serialize, Deserialize)]
The Source struct is no longer serialized/deserialized. Remove the
unused derives.

Bug: 279485059
Test: atest aconfig.test
Change-Id: Ifd78988ed8134ab43013314b4437e428a8927981
2023-05-05 10:57:19 +02:00
Mårten Kongstad
09c28d1689 aconfig: add support for changing flag value based on build
Teach aconfig about build IDs (continuously increasing integers). Extend
the aconfig file format to allow flags to say "by default, my value is
X, but starting from build ID A, it's Y, and from build ID B, it's Z".

Bug: 279485059
Test: atest aconfig.test
Change-Id: Idde03dee06f6cb9041c0dd4ca917c8b2f2faafdd
2023-05-04 14:34:55 +02:00
Mårten Kongstad
4d2b4b047b aconfig: introduce cache
Introduce the Cache struct to represent parsed and verified aconfig and
override content. Most commands in aconfig will work of an existing
cache file, eliminating the need to re-read the input every time.

Restructure main.rs to use clap to create a proper command line
interface with support for sub-commands. main.rs is responsible for
parsing the command line, performing disk I/O and calling the correct
subcommand implementation (in commands.rs).

To simplify unit tests, subcommands never perform explicit I/O; instead
they only work with Read and Write traits.

Also add dependencies on clap, serde and serde_json.

Bug: 279485059
Test: atest aconfig.test
Change-Id: Ib6abf2eabd264009804f253874b6fba924fc391b
2023-05-04 10:40:26 +02:00
Mårten Kongstad
bb520729e8 aconfig: define Aconfig proto
Fill in aconfig.proto. Define Aconfig definitions (for introducing flags
and setting their values) and Overrides (for overriding flags regardless
of what their definitions say). More changes to the proto schema are
expected when more of the aconfig project is outlined.

Use proto2 instead of proto3: this will cause the protobuf text parser
to error on missing fields instead of returning a default value which is
ambiguous, especially for booleans. (Also, the text protobuf parser
doesn't provide good error messages: if the input is missing a field,
the error is always "1:1: Message not initialized").

Unfortunately the generated Rust wrappers around the proto structs land
in an external crate, which prevents aconfig from adding new impl
blocks. Circumvent this by converting the data read from proto into
structs defined in the aconfig crate.

Change main.rs to parse (static) text proto.

Also add dependency on anyhow.

Bug: 279485059
Test: atest aconfig.test
Change-Id: I512e3b61ef20e2f55b7699a178d466d2a9a89eac
2023-05-04 10:35:25 +02:00
Mårten Kongstad
fe753f5365 aconfig: add support for cargo
Officially, aconfig is build using the Android tool-chain. However, to
speed up the local development cycle, add support for building with
cargo.

While it is possible to tell cargo to place the build artifacts outside
the source tree, there is no way to tell it to not generate the cargo
lock file in the same directory as Cargo.toml. Add a .gitignore to
ignore Cargo.lock and the target directory.

The way the Android build system and cargo generates code from the
protobuf files is slightly different. Tell cargo to enable the "cargo"
feature and introduce src/protos.rs to hide this difference from the
rest of the aconfig source.

Bug: 279485059
Test: m aconfig && aconfig
Test: atest aconfig.test
Test: cargo build
Test: cargo test
Change-Id: I85741f58cadae353ed95c124f566e4f4a7484186
2023-05-03 09:41:11 +02:00
Mårten Kongstad
867a349ed9 aconfig: add project scaffolding
Introduce a new tool, aconfig, to manage build time configurations, such
as feature flags.

This CL adds a project skeleton. Later CLs will add the actual
implementation.

Note: there is no need for an explicit TEST_MAPPING file;
rust_test_host are automatically included in host-unit-tests and
explicitly adding these tests via TEST_MAPPING will cause an error.

Bug: 279485059
Test: m aconfig && aconfig
Test: atest aconfig.test
Change-Id: I94047a19a55ae4d45b4fd7a0c8105a91ddcdfd79
2023-05-02 17:36:30 +02:00