Change all required proto fields to optional. While the proto file is
supposed to be a backwards compatible API, and fields are not supposed
to be deprecated, this commit will allow for that option if needed.
Implementation wise this change doesn't matter much: any parsed data
needs additional verification outside what the protobuf crate's parser
provides anyway, so adding checks to verify that all required fields,
even though marked optional in the proto file, were found is a minor
increase in code complexity.
If in the future a proto field should no longer be used:
- keep the field in the proto, still marked optional and clearly
document that it is no longer in use
- change protos.rs from checking struct.has_field() to explicitly
dropping any value via struct.clear_field()
Bug: 286337317
Test: atest aconfig.test
Change-Id: Iad1ccfe50ecac286ff7a796aec909bec70b9520d
Generate Java constants for use in @FlaggedApi(flag = ...).
Also update the generated Java code to use the constants when reaching
out to DeviceConfig instead of hard-coding (duplicate) strings.
Bug: 285288440
Test: atest aconfig.test aconfig.test.java
Change-Id: I1127cacba650cc7a7896b1533e03631d7f5ec71b
Remove the hand-crafted wrappers around the structures auto-generated
from protos/aconfig.proto, and use the auto-generated structs directly
intead. This gets rid of a lot of manual repetition, and its inherent
risk.
Also unify how individual fields read from text proto are verified (e.g.
is the flag.name field a valid identifier).
Also change the intermediate cache format from JSON to binary protobuf.
The concept of a 'cache' as an intermediate internal format to represent
parsed input stays. The command line interface still refers to caches.
At the moment a cache file is identical to a parsed_file protbuf, and
the code exploits this internally.
A couple of points regarding the auto-generated structs:
- Vectors are named in the singular (e.g. parsed_flags.parsed_flag is
a Vec<ProtoParsedFlag>) because this improves ergonomics for all
devs working with aconfig input files
- The auto-generated structs have fields that are of type Option<T>
and convenience methods (named the same as the fields) to access T
Test: atest aconfig.test aconfig.test.java
Bug: 283910447
Change-Id: I512820cc4bc6c543dea9f6a4356f863120a10be3
Before java code will directly use the flag name as the method name.
This change adds funciton to try the best to convert flag name to
camelCase, and then use the camelCase string as the method name in the
generated code.
Bug: 279483816
Test: atest aconfig.test aconfig.test.java
Change-Id: I45fc6df46c9d535cd38a657a41313202f9b660af
Group statements with identical #[cfg(feature = "cargo")] attributes in
the same block. This reduces repetition and makes the code easier to
read and less error prone.
Bug: 284779868
Test: atest aconfig.test
Change-Id: Iebdcd20e7cd22cb641424a1af594f5c9ac57b623
This change includes
- refactor generated java code to generate
- Flags.java to support the static API
- FeatureFlagsImpl.java to support injection API
- FeatureFlags.java interface
Bug: 279483816
Test: atest aconfig.test aconfig.test.java
Change-Id: If0d4baf317b9174635cd0fff3832ab7091ee52ed
The Java codegen may translate flag names (snake_case) to Java
camelCase, dropping the underscores. The flags a_b and a__b will
translate to the same camelCase form, which is ambiguous.
Circumvent this problem by disallowing consecutive underscores in flag
names, flag namespaces, and packages.
Bug: 284252015
Test: atest aconfig.test
Change-Id: I2586a38160723c06265a140193da8178655553e4
Add integration tests for Java. This test setup verifies that
- the build system calls aconfig to generate a Java library
- the Java test compiles against the auto-generated library
- the auto-generated code returns expected values
Similar integration tests for C++ and Rust will be added in follow-up
CLs.
Note: the build does not currently support specifying that
tests/*.values should be applied, so the test flags will all be assigned
the defaults. A later CL will fix this.
Bug: b/283911467
Test: atest aconfig.test aconfig.test.java
Change-Id: Ia365e209261f4935a23e2dac9ef0ab5b60f76e52
Update the output format of create-device-config-defaults to include the
flag's namespace. Also change the delimiters. The new format is
<namespace>:<package>.<flag-name>=[enabled|disabled|
Bug: 285468565
Test: atest aconfig.test
Change-Id: I9b4ca1611cca8528dc341fc12812b614c86f6c08
Implement a helper function to make it easier for unit tests to diff
(and find the first difference) generated code and expected code.
Bug: 283910447
Test: atest aconfig.test
Change-Id: I460e8fbf05e8f33e8a62ecef67b2d9d77051e876
Add a new field to the proto messages flag_declaration and parsed_flag.
The new field will be used verbatim as a parameter when calling
DeviceConfig.getBoolean to read the value of a READ_WRITE flag. See the
DeviceConfig API for more info.
Note: not to be confused with the old namespace field, which has been
renamed to package.
Bug: 285211724
Test: atest aconfig.test
Change-Id: I2181be7b5e98fc334e5277fb5f7e386f1fe0b550
Allow package fields to include dots.
Update the generated code based on the package name: if the package name
is com.android.example:
- java: package com.android.example; ...
- C++: namespace com::android::example { ... }
- Rust: mod com { mod android { mod example { ... } } }
Also, update examples to use dots in the package fields.
Also, remove unnecessary #include from the auto-generated C++ code: the
header should not include itself.
Bug: 285000854
Test: atest aconfig.test
Change-Id: I8a5352e25c64c34dee0725202a1b7c9957819de8
What used to be referred to as a namespace is now called a package.
This CL is a semantic change only.
Bug: 285000854
Test: m nothing
Test: atest aconfig.test
Change-Id: If3fca67c415af75b44f316e16666b97089407069
Add a new "create-device-config-sysprops" command that works like
"create-device-config-defaults" but for system properties.
DeviceConfig is a Java service, and will mirror (some of) its values by
setting system properties in the persist.device_config namespace. Native
code will access DeviceConfig (actually, the system properties) via the
server_configurable_flags library.
The new command writes a file that can be appended to /system/build.prop
to pre-populate persist.device_config before DeviceConfig has started.
Like create-device-config-defaults, the new command skips READ_ONLY
flags.
Bug: 285468565
Test: atest aconfig.test
Change-Id: I311c7c5e0b03dc897b09204137d43cc182324717
DeviceConfig is the backend for READ_WRITE flags.
Add a new command "create-device-config-defaults" to create a file that
DeviceConfig will read to pre-populate its data store on first init.
This will be used to quickly switch flag values during CI tests:
rebuilding and reflashing a device would have the same effect, but would
be costlier. This feature is not expected to be used outside CI tests.
Note: because DeviceConfig only works with READ_WRITE flags, the
generated file excludes READ_ONLY flags.
Bug: 285468565
Test: atest aconfig.test
Change-Id: I4caff1a10647b8da0ce4e3615678993a957a92dd
Create a test utility function to create a Cache from the files in
testdata/*. A follow-up CL will update the unit tests to use this
instead of creating their own caches.
Bug: 283910447
Test: atest aconfig.test
Change-Id: Ice5064eadb0babde5eb38d292330d213ab136d96
Remove unnecessary use from the cache::test module: they already covered
by `use super:*;`.
Bug: 283910447
Test: atest aconfig.test
Change-Id: I9e03385629f38180c0f92080c7f097a8e0d9ef69
Pass the Cache argument to command::create_<lang>_lib functions by value
instead of by reference, to align with other commands.
The intended ownership flow is as follows:
- main creates objects based on command line arguments
- main hands commands ownership of the objects
- command processes the objects
- command gives main ownership of any generated output
- main writes the output to file
Rationale: commands.rs is a unit testable version of main, and to the
rest of aconfig, acts as the top level entry point; main.rs exists only
to parse command line arguments and perform I/O.
Bug: 283910447
Test: atest aconfig.test
Change-Id: I1e1dea7da8ecc2bb6e2f7ee4a6df64562c148959
The namespace and flag names will be used as identifiers in the
auto-generated code. Place restrictions on what constitutes a valid
name.
Valid identifiers are those that match /[a-z][a-z0-9_]/. aconfig
explicitly does not implement any automatic translation to make names
valid identifiers: this sidesteps potential conflicts such as "foo.bar"
and "foo_bar" mapping to the same name if dots were translated to
underscores.
Bug: b/284252015
Test: atest aconfig.test
Change-Id: I38d005a74311e5829e540063404d1565071e6e96
Add a new `create-rust-lib` command to generate Rust code. The output is
a src/lib.rs file; the build system is assumed to set the generated
crate's name.
For READ_ONLY flags, the generated code returns a hard-coded true or false.
For READ_WRITE flags, the generated code reaches out to DeviceConfig via
the cc_library server_configurable_flags via the
libprofcollect_libflags_rust Rust bindings. The build system is assumed
to add this to the generated crate's dependencies.
Note: libprofcollect_libflags_rust seems generic enough that it should
be moved to an official Rust wrapper for server_configurable_flags. This
is tracked in b/284096062.
Summary of module the built system is assumed to wrap the auto-generated
code in:
rust_library {
name: "lib<namespace>_rs",
crate_name: "<namespace>_rs",
edition: "2021",
clippy_lints: "none",
no_stdlibs: true,
lints: "none",
srcs: ["src/lib.rs"],
rustlibs: [
"libprofcollect_libflags_rust",
],
}
Also add a set of test input to be used in the unit tests for a more
coherent test strategy. A follow-up CL will migrate the code in
commands.rs, codegen_java.rs and codegen_cpp.rs.
Bug: 279483360
Bug: 283907905
Test: atest aconfig.test
Test: manual: create cache from files in testdata, create rust lib, add to module template above, verify the module builds
Change-Id: I02606aa3686eda921116e33f7e2df8fd1156a7aa
Introduce a builder pattern for constructing a cache from flag
declarations and flag values. Teach the builder to sort the flags by
name as the last step. This will ensure consistent dump output
regardless of the order flags are specified in the input files.
Bug: 279485059
Test: atest aconfig.test
Change-Id: Icdd62f51fa3761a469663f17581a83d9909e9ffe
Teach `aconfig dump` to read multiple caches at the same time.
A cache represents a single namespace, and the Android build creates
multiple caches for different namespaces. By passing in all those cache
files to `aconfig dump`, aconfig will create a complete overview of all
flags in the Android tree.
Caches are traversed in order of namespace to produce the same output
regardless of the order the cache files are given on the command line.
If two caches use the same namespace, their order with respect to each
other is undefined.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I54c3950bbb7b2be7d96c8928e78ae83aa626c2e2
The general idea to reuse java codegen's very neat tiny template idea.
For generated cpp code, it is in the form of a collection of classes
inside a namespace. The reason we choose a collection of classes rather
than a collection of static functions is because gmock test technology
only supports mocking virtual method.
Bug: b/279483801
Test: atest aconfig.test
Change-Id: I9ba00667437ff7c3e147ff2828171fc95528bebf
Add invariant to struct Cache: all flag namespace and name fields added
to the cache are required to be non-empty strings.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I5ff34ec8feccc19e52241d4221fc87699518f3ff
Do not call unwrap outside tests: replace existing uses with Result
return values or infallible alternatives.
Bug: 279485059
Test: atest aconfig.test
Change-Id: Ie5919b704b23a0f96bbef84ffbe9270d667cecd8
Rename enum Format to enum DumpFormat to make it more apparent what it
refers to.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I869be020b69618b036fa05247f155d9e35ff85e2
Update codegen_java to write the generated Java file(s) to
"java/package/File.java" instead of just "File.java".
Also generalize codegen_java::GeneratedFile to commands::OutputFile in
preparation for the upcoming C++ and Rust codegen.
Also change Java package name to 'com.android.internal.aconfig'.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I13978697e35010fe6be8637aa495d4b852dbed7e
Simplify how aconfig configurations work: remove the ability to set flag
values based on build-id.
The aconfig files now some in two flavours:
- flag declaration files: introduce new flags; aconfig will assign the
flags a hard-coded default value (disabled, read-write)
- flag value files: assign flags new values
`aconfig create-cache` expects flags to be declared exactly once, and
for their values to be reassigned zero or more times.
The flag value files are identical what used to be called override
files.
Also, remove the now obsolete build-id parameter: this was used to
calculate default values before applying overrides, and is no longer
needed.
Also rename a few more structs and functions to be closer to the .proto
names. This will make it easier to use the generated proto structs
directly, and get rid of the hand-crafter wrappers.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I7bf881338b0567f932099ce419cac457abbe8df8
Flags belong to a namespace. Update the proto files to reflect this.
Config files can only refer to a single namespace. Override files can
refer to multiple namespaces; an override directive for a flag in a
different namespace than the one represented by the cache will be
silently ignored.
Rename the proto messages to make it more clear what they are. Propagate
this change through the wrappers in aconfig.rs and the rest of the code.
Also, settle on Tracepoint instead of TracePoint.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I16e69dd14687bc498b2ba89d6a35879459903801
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
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
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
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
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
The Source struct is no longer serialized/deserialized. Remove the
unused derives.
Bug: 279485059
Test: atest aconfig.test
Change-Id: Ifd78988ed8134ab43013314b4437e428a8927981
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
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