Merge "aconfig: update cpp_codegen to just read from new storage" into main
diff --git a/ci/build_metadata b/ci/build_metadata
index 8136702..a8eb65d 100755
--- a/ci/build_metadata
+++ b/ci/build_metadata
@@ -21,5 +21,5 @@
export TARGET_BUILD_VARIANT=eng
build/soong/bin/m dist \
- code_metadata
+ all_teams
diff --git a/ci/optimized_targets.py b/ci/optimized_targets.py
index 9143cbf..4bee401 100644
--- a/ci/optimized_targets.py
+++ b/ci/optimized_targets.py
@@ -16,12 +16,13 @@
from abc import ABC
import argparse
import functools
-from build_context import BuildContext
import json
import logging
import os
-from typing import Self
+import pathlib
+import subprocess
+from build_context import BuildContext
import test_mapping_module_retriever
@@ -33,6 +34,9 @@
build.
"""
+ _SOONG_UI_BASH_PATH = 'build/soong/soong_ui.bash'
+ _PREBUILT_SOONG_ZIP_PATH = 'prebuilts/build-tools/linux-x86/bin/soong_zip'
+
def __init__(
self,
target: str,
@@ -75,6 +79,88 @@
f'get_build_targets_impl not implemented in {type(self).__name__}'
)
+ def _generate_zip_options_for_items(
+ self,
+ prefix: str = '',
+ relative_root: str = '',
+ list_files: list[str] | None = None,
+ files: list[str] | None = None,
+ directories: list[str] | None = None,
+ ) -> list[str]:
+ if not list_files and not files and not directories:
+ raise RuntimeError(
+ f'No items specified to be added to zip! Prefix: {prefix}, Relative'
+ f' root: {relative_root}'
+ )
+ command_segment = []
+ # These are all soong_zip options so consult soong_zip --help for specifics.
+ if prefix:
+ command_segment.append('-P')
+ command_segment.append(prefix)
+ if relative_root:
+ command_segment.append('-C')
+ command_segment.append(relative_root)
+ if list_files:
+ for list_file in list_files:
+ command_segment.append('-l')
+ command_segment.append(list_file)
+ if files:
+ for file in files:
+ command_segment.append('-f')
+ command_segment.append(file)
+ if directories:
+ for directory in directories:
+ command_segment.append('-D')
+ command_segment.append(directory)
+
+ return command_segment
+
+ def _query_soong_vars(
+ self, src_top: pathlib.Path, soong_vars: list[str]
+ ) -> dict[str, str]:
+ process_result = subprocess.run(
+ args=[
+ f'{src_top / self._SOONG_UI_BASH_PATH}',
+ '--dumpvar-mode',
+ '--abs',
+ soong_vars,
+ ],
+ env=os.environ,
+ check=False,
+ capture_output=True,
+ )
+ if not process_result.returncode == 0:
+ logging.error('soong dumpvars command failed! stderr:')
+ logging.error(process_result.stderr)
+ raise RuntimeError('Soong dumpvars failed! See log for stderr.')
+
+ if not process_result.stdout:
+ raise RuntimeError(
+ 'Necessary soong variables ' + soong_vars + ' not found.'
+ )
+
+ try:
+ return {
+ line.split('=')[0]: line.split('=')[1].strip("'")
+ for line in process_result.stdout.split('\n')
+ }
+ except IndexError as e:
+ raise RuntimeError(
+ 'Error parsing soong dumpvars output! See output here:'
+ f' {process_result.stdout}',
+ e,
+ )
+
+ def _base_zip_command(
+ self, src_top: pathlib.Path, dist_dir: pathlib.Path, name: str
+ ) -> list[str]:
+ return [
+ f'{src_top / self._PREBUILT_SOONG_ZIP_PATH }',
+ '-d',
+ '-o',
+ f'{dist_dir / name}',
+ ]
+
class NullOptimizer(OptimizedBuildTarget):
"""No-op target optimizer.
@@ -121,8 +207,6 @@
class GeneralTestsOptimizer(OptimizedBuildTarget):
"""general-tests optimizer
- TODO(b/358215235): Implement
-
This optimizer reads in the list of changed files from the file located in
env[CHANGE_INFO] and uses this list alongside the normal TEST MAPPING logic to
determine what test mapping modules will run for the given changes. It then
@@ -177,6 +261,208 @@
return modules_to_build
+ def get_package_outputs_commands_impl(self):
+ src_top = pathlib.Path(os.environ.get('TOP', os.getcwd()))
+ dist_dir = pathlib.Path(os.environ.get('DIST_DIR'))
+
+ soong_vars = self._query_soong_vars(
+ src_top,
+ [
+ 'HOST_OUT_TESTCASES',
+ 'TARGET_OUT_TESTCASES',
+ 'PRODUCT_OUT',
+ 'SOONG_HOST_OUT',
+ 'HOST_OUT',
+ ],
+ )
+ host_out_testcases = pathlib.Path(soong_vars.get('HOST_OUT_TESTCASES'))
+ target_out_testcases = pathlib.Path(soong_vars.get('TARGET_OUT_TESTCASES'))
+ product_out = pathlib.Path(soong_vars.get('PRODUCT_OUT'))
+ soong_host_out = pathlib.Path(soong_vars.get('SOONG_HOST_OUT'))
+ host_out = pathlib.Path(soong_vars.get('HOST_OUT'))
+
+ host_paths = []
+ target_paths = []
+ host_config_files = []
+ target_config_files = []
+ for module in self.modules_to_build:
+ host_path = host_out_testcases / module
+ if os.path.exists(host_path):
+ host_paths.append(host_path)
+ self._collect_config_files(src_top, host_path, host_config_files)
+
+ target_path = target_out_testcases / module
+ if os.path.exists(target_path):
+ target_paths.append(target_path)
+ self._collect_config_files(src_top, target_path, target_config_files)
+
+ if not os.path.exists(host_path) and not os.path.exists(target_path):
+ logging.info(f'No host or target build outputs found for {module}.')
+
+ zip_commands = []
+
+ zip_commands.extend(
+ self._get_zip_test_configs_zips_commands(
+ dist_dir,
+ host_out,
+ product_out,
+ host_config_files,
+ target_config_files,
+ )
+ )
+
+ zip_command = self._base_zip_command(
+ host_out, dist_dir, 'general-tests.zip'
+ )
+
+ # Add host testcases.
+ zip_command.extend(
+ self._generate_zip_options_for_items(
+ prefix='host',
+ relative_root=f'{src_top / soong_host_out}',
+ directories=host_paths,
+ )
+ )
+
+ # Add target testcases.
+ zip_command.extend(
+ self._generate_zip_options_for_items(
+ prefix='target',
+ relative_root=f'{src_top / product_out}',
+ directories=target_paths,
+ )
+ )
+
+ # TODO(lucafarsi): Push this logic into a general-tests-minimal build command
+ # Add necessary tools. These are also hardcoded in general-tests.mk.
+ framework_path = soong_host_out / 'framework'
+
+ zip_command.extend(
+ self._generate_zip_options_for_items(
+ prefix='host/tools',
+ relative_root=str(framework_path),
+ files=[
+ f"{framework_path / 'cts-tradefed.jar'}",
+ f"{framework_path / 'compatibility-host-util.jar'}",
+ f"{framework_path / 'vts-tradefed.jar'}",
+ ],
+ )
+ )
+
+ zip_commands.append(zip_command)
+ return zip_commands
+
+ def _collect_config_files(
+ self,
+ src_top: pathlib.Path,
+ root_dir: pathlib.Path,
+ config_files: list[str],
+ ):
+ for root, dirs, files in os.walk(src_top / root_dir):
+ for file in files:
+ if file.endswith('.config'):
+ config_files.append(root_dir / file)
+
+ def _get_zip_test_configs_zips_commands(
+ self,
+ dist_dir: pathlib.Path,
+ host_out: pathlib.Path,
+ product_out: pathlib.Path,
+ host_config_files: list[str],
+ target_config_files: list[str],
+ ) -> tuple[list[str], list[str]]:
+ """Generate general-tests_configs.zip and general-tests_list.zip.
+
+ general-tests_configs.zip contains all of the .config files that were
+ built and general-tests_list.zip contains a text file which lists
+ all of the .config files that are in general-tests_configs.zip.
+
+ general-tests_configs.zip is organized as follows:
+ /
+ host/
+ testcases/
+ test_1.config
+ test_2.config
+ ...
+ target/
+ testcases/
+ test_1.config
+ test_2.config
+ ...
+
+ So the process is we write out the paths to all the host config files into
+ one
+ file and all the paths to the target config files in another. We also write
+ the paths to all the config files into a third file to use for
+ general-tests_list.zip.
+
+ Args:
+ dist_dir: dist directory.
+ host_out: host out directory.
+ product_out: product out directory.
+ host_config_files: list of all host config files.
+ target_config_files: list of all target config files.
+
+ Returns:
+ The commands to generate general-tests_configs.zip and
+ general-tests_list.zip
+ """
+ with open(
+ f"{host_out / 'host_general-tests_list'}", 'w'
+ ) as host_list_file, open(
+ f"{product_out / 'target_general-tests_list'}", 'w'
+ ) as target_list_file, open(
+ f"{host_out / 'general-tests_list'}", 'w'
+ ) as list_file:
+
+ for config_file in host_config_files:
+ host_list_file.write(f'{config_file}' + '\n')
+ list_file.write('host/' + os.path.relpath(config_file, host_out) + '\n')
+
+ for config_file in target_config_files:
+ target_list_file.write(f'{config_file}' + '\n')
+ list_file.write(
+ 'target/' + os.path.relpath(config_file, product_out) + '\n'
+ )
+
+ zip_commands = []
+
+ tests_config_zip_command = self._base_zip_command(
+ host_out, dist_dir, 'general-tests_configs.zip'
+ )
+ tests_config_zip_command.extend(
+ self._generate_zip_options_for_items(
+ prefix='host',
+ relative_root=str(host_out),
+ list_files=[f"{host_out / 'host_general-tests_list'}"],
+ )
+ )
+
+ tests_config_zip_command.extend(
+ self._generate_zip_options_for_items(
+ prefix='target',
+ relative_root=str(product_out),
+ list_files=[
+ f"{product_out / 'target_general-tests_list'}"
+ ],
+ ),
+ )
+
+ zip_commands.append(tests_config_zip_command)
+
+ tests_list_zip_command = self._base_zip_command(
+ host_out, dist_dir, 'general-tests_list.zip'
+ )
+ tests_list_zip_command.extend(
+ self._generate_zip_options_for_items(
+ relative_root=str(host_out),
+ files=[f"{host_out / 'general-tests_list'}"],
+ )
+ )
+ zip_commands.append(tests_list_zip_command)
+
+ return zip_commands
+
def get_enabled_flag(self):
return 'general_tests_optimized'
diff --git a/ci/optimized_targets_test.py b/ci/optimized_targets_test.py
index 919c193..762b62e 100644
--- a/ci/optimized_targets_test.py
+++ b/ci/optimized_targets_test.py
@@ -19,10 +19,12 @@
import os
import pathlib
import re
+import subprocess
+import textwrap
import unittest
from unittest import mock
-import optimized_targets
from build_context import BuildContext
+import optimized_targets
from pyfakefs import fake_filesystem_unittest
@@ -43,11 +45,68 @@
def _setup_working_build_env(self):
self.change_info_file = pathlib.Path('/tmp/change_info')
+ self._write_soong_ui_file()
+ self._host_out_testcases = pathlib.Path('/tmp/top/host_out_testcases')
+ self._host_out_testcases.mkdir(parents=True)
+ self._target_out_testcases = pathlib.Path('/tmp/top/target_out_testcases')
+ self._target_out_testcases.mkdir(parents=True)
+ self._product_out = pathlib.Path('/tmp/top/product_out')
+ self._product_out.mkdir(parents=True)
+ self._soong_host_out = pathlib.Path('/tmp/top/soong_host_out')
+ self._soong_host_out.mkdir(parents=True)
+ self._host_out = pathlib.Path('/tmp/top/host_out')
+ self._host_out.mkdir(parents=True)
+
+ self._dist_dir = pathlib.Path('/tmp/top/out/dist')
+ self._dist_dir.mkdir(parents=True)
self.mock_os_environ.update({
'CHANGE_INFO': str(self.change_info_file),
+ 'TOP': '/tmp/top',
+ 'DIST_DIR': '/tmp/top/out/dist',
})
+ def _write_soong_ui_file(self):
+ soong_path = pathlib.Path('/tmp/top/build/soong')
+ soong_path.mkdir(parents=True)
+ with open(os.path.join(soong_path, 'soong_ui.bash'), 'w') as f:
+ f.write("""
+ #/bin/bash
+ echo HOST_OUT_TESTCASES='/tmp/top/host_out_testcases'
+ echo TARGET_OUT_TESTCASES='/tmp/top/target_out_testcases'
+ echo PRODUCT_OUT='/tmp/top/product_out'
+ echo SOONG_HOST_OUT='/tmp/top/soong_host_out'
+ echo HOST_OUT='/tmp/top/host_out'
+ """)
+ os.chmod(os.path.join(soong_path, 'soong_ui.bash'), 0o666)
+
+ def _write_change_info_file(self):
+ change_info_contents = {
+ 'changes': [{
+ 'projectPath': '/project/path',
+ 'revisions': [{
+ 'fileInfos': [{
+ 'path': 'file/path/file_name',
+ }],
+ }],
+ }]
+ }
+
+ with open(self.change_info_file, 'w') as f:
+ json.dump(change_info_contents, f)
+
+ def _write_test_mapping_file(self):
+ test_mapping_contents = {
+ 'test-mapping-group': [
+ {
+ 'name': 'test_mapping_module',
+ },
+ ],
+ }
+
+ with open('/project/path/file/path/TEST_MAPPING', 'w') as f:
+ json.dump(test_mapping_contents, f)
+
def test_general_tests_optimized(self):
optimizer = self._create_general_tests_optimizer()
@@ -124,36 +183,56 @@
with self.assertRaises(json.decoder.JSONDecodeError):
build_targets = optimizer.get_build_targets()
- def _write_change_info_file(self):
- change_info_contents = {
- 'changes': [{
- 'projectPath': '/project/path',
- 'revisions': [{
- 'fileInfos': [{
- 'path': 'file/path/file_name',
- }],
- }],
- }]
- }
+ @mock.patch('subprocess.run')
+ def test_packaging_outputs_success(self, subprocess_run):
+ subprocess_run.return_value = self._get_soong_vars_output()
+ optimizer = self._create_general_tests_optimizer()
+ self._set_up_build_outputs(['test_mapping_module'])
- with open(self.change_info_file, 'w') as f:
- json.dump(change_info_contents, f)
+ targets = optimizer.get_build_targets()
+ package_commands = optimizer.get_package_outputs_commands()
- def _write_test_mapping_file(self):
- test_mapping_contents = {
- 'test-mapping-group': [
- {
- 'name': 'test_mapping_module',
- },
- ],
- }
+ self._verify_soong_zip_commands(package_commands, ['test_mapping_module'])
- with open('/project/path/file/path/TEST_MAPPING', 'w') as f:
- json.dump(test_mapping_contents, f)
+ @mock.patch('subprocess.run')
+ def test_get_soong_dumpvars_fails_raises(self, subprocess_run):
+ subprocess_run.return_value = self._get_soong_vars_output(return_code=-1)
+ optimizer = self._create_general_tests_optimizer()
+ self._set_up_build_outputs(['test_mapping_module'])
- def _create_general_tests_optimizer(
- self, build_context: BuildContext = None
- ):
+ targets = optimizer.get_build_targets()
+
+ with self.assertRaisesRegex(RuntimeError, 'Soong dumpvars failed!'):
+ package_commands = optimizer.get_package_outputs_commands()
+
+ @mock.patch('subprocess.run')
+ def test_get_soong_dumpvars_bad_output_raises(self, subprocess_run):
+ subprocess_run.return_value = self._get_soong_vars_output(
+ stdout='This output is bad'
+ )
+ optimizer = self._create_general_tests_optimizer()
+ self._set_up_build_outputs(['test_mapping_module'])
+
+ targets = optimizer.get_build_targets()
+
+ with self.assertRaisesRegex(
+ RuntimeError, 'Error parsing soong dumpvars output'
+ ):
+ package_commands = optimizer.get_package_outputs_commands()
+
+ @mock.patch('subprocess.run')
+ def test_no_build_outputs_packaging_fails(self, subprocess_run):
+ subprocess_run.return_value = self._get_soong_vars_output()
+ optimizer = self._create_general_tests_optimizer()
+
+ targets = optimizer.get_build_targets()
+
+ with self.assertRaisesRegex(
+ RuntimeError, 'No items specified to be added to zip'
+ ):
+ package_commands = optimizer.get_package_outputs_commands()
+
+ def _create_general_tests_optimizer(self, build_context: BuildContext = None):
if not build_context:
build_context = self._create_build_context()
return optimized_targets.GeneralTestsOptimizer(
@@ -170,7 +249,9 @@
build_context_dict = {}
build_context_dict['enabledBuildFeatures'] = [{'name': 'optimized_build'}]
if general_tests_optimized:
- build_context_dict['enabledBuildFeatures'].append({'name': 'general_tests_optimized'})
+ build_context_dict['enabledBuildFeatures'].append(
+ {'name': 'general_tests_optimized'}
+ )
build_context_dict['testContext'] = test_context
return BuildContext(build_context_dict)
@@ -199,6 +280,81 @@
],
}
+ def _get_soong_vars_output(
+ self, return_code: int = 0, stdout: str = ''
+ ) -> subprocess.CompletedProcess:
+ return_value = subprocess.CompletedProcess(args=[], returncode=return_code)
+ if not stdout:
+ stdout = textwrap.dedent(f"""\
+ HOST_OUT_TESTCASES='{self._host_out_testcases}'
+ TARGET_OUT_TESTCASES='{self._target_out_testcases}'
+ PRODUCT_OUT='{self._product_out}'
+ SOONG_HOST_OUT='{self._soong_host_out}'
+ HOST_OUT='{self._host_out}'""")
+
+ return_value.stdout = stdout
+ return return_value
+
+ def _set_up_build_outputs(self, targets: list[str]):
+ for target in targets:
+ host_dir = self._host_out_testcases / target
+ host_dir.mkdir()
+ (host_dir / f'{target}.config').touch()
+ (host_dir / f'test_file').touch()
+
+ target_dir = self._target_out_testcases / target
+ target_dir.mkdir()
+ (target_dir / f'{target}.config').touch()
+ (target_dir / f'test_file').touch()
+
+ def _verify_soong_zip_commands(self, commands: list[str], targets: list[str]):
+ """Verify the structure of the zip commands.
+
+ Zip commands have to start with the soong_zip binary path, then are followed
+ by a couple of options and the name of the file being zipped. Depending on
+ which zip we are creating look for a few essential items being added in
+ those zips.
+
+ Args:
+ commands: list of command lists
+ targets: list of targets expected to be in general-tests.zip
+ """
+ for command in commands:
+ self.assertEqual(
+ '/tmp/top/host_out/prebuilts/build-tools/linux-x86/bin/soong_zip',
+ command[0],
+ )
+ self.assertEqual('-d', command[1])
+ self.assertEqual('-o', command[2])
+ match (command[3]):
+ case '/tmp/top/out/dist/general-tests_configs.zip':
+ self.assertIn(f'{self._host_out}/host_general-tests_list', command)
+ self.assertIn(
+ f'{self._product_out}/target_general-tests_list', command
+ )
+ return
+ case '/tmp/top/out/dist/general-tests_list.zip':
+ self.assertIn('-f', command)
+ self.assertIn(f'{self._host_out}/general-tests_list', command)
+ return
+ case '/tmp/top/out/dist/general-tests.zip':
+ for target in targets:
+ self.assertIn(f'{self._host_out_testcases}/{target}', command)
+ self.assertIn(f'{self._target_out_testcases}/{target}', command)
+ self.assertIn(
+ f'{self._soong_host_out}/framework/cts-tradefed.jar', command
+ )
+ self.assertIn(
+ f'{self._soong_host_out}/framework/compatibility-host-util.jar',
+ command,
+ )
+ self.assertIn(
+ f'{self._soong_host_out}/framework/vts-tradefed.jar', command
+ )
+ return
+ case _:
+ self.fail(f'malformed command: {command}')
+
if __name__ == '__main__':
# Setup logging to be silent so unit tests can pass through TF.
diff --git a/core/Makefile b/core/Makefile
index f376014..b0392cd 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -3588,10 +3588,10 @@
ifeq ($(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE),)
$(error PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE must be set if USE_SOONG_DEFINED_SYSTEM_IMAGE is true)
endif
-soong_defined_system_image := $(call intermediates-dir-for,ETC,$(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE))/$(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE)
-$(BUILT_SYSTEMIMAGE): $(INSTALLED_FILES_FILE) $(systemimage_intermediates)/file_list.txt $(soong_defined_system_image)
-$(eval $(call copy-one-file, $(soong_defined_system_image), $(BUILT_SYSTEMIMAGE)))
-soong_defined_system_image :=
+SOONG_DEFINED_SYSTEM_IMAGE_PATH := $(call intermediates-dir-for,ETC,$(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE))/$(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE)
+SOONG_DEFINED_SYSTEM_IMAGE_BASE := $(dir $(ALL_MODULES.$(PRODUCT_SOONG_DEFINED_SYSTEM_IMAGE).FILESYSTEM_FILELIST))
+$(BUILT_SYSTEMIMAGE): $(INSTALLED_FILES_FILE) $(systemimage_intermediates)/file_list.txt $(SOONG_DEFINED_SYSTEM_IMAGE_PATH)
+$(eval $(call copy-one-file, $(SOONG_DEFINED_SYSTEM_IMAGE_PATH), $(BUILT_SYSTEMIMAGE)))
else
$(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE) $(systemimage_intermediates)/file_list.txt
$(call build-systemimage-target,$@)
@@ -6134,6 +6134,9 @@
$(BUILT_TARGET_FILES_DIR): zip_root := $(intermediates)/$(name)
$(BUILT_TARGET_FILES_DIR): intermediates := $(intermediates)
+ifneq ($(SOONG_DEFINED_SYSTEM_IMAGE_PATH),)
+ $(BUILT_TARGET_FILES_DIR): $(SOONG_DEFINED_SYSTEM_IMAGE_PATH)
+endif
# $(1): Directory to copy
# $(2): Location to copy it to
@@ -6620,8 +6623,13 @@
endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET
ifdef BUILDING_SYSTEM_IMAGE
@# Contents of the system image
+ifneq ($(SOONG_DEFINED_SYSTEM_IMAGE_PATH),)
+ $(hide) $(call package_files-copy-root, \
+ $(SOONG_DEFINED_SYSTEM_IMAGE_BASE)/root/system,$(zip_root)/SYSTEM)
+else
$(hide) $(call package_files-copy-root, \
$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
+endif
else ifdef INSTALLED_BUILD_PROP_TARGET
@# Copy the system build.prop even if not building a system image
@# because add_img_to_target_files may need it to build other partition
diff --git a/tools/aconfig/aconfig/src/codegen/rust.rs b/tools/aconfig/aconfig/src/codegen/rust.rs
index 6f3f7bf..7bc34d6 100644
--- a/tools/aconfig/aconfig/src/codegen/rust.rs
+++ b/tools/aconfig/aconfig/src/codegen/rust.rs
@@ -116,10 +116,6 @@
use std::sync::LazyLock;
use log::{log, LevelFilter, Level};
-static STORAGE_MIGRATION_MARKER_FILE: &str =
- "/metadata/aconfig_test_missions/mission_1";
-static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
-
/// flag provider
pub struct FlagProvider;
@@ -260,13 +256,13 @@
use std::sync::LazyLock;
use log::{log, LevelFilter, Level};
-static STORAGE_MIGRATION_MARKER_FILE: &str =
- "/metadata/aconfig_test_missions/mission_1";
-static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
-
/// flag provider
pub struct FlagProvider;
+static READ_FROM_NEW_STORAGE: LazyLock<bool> = LazyLock::new(|| unsafe {
+ Path::new("/metadata/aconfig/boot/enable_only_new_storage").exists()
+});
+
static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe {
get_mapped_storage_file("system", StorageFileType::PackageMap)
.and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test"))
@@ -279,24 +275,14 @@
/// flag value cache for disabled_rw
static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| {
- let result = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.aconfig_test",
- "com.android.aconfig.test.disabled_rw",
- "false") == "true";
-
- let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.core_experiments_team_internal",
- "com.android.providers.settings.use_new_storage_value",
- "false") == "true";
-
- if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
+ if *READ_FROM_NEW_STORAGE {
// This will be called multiple times. Subsequent calls after the first are noops.
logger::init(
logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
+ .with_tag_on_device("aconfig_rust_codegen")
.with_max_level(LevelFilter::Info));
- let aconfig_storage_result = FLAG_VAL_MAP
+ let flag_value_result = FLAG_VAL_MAP
.as_ref()
.map_err(|err| format!("failed to get flag val map: {err}"))
.and_then(|flag_val_map| {
@@ -314,54 +300,33 @@
})
});
- match aconfig_storage_result {
- Ok(storage_result) if storage_result == result => {
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
- },
- Ok(storage_result) => {
- log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
+ match flag_value_result {
+ Ok(flag_value) => {
+ return flag_value;
},
Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: {err}");
- if use_new_storage_value {
- panic!("failed to read flag value: {err}");
- }
+ log!(Level::Error, "aconfig_rust_codegen: error: {err}");
+ panic!("failed to read flag value: {err}");
}
}
+ } else {
+ flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.aconfig_test",
+ "com.android.aconfig.test.disabled_rw",
+ "false") == "true"
}
-
- result
});
/// flag value cache for disabled_rw_exported
static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| {
- let result = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.aconfig_test",
- "com.android.aconfig.test.disabled_rw_exported",
- "false") == "true";
-
- let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.core_experiments_team_internal",
- "com.android.providers.settings.use_new_storage_value",
- "false") == "true";
-
- if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
+ if *READ_FROM_NEW_STORAGE {
// This will be called multiple times. Subsequent calls after the first are noops.
logger::init(
logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
+ .with_tag_on_device("aconfig_rust_codegen")
.with_max_level(LevelFilter::Info));
- let aconfig_storage_result = FLAG_VAL_MAP
+ let flag_value_result = FLAG_VAL_MAP
.as_ref()
.map_err(|err| format!("failed to get flag val map: {err}"))
.and_then(|flag_val_map| {
@@ -379,54 +344,33 @@
})
});
- match aconfig_storage_result {
- Ok(storage_result) if storage_result == result => {
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
- },
- Ok(storage_result) => {
- log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_exported'. Legacy storage was {result}, new storage was {storage_result}");
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
+ match flag_value_result {
+ Ok(flag_value) => {
+ return flag_value;
},
Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: {err}");
- if use_new_storage_value {
- panic!("failed to read flag value: {err}");
- }
+ log!(Level::Error, "aconfig_rust_codegen: error: {err}");
+ panic!("failed to read flag value: {err}");
}
}
+ } else {
+ flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.aconfig_test",
+ "com.android.aconfig.test.disabled_rw_exported",
+ "false") == "true"
}
-
- result
});
/// flag value cache for disabled_rw_in_other_namespace
static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| {
- let result = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.other_namespace",
- "com.android.aconfig.test.disabled_rw_in_other_namespace",
- "false") == "true";
-
- let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.core_experiments_team_internal",
- "com.android.providers.settings.use_new_storage_value",
- "false") == "true";
-
- if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
+ if *READ_FROM_NEW_STORAGE {
// This will be called multiple times. Subsequent calls after the first are noops.
logger::init(
logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
+ .with_tag_on_device("aconfig_rust_codegen")
.with_max_level(LevelFilter::Info));
- let aconfig_storage_result = FLAG_VAL_MAP
+ let flag_value_result = FLAG_VAL_MAP
.as_ref()
.map_err(|err| format!("failed to get flag val map: {err}"))
.and_then(|flag_val_map| {
@@ -444,55 +388,34 @@
})
});
- match aconfig_storage_result {
- Ok(storage_result) if storage_result == result => {
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
- },
- Ok(storage_result) => {
- log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_in_other_namespace'. Legacy storage was {result}, new storage was {storage_result}");
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
+ match flag_value_result {
+ Ok(flag_value) => {
+ return flag_value;
},
Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: {err}");
- if use_new_storage_value {
- panic!("failed to read flag value: {err}");
- }
+ log!(Level::Error, "aconfig_rust_codegen: error: {err}");
+ panic!("failed to read flag value: {err}");
}
}
+ } else {
+ flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.other_namespace",
+ "com.android.aconfig.test.disabled_rw_in_other_namespace",
+ "false") == "true"
}
-
- result
});
/// flag value cache for enabled_rw
static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| {
- let result = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.aconfig_test",
- "com.android.aconfig.test.enabled_rw",
- "true") == "true";
-
- let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.core_experiments_team_internal",
- "com.android.providers.settings.use_new_storage_value",
- "false") == "true";
-
- if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
+ if *READ_FROM_NEW_STORAGE {
// This will be called multiple times. Subsequent calls after the first are noops.
logger::init(
logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
+ .with_tag_on_device("aconfig_rust_codegen")
.with_max_level(LevelFilter::Info));
- let aconfig_storage_result = FLAG_VAL_MAP
+ let flag_value_result = FLAG_VAL_MAP
.as_ref()
.map_err(|err| format!("failed to get flag val map: {err}"))
.and_then(|flag_val_map| {
@@ -510,32 +433,21 @@
})
});
- match aconfig_storage_result {
- Ok(storage_result) if storage_result == result => {
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
- },
- Ok(storage_result) => {
- log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'enabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
- if use_new_storage_value {
- return storage_result;
- } else {
- return result;
- }
+ match flag_value_result {
+ Ok(flag_value) => {
+ return flag_value;
},
Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: {err}");
- if use_new_storage_value {
- panic!("failed to read flag value: {err}");
- }
+ log!(Level::Error, "aconfig_rust_codegen: error: {err}");
+ panic!("failed to read flag value: {err}");
}
}
+ } else {
+ flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.aconfig_test",
+ "com.android.aconfig.test.enabled_rw",
+ "true") == "true"
}
-
- result
});
impl FlagProvider {
@@ -596,65 +508,7 @@
/// query flag disabled_ro
#[inline(always)]
pub fn disabled_ro() -> bool {
-
-
- let result = false;
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe {
- let package_map = match get_mapped_storage_file("system", StorageFileType::PackageMap) {
- Ok(file) => file,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'disabled_ro': {err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "com.android.aconfig.test") {
- Ok(Some(context)) => context,
- Ok(None) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'disabled_ro': did not get context");
- return result;
- },
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'disabled_ro': {err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("system", StorageFileType::FlagVal) {
- Ok(val_map) => val_map,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'disabled_ro': {err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, 0 + package_read_context.boolean_start_index) {
- Ok(val) => val,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'disabled_ro': {err}");
- return result;
- }
- };
-
- if result != value {
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for 'disabled_ro'. Legacy storage was {result}, new storage was {value}");
- } else {
- let default_value = false;
- }
- }
-
- result
-
+ false
}
/// query flag disabled_rw
@@ -678,257 +532,25 @@
/// query flag enabled_fixed_ro
#[inline(always)]
pub fn enabled_fixed_ro() -> bool {
-
-
- let result = true;
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe {
- let package_map = match get_mapped_storage_file("system", StorageFileType::PackageMap) {
- Ok(file) => file,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro': {err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "com.android.aconfig.test") {
- Ok(Some(context)) => context,
- Ok(None) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro': did not get context");
- return result;
- },
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro': {err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("system", StorageFileType::FlagVal) {
- Ok(val_map) => val_map,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro': {err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, 4 + package_read_context.boolean_start_index) {
- Ok(val) => val,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro': {err}");
- return result;
- }
- };
-
- if result != value {
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for 'enabled_fixed_ro'. Legacy storage was {result}, new storage was {value}");
- } else {
- let default_value = true;
- }
- }
-
- result
-
+ true
}
/// query flag enabled_fixed_ro_exported
#[inline(always)]
pub fn enabled_fixed_ro_exported() -> bool {
-
-
- let result = true;
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe {
- let package_map = match get_mapped_storage_file("system", StorageFileType::PackageMap) {
- Ok(file) => file,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro_exported': {err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "com.android.aconfig.test") {
- Ok(Some(context)) => context,
- Ok(None) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro_exported': did not get context");
- return result;
- },
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro_exported': {err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("system", StorageFileType::FlagVal) {
- Ok(val_map) => val_map,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro_exported': {err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, 5 + package_read_context.boolean_start_index) {
- Ok(val) => val,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_fixed_ro_exported': {err}");
- return result;
- }
- };
-
- if result != value {
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for 'enabled_fixed_ro_exported'. Legacy storage was {result}, new storage was {value}");
- } else {
- let default_value = true;
- }
- }
-
- result
-
+ true
}
/// query flag enabled_ro
#[inline(always)]
pub fn enabled_ro() -> bool {
-
-
- let result = true;
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe {
- let package_map = match get_mapped_storage_file("system", StorageFileType::PackageMap) {
- Ok(file) => file,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro': {err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "com.android.aconfig.test") {
- Ok(Some(context)) => context,
- Ok(None) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro': did not get context");
- return result;
- },
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro': {err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("system", StorageFileType::FlagVal) {
- Ok(val_map) => val_map,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro': {err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, 6 + package_read_context.boolean_start_index) {
- Ok(val) => val,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro': {err}");
- return result;
- }
- };
-
- if result != value {
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for 'enabled_ro'. Legacy storage was {result}, new storage was {value}");
- } else {
- let default_value = true;
- }
- }
-
- result
-
+ true
}
/// query flag enabled_ro_exported
#[inline(always)]
pub fn enabled_ro_exported() -> bool {
-
-
- let result = true;
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe {
- let package_map = match get_mapped_storage_file("system", StorageFileType::PackageMap) {
- Ok(file) => file,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro_exported': {err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "com.android.aconfig.test") {
- Ok(Some(context)) => context,
- Ok(None) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro_exported': did not get context");
- return result;
- },
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro_exported': {err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("system", StorageFileType::FlagVal) {
- Ok(val_map) => val_map,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro_exported': {err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, 7 + package_read_context.boolean_start_index) {
- Ok(val) => val,
- Err(err) => {
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag 'enabled_ro_exported': {err}");
- return result;
- }
- };
-
- if result != value {
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for 'enabled_ro_exported'. Legacy storage was {result}, new storage was {value}");
- } else {
- let default_value = true;
- }
- }
-
- result
-
+ true
}
/// query flag enabled_rw
@@ -1203,10 +825,6 @@
use std::sync::LazyLock;
use log::{log, LevelFilter, Level};
-static STORAGE_MIGRATION_MARKER_FILE: &str =
- "/metadata/aconfig_test_missions/mission_1";
-static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
-
/// flag provider
pub struct FlagProvider;
@@ -1275,10 +893,6 @@
use std::sync::LazyLock;
use log::{log, LevelFilter, Level};
-static STORAGE_MIGRATION_MARKER_FILE: &str =
- "/metadata/aconfig_test_missions/mission_1";
-static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
-
/// flag provider
pub struct FlagProvider;
diff --git a/tools/aconfig/aconfig/templates/rust.template b/tools/aconfig/aconfig/templates/rust.template
index ea1c600..c2f162f 100644
--- a/tools/aconfig/aconfig/templates/rust.template
+++ b/tools/aconfig/aconfig/templates/rust.template
@@ -5,15 +5,15 @@
use std::sync::LazyLock;
use log::\{log, LevelFilter, Level};
-static STORAGE_MIGRATION_MARKER_FILE: &str =
- "/metadata/aconfig_test_missions/mission_1";
-static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
-
/// flag provider
pub struct FlagProvider;
{{ if has_readwrite- }}
{{ if allow_instrumentation }}
+static READ_FROM_NEW_STORAGE: LazyLock<bool> = LazyLock::new(|| unsafe \{
+ Path::new("/metadata/aconfig/boot/enable_only_new_storage").exists()
+});
+
static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe \{
get_mapped_storage_file("{container}", StorageFileType::PackageMap)
.and_then(|package_map| get_package_read_context(&package_map, "{package}"))
@@ -30,24 +30,15 @@
/// flag value cache for {flag.name}
{{ if allow_instrumentation }}
static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{
- let result = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.{flag.device_config_namespace}",
- "{flag.device_config_flag}",
- "{flag.default_value}") == "true";
- let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
- "aconfig_flags.core_experiments_team_internal",
- "com.android.providers.settings.use_new_storage_value",
- "false") == "true";
-
- if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() \{
+ if *READ_FROM_NEW_STORAGE \{
// This will be called multiple times. Subsequent calls after the first are noops.
logger::init(
logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
+ .with_tag_on_device("aconfig_rust_codegen")
.with_max_level(LevelFilter::Info));
- let aconfig_storage_result = FLAG_VAL_MAP
+ let flag_value_result = FLAG_VAL_MAP
.as_ref()
.map_err(|err| format!("failed to get flag val map: \{err}"))
.and_then(|flag_val_map| \{
@@ -65,33 +56,23 @@
})
});
- match aconfig_storage_result \{
- Ok(storage_result) if storage_result == result => \{
- if use_new_storage_value \{
- return storage_result;
- } else \{
- return result;
- }
- },
- Ok(storage_result) => \{
- log!(Level::Error, "AconfigTestMission1: error: mismatch for flag '{flag.name}'. Legacy storage was \{result}, new storage was \{storage_result}");
- if use_new_storage_value \{
- return storage_result;
- } else \{
- return result;
- }
+ match flag_value_result \{
+ Ok(flag_value) => \{
+ return flag_value;
},
Err(err) => \{
- log!(Level::Error, "AconfigTestMission1: error: \{err}");
- if use_new_storage_value \{
- panic!("failed to read flag value: \{err}");
- }
+ log!(Level::Error, "aconfig_rust_codegen: error: \{err}");
+ panic!("failed to read flag value: \{err}");
}
}
+ } else \{
+ flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.{flag.device_config_namespace}",
+ "{flag.device_config_flag}",
+ "{flag.default_value}") == "true"
}
- result
- });
+});
{{ else }}
static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
"aconfig_flags.{flag.device_config_namespace}",
@@ -123,72 +104,11 @@
{{ for flag in template_flags }}
/// query flag {flag.name}
#[inline(always)]
-{{ -if flag.readwrite }}
pub fn {flag.name}() -> bool \{
+{{ -if flag.readwrite }}
PROVIDER.{flag.name}()
{{ -else }}
-pub fn {flag.name}() -> bool \{
- {{ if not allow_instrumentation }}
{flag.default_value}
- {{ else }}
-
- let result = {flag.default_value};
- if !Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() \{
- return result;
- }
-
- // This will be called multiple times. Subsequent calls after the first
- // are noops.
- logger::init(
- logger::Config::default()
- .with_tag_on_device(MIGRATION_LOG_TAG)
- .with_max_level(LevelFilter::Info),
- );
-
- unsafe \{
- let package_map = match get_mapped_storage_file("{flag.container}", StorageFileType::PackageMap) \{
- Ok(file) => file,
- Err(err) => \{
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag '{flag.name}': \{err}");
- return result;
- }
- };
-
- let package_read_context = match get_package_read_context(&package_map, "{package}") \{
- Ok(Some(context)) => context,
- Ok(None) => \{
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag '{flag.name}': did not get context");
- return result;
- },
- Err(err) => \{
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag '{flag.name}': \{err}");
- return result;
- }
- };
- let flag_val_map = match get_mapped_storage_file("{flag.container}", StorageFileType::FlagVal) \{
- Ok(val_map) => val_map,
- Err(err) => \{
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag '{flag.name}': \{err}");
- return result;
- }
- };
- let value = match get_boolean_flag_value(&flag_val_map, {flag.flag_offset} + package_read_context.boolean_start_index) \{
- Ok(val) => val,
- Err(err) => \{
- log!(Level::Error, "AconfigTestMission1: error: failed to read flag '{flag.name}': \{err}");
- return result;
- }
- };
-
- if result != value \{
- log!(Level::Error, "AconfigTestMission1: error: flag mismatch for '{flag.name}'. Legacy storage was \{result}, new storage was \{value}");
- } else \{
- let default_value = {flag.default_value};
- }
- }
-
- result
- {{ endif }}
{{ -endif }}
}
{{ endfor }}
diff --git a/tools/aconfig/aconfig_storage_file/Android.bp b/tools/aconfig/aconfig_storage_file/Android.bp
index 40b4464..e875c7b 100644
--- a/tools/aconfig/aconfig_storage_file/Android.bp
+++ b/tools/aconfig/aconfig_storage_file/Android.bp
@@ -14,6 +14,7 @@
"libclap",
"libcxx",
"libaconfig_storage_protos",
+ "libserde",
],
}
@@ -36,7 +37,10 @@
name: "aconfig-storage",
defaults: ["aconfig_storage_file.defaults"],
srcs: ["src/main.rs"],
- rustlibs: ["libaconfig_storage_file"],
+ rustlibs: [
+ "libaconfig_storage_file",
+ "libserde_json",
+ ],
}
rust_test_host {
diff --git a/tools/aconfig/aconfig_storage_file/Cargo.toml b/tools/aconfig/aconfig_storage_file/Cargo.toml
index 192dfad..a405578 100644
--- a/tools/aconfig/aconfig_storage_file/Cargo.toml
+++ b/tools/aconfig/aconfig_storage_file/Cargo.toml
@@ -14,6 +14,8 @@
thiserror = "1.0.56"
clap = { version = "4.1.8", features = ["derive"] }
cxx = "1.0"
+serde = { version = "1.0.152", features = ["derive"] }
+serde_json = "1.0.93"
[[bin]]
name = "aconfig-storage"
diff --git a/tools/aconfig/aconfig_storage_file/src/flag_info.rs b/tools/aconfig/aconfig_storage_file/src/flag_info.rs
index beac38d..f090396 100644
--- a/tools/aconfig/aconfig_storage_file/src/flag_info.rs
+++ b/tools/aconfig/aconfig_storage_file/src/flag_info.rs
@@ -20,10 +20,11 @@
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{AconfigStorageError, StorageFileType};
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
use std::fmt;
/// Flag info header struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagInfoHeader {
pub version: u32,
pub container: String,
@@ -89,7 +90,7 @@
}
/// bit field for flag info
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum FlagInfoBit {
HasServerOverride = 1 << 0,
IsReadWrite = 1 << 1,
@@ -97,7 +98,7 @@
}
/// Flag info node struct
-#[derive(PartialEq, Clone)]
+#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct FlagInfoNode {
pub attributes: u8,
}
@@ -138,7 +139,7 @@
}
/// Flag info list struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagInfoList {
pub header: FlagInfoHeader,
pub nodes: Vec<FlagInfoNode>,
diff --git a/tools/aconfig/aconfig_storage_file/src/flag_table.rs b/tools/aconfig/aconfig_storage_file/src/flag_table.rs
index 660edac..0588fe5 100644
--- a/tools/aconfig/aconfig_storage_file/src/flag_table.rs
+++ b/tools/aconfig/aconfig_storage_file/src/flag_table.rs
@@ -23,10 +23,11 @@
};
use crate::{AconfigStorageError, StorageFileType, StoredFlagType};
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
use std::fmt;
/// Flag table header struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagTableHeader {
pub version: u32,
pub container: String,
@@ -95,7 +96,7 @@
}
/// Flag table node struct
-#[derive(PartialEq, Clone)]
+#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct FlagTableNode {
pub package_id: u32,
pub flag_name: String,
@@ -154,7 +155,7 @@
}
}
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagTable {
pub header: FlagTableHeader,
pub buckets: Vec<Option<u32>>,
diff --git a/tools/aconfig/aconfig_storage_file/src/flag_value.rs b/tools/aconfig/aconfig_storage_file/src/flag_value.rs
index 506924b..b64c10e 100644
--- a/tools/aconfig/aconfig_storage_file/src/flag_value.rs
+++ b/tools/aconfig/aconfig_storage_file/src/flag_value.rs
@@ -20,10 +20,11 @@
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{AconfigStorageError, StorageFileType};
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
use std::fmt;
/// Flag value header struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagValueHeader {
pub version: u32,
pub container: String,
@@ -89,7 +90,7 @@
}
/// Flag value list struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagValueList {
pub header: FlagValueHeader,
pub booleans: Vec<bool>,
diff --git a/tools/aconfig/aconfig_storage_file/src/lib.rs b/tools/aconfig/aconfig_storage_file/src/lib.rs
index b6367ff..cf52bc0 100644
--- a/tools/aconfig/aconfig_storage_file/src/lib.rs
+++ b/tools/aconfig/aconfig_storage_file/src/lib.rs
@@ -41,6 +41,7 @@
pub mod test_utils;
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fs::File;
use std::hash::Hasher;
@@ -107,7 +108,7 @@
/// Flag type enum as stored by storage file
/// ONLY APPEND, NEVER REMOVE FOR BACKWARD COMPATIBILITY. THE MAX IS U16.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum StoredFlagType {
ReadWriteBoolean = 0,
ReadOnlyBoolean = 1,
diff --git a/tools/aconfig/aconfig_storage_file/src/main.rs b/tools/aconfig/aconfig_storage_file/src/main.rs
index 8b9e38d..a9cfd19 100644
--- a/tools/aconfig/aconfig_storage_file/src/main.rs
+++ b/tools/aconfig/aconfig_storage_file/src/main.rs
@@ -20,9 +20,29 @@
list_flags, list_flags_with_info, read_file_to_bytes, AconfigStorageError, FlagInfoList,
FlagTable, FlagValueList, PackageTable, StorageFileType,
};
-
use clap::{builder::ArgAction, Arg, Command};
+use serde::Serialize;
+use serde_json;
+use std::fmt;
+use std::fs;
+use std::fs::File;
+use std::io::Write;
+/**
+ * Usage Examples
+ *
+ * Print file:
+ * $ aconfig-storage print --file=path/to/flag.map --type=flag_map
+ *
+ * List flags:
+ * $ aconfig-storage list --flag-map=path/to/flag.map \
+ * --flag-val=path/to/flag.val --package-map=path/to/package.map
+ *
+ * Write binary file for testing:
+ * $ aconfig-storage print --file=path/to/flag.map --type=flag_map --format=json > flag_map.json
+ * $ vim flag_map.json // Manually make updates
+ * $ aconfig-storage write-bytes --input-file=flag_map.json --output-file=path/to/flag.map --type=flag_map
+ */
fn cli() -> Command {
Command::new("aconfig-storage")
.subcommand_required(true)
@@ -34,7 +54,8 @@
.long("type")
.required(true)
.value_parser(|s: &str| StorageFileType::try_from(s)),
- ),
+ )
+ .arg(Arg::new("format").long("format").required(false).action(ArgAction::Set)),
)
.subcommand(
Command::new("list")
@@ -50,41 +71,75 @@
Arg::new("flag-info").long("flag-info").required(false).action(ArgAction::Set),
),
)
+ .subcommand(
+ Command::new("write-bytes")
+ // Where to write the output bytes. Suggest to use the StorageFileType names (e.g. flag.map).
+ .arg(
+ Arg::new("output-file")
+ .long("output-file")
+ .required(true)
+ .action(ArgAction::Set),
+ )
+ // Input file should be json.
+ .arg(
+ Arg::new("input-file").long("input-file").required(true).action(ArgAction::Set),
+ )
+ .arg(
+ Arg::new("type")
+ .long("type")
+ .required(true)
+ .value_parser(|s: &str| StorageFileType::try_from(s)),
+ ),
+ )
}
fn print_storage_file(
file_path: &str,
file_type: &StorageFileType,
+ as_json: bool,
) -> Result<(), AconfigStorageError> {
let bytes = read_file_to_bytes(file_path)?;
match file_type {
StorageFileType::PackageMap => {
let package_table = PackageTable::from_bytes(&bytes)?;
- println!("{:?}", package_table);
+ println!("{}", to_print_format(package_table, as_json));
}
StorageFileType::FlagMap => {
let flag_table = FlagTable::from_bytes(&bytes)?;
- println!("{:?}", flag_table);
+ println!("{}", to_print_format(flag_table, as_json));
}
StorageFileType::FlagVal => {
let flag_value = FlagValueList::from_bytes(&bytes)?;
- println!("{:?}", flag_value);
+ println!("{}", to_print_format(flag_value, as_json));
}
StorageFileType::FlagInfo => {
let flag_info = FlagInfoList::from_bytes(&bytes)?;
- println!("{:?}", flag_info);
+ println!("{}", to_print_format(flag_info, as_json));
}
}
Ok(())
}
+fn to_print_format<T>(file_contents: T, as_json: bool) -> String
+where
+ T: Serialize + fmt::Debug,
+{
+ if as_json {
+ serde_json::to_string(&file_contents).unwrap()
+ } else {
+ format!("{:?}", file_contents)
+ }
+}
+
fn main() -> Result<(), AconfigStorageError> {
let matches = cli().get_matches();
match matches.subcommand() {
Some(("print", sub_matches)) => {
let file_path = sub_matches.get_one::<String>("file").unwrap();
let file_type = sub_matches.get_one::<StorageFileType>("type").unwrap();
- print_storage_file(file_path, file_type)?
+ let format = sub_matches.get_one::<String>("format");
+ let as_json: bool = format == Some(&"json".to_string());
+ print_storage_file(file_path, file_type, as_json)?
}
Some(("list", sub_matches)) => {
let package_map = sub_matches.get_one::<String>("package-map").unwrap();
@@ -96,10 +151,10 @@
let flags = list_flags_with_info(package_map, flag_map, flag_val, info_file)?;
for flag in flags.iter() {
println!(
- "{} {} {} {:?} IsReadWrite: {}, HasServerOverride: {}, HasLocalOverride: {}",
- flag.package_name, flag.flag_name, flag.flag_value, flag.value_type,
- flag.is_readwrite, flag.has_server_override, flag.has_local_override,
- );
+ "{} {} {} {:?} IsReadWrite: {}, HasServerOverride: {}, HasLocalOverride: {}",
+ flag.package_name, flag.flag_name, flag.flag_value, flag.value_type,
+ flag.is_readwrite, flag.has_server_override, flag.has_local_override,
+ );
}
}
None => {
@@ -113,6 +168,40 @@
}
}
}
+ // Converts JSON of the file into raw bytes (as is used on-device).
+ // Intended to generate/easily update these files for testing.
+ Some(("write-bytes", sub_matches)) => {
+ let input_file_path = sub_matches.get_one::<String>("input-file").unwrap();
+ let input_json = fs::read_to_string(input_file_path).unwrap();
+
+ let file_type = sub_matches.get_one::<StorageFileType>("type").unwrap();
+ let output_bytes: Vec<u8>;
+ match file_type {
+ StorageFileType::FlagVal => {
+ let list: FlagValueList = serde_json::from_str(&input_json).unwrap();
+ output_bytes = list.into_bytes();
+ }
+ StorageFileType::FlagInfo => {
+ let list: FlagInfoList = serde_json::from_str(&input_json).unwrap();
+ output_bytes = list.into_bytes();
+ }
+ StorageFileType::FlagMap => {
+ let table: FlagTable = serde_json::from_str(&input_json).unwrap();
+ output_bytes = table.into_bytes();
+ }
+ StorageFileType::PackageMap => {
+ let table: PackageTable = serde_json::from_str(&input_json).unwrap();
+ output_bytes = table.into_bytes();
+ }
+ }
+
+ let output_file_path = sub_matches.get_one::<String>("output-file").unwrap();
+ let file = File::create(output_file_path);
+ if file.is_err() {
+ panic!("can't make file");
+ }
+ let _ = file.unwrap().write_all(&output_bytes);
+ }
_ => unreachable!(),
}
Ok(())
diff --git a/tools/aconfig/aconfig_storage_file/src/package_table.rs b/tools/aconfig/aconfig_storage_file/src/package_table.rs
index 007f86e..a5bd9e6 100644
--- a/tools/aconfig/aconfig_storage_file/src/package_table.rs
+++ b/tools/aconfig/aconfig_storage_file/src/package_table.rs
@@ -20,10 +20,11 @@
use crate::{get_bucket_index, read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{AconfigStorageError, StorageFileType};
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
use std::fmt;
/// Package table header struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct PackageTableHeader {
pub version: u32,
pub container: String,
@@ -92,7 +93,7 @@
}
/// Package table node struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct PackageTableNode {
pub package_name: String,
pub package_id: u32,
@@ -151,7 +152,7 @@
}
/// Package table struct
-#[derive(PartialEq)]
+#[derive(PartialEq, Serialize, Deserialize)]
pub struct PackageTable {
pub header: PackageTableHeader,
pub buckets: Vec<Option<u32>>,
diff --git a/tools/aconfig/aflags/src/main.rs b/tools/aconfig/aflags/src/main.rs
index a726cc0..07b7243 100644
--- a/tools/aconfig/aflags/src/main.rs
+++ b/tools/aconfig/aflags/src/main.rs
@@ -116,9 +116,10 @@
}
fn display_staged_value(&self) -> String {
- match self.staged_value {
- Some(v) => format!("(->{})", v),
- None => "-".to_string(),
+ match (&self.permission, self.staged_value) {
+ (FlagPermission::ReadOnly, _) => "-".to_string(),
+ (FlagPermission::ReadWrite, None) => "-".to_string(),
+ (FlagPermission::ReadWrite, Some(v)) => format!("(->{})", v),
}
}
}
diff --git a/tools/edit_monitor/Android.bp b/tools/edit_monitor/Android.bp
new file mode 100644
index 0000000..80437c0
--- /dev/null
+++ b/tools/edit_monitor/Android.bp
@@ -0,0 +1,21 @@
+// Copyright 2024 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Set of error prone rules to ensure code quality
+// PackageLocation check requires the androidCompatible=false otherwise it does not do anything.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+ default_team: "trendy_team_adte",
+}
diff --git a/tools/edit_monitor/OWNERS b/tools/edit_monitor/OWNERS
new file mode 100644
index 0000000..8f0f364
--- /dev/null
+++ b/tools/edit_monitor/OWNERS
@@ -0,0 +1 @@
+include platform/tools/asuite:/OWNERS_ADTE_TEAM
\ No newline at end of file
diff --git a/tools/releasetools/ota_from_raw_img.py b/tools/releasetools/ota_from_raw_img.py
index 03b44f1..3b9374a 100644
--- a/tools/releasetools/ota_from_raw_img.py
+++ b/tools/releasetools/ota_from_raw_img.py
@@ -105,9 +105,6 @@
if args.package_key:
logger.info("Signing payload...")
- # TODO: remove OPTIONS when no longer used as fallback in payload_signer
- common.OPTIONS.payload_signer_args = None
- common.OPTIONS.payload_signer_maximum_signature_size = None
signer = PayloadSigner(args.package_key, args.private_key_suffix,
key_passwords[args.package_key],
payload_signer=args.payload_signer,