Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c971299 authored by Mårten Kongstad's avatar Mårten Kongstad Committed by Gerrit Code Review
Browse files

Merge changes from topic "record-finalized-flags-part-2" into main

* changes:
  record-finalized-flags: add actual implementation
  record-finalized-flags: convert to Rust
parents 0457b6c4 0f4e0326
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
Cargo.lock
target/
+26 −2
Original line number Diff line number Diff line
sh_binary_host {
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

rust_defaults {
    name: "record-finalized-flags-defaults",
    edition: "2021",
    clippy_lints: "android",
    lints: "android",
    srcs: ["src/main.rs"],
    rustlibs: [
        "libaconfig_protos",
        "libanyhow",
        "libclap",
        "libregex",
    ],
}

rust_binary_host {
    name: "record-finalized-flags",
    src: "record-finalized-flags.sh",
    defaults: ["record-finalized-flags-defaults"],
}

rust_test_host {
    name: "record-finalized-flags-test",
    defaults: ["record-finalized-flags-defaults"],
    test_suites: ["general-tests"],
}
+15 −0
Original line number Diff line number Diff line
# Cargo.toml file to allow rapid development of record-finalized-flags using
# cargo. Soong is the official Android build system, and the only system
# guaranteed to support record-finalized-flags. If there is ever any issue with
# the cargo setup, support for cargo will be dropped and this file removed.

[package]
name = "record-finalized-flags"
version = "0.1.0"
edition = "2021"

[dependencies]
aconfig_protos = { path = "../aconfig/aconfig_protos" }
anyhow = { path = "../../../../external/rust/android-crates-io/crates/anyhow" }
clap = { path = "../../../../external/rust/android-crates-io/crates/clap", features = ["derive"] }
regex = { path = "../../../../external/rust/android-crates-io/crates/regex" }
+0 −18
Original line number Diff line number Diff line
#!/bin/bash -e
#
# Copyright 2024 Google Inc. All rights reserved.
#
# 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.

# TODO: implement this tool
echo "record-finalized-flags.sh $*"
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.
 */

use anyhow::Result;
use regex::Regex;
use std::{collections::HashSet, io::Read};

use crate::FlagId;

/// Grep for all flags used with @FlaggedApi annotations in an API signature file (*current.txt
/// file).
pub(crate) fn extract_flagged_api_flags<R: Read>(mut reader: R) -> Result<HashSet<FlagId>> {
    let mut haystack = String::new();
    reader.read_to_string(&mut haystack)?;
    let regex = Regex::new(r#"(?ms)@FlaggedApi\("(.*?)"\)"#).unwrap();
    let iter = regex.captures_iter(&haystack).map(|cap| cap[1].to_owned());
    Ok(HashSet::from_iter(iter))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        let api_signature_file = include_bytes!("../tests/api-signature-file.txt");
        let flags = extract_flagged_api_flags(&api_signature_file[..]).unwrap();
        assert_eq!(
            flags,
            HashSet::from_iter(vec![
                "record_finalized_flags.test.foo".to_string(),
                "this.flag.is.not.used".to_string(),
            ])
        );
    }
}
Loading