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

Commit c8bd0263 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I2c1bc4b8,I637e7e3f,I6ce9e6e7 into main

* changes:
  floss: Remove unnecessary regex crate usage
  floss: Add support for running cargo-bloat
  floss: Fix env encoding issue with build.py
parents b710b8e8 482a8984
Loading
Loading
Loading
Loading
+21 −1
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ USE_DEFAULTS = {


VALID_TARGETS = [
VALID_TARGETS = [
    'all',  # All targets except test and clean
    'all',  # All targets except test and clean
    'bloat',  # Check bloat of crates
    'clean',  # Clean up output directory
    'clean',  # Clean up output directory
    'docs',  # Build Rust docs
    'docs',  # Build Rust docs
    'hosttools',  # Build the host tools (i.e. packetgen)
    'hosttools',  # Build the host tools (i.e. packetgen)
@@ -148,7 +149,7 @@ REQUIRED_APT_PACKAGES = [
]
]


# List of cargo packages required for linux build
# List of cargo packages required for linux build
REQUIRED_CARGO_PACKAGES = ['cxxbridge-cmd', 'pdl-compiler']
REQUIRED_CARGO_PACKAGES = ['cxxbridge-cmd', 'pdl-compiler', 'grpcio-compiler', 'cargo-bloat']


APT_PKG_LIST = ['apt', '-qq', 'list']
APT_PKG_LIST = ['apt', '-qq', 'list']
CARGO_PKG_LIST = ['cargo', 'install', '--list']
CARGO_PKG_LIST = ['cargo', 'install', '--list']
@@ -249,6 +250,8 @@ class HostBuild():
            'link-arg=-Wl,--allow-multiple-definition',
            'link-arg=-Wl,--allow-multiple-definition',
            # exclude uninteresting warnings
            # exclude uninteresting warnings
            '-A improper_ctypes_definitions -A improper_ctypes -A unknown_lints',
            '-A improper_ctypes_definitions -A improper_ctypes -A unknown_lints',
            '-Cstrip=debuginfo',
            '-Copt-level=z',
        ]
        ]


        return ' '.join(rust_flags)
        return ' '.join(rust_flags)
@@ -295,6 +298,10 @@ class HostBuild():
        if not env:
        if not env:
            env = self.env
            env = self.env


        for k, v in env.items():
            if env[k] is None:
                env[k] = ""

        log_file = os.path.join(self.output_dir, '{}.log'.format(target))
        log_file = os.path.join(self.output_dir, '{}.log'.format(target))
        with open(log_file, 'wb') as lf:
        with open(log_file, 'wb') as lf:
            rc = 0
            rc = 0
@@ -566,6 +573,17 @@ class HostBuild():


        print('Tarball created at {}'.format(tar_location))
        print('Tarball created at {}'.format(tar_location))


    def _target_bloat(self):
        """Run cargo bloat on workspace.
        """
        crate_paths = [
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'mgmt'),
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'service'),
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'client')
        ]
        for crate in crate_paths:
            self.run_command('bloat', ['cargo', 'bloat', '--release', '--crates', '--wide'], cwd=crate, env=self.env)

    def _target_clean(self):
    def _target_clean(self):
        """ Delete the output directory entirely.
        """ Delete the output directory entirely.
        """
        """
@@ -620,6 +638,8 @@ class HostBuild():
            self._target_install()
            self._target_install()
        elif self.target == 'utils':
        elif self.target == 'utils':
            self._target_utils()
            self._target_utils()
        elif self.target == 'bloat':
            self._target_bloat()
        elif self.target == 'all':
        elif self.target == 'all':
            self._target_all()
            self._target_all()


+5 −1
Original line number Original line Diff line number Diff line
@@ -67,7 +67,11 @@ RUN /tmp/rustup.sh -y --default-toolchain 1.77.1
ENV PATH="/root/.cargo/bin:${PATH}"
ENV PATH="/root/.cargo/bin:${PATH}"


# Install cargo packages required on build image.
# Install cargo packages required on build image.
RUN cargo install --locked cxxbridge-cmd@1.0.94 pdl-compiler@0.1.1 grpcio-compiler@0.13.0
RUN cargo install --locked \
    cxxbridge-cmd@1.0.94 \
    pdl-compiler@0.1.1 \
    grpcio-compiler@0.13.0 \
    cargo-bloat@0.12.1
RUN cargo install --git https://android.googlesource.com/platform/build#8f9ca807 aconfig
RUN cargo install --git https://android.googlesource.com/platform/build#8f9ca807 aconfig


# Rename llvm packages. By default, they are named 11vm-ar-13, etc. which won't
# Rename llvm packages. By default, they are named 11vm-ar-13, etc. which won't
+0 −1
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ log = "0.4.14"
nix = "0.23"
nix = "0.23"
num-traits = "0.2"
num-traits = "0.2"
protobuf = "2.0"
protobuf = "2.0"
regex = "1.5"
serde_json = "1.0"
serde_json = "1.0"
syslog = "6"
syslog = "6"
tokio = { version = "1.0", features = ["fs", "macros", "rt-multi-thread", "sync"] }
tokio = { version = "1.0", features = ["fs", "macros", "rt-multi-thread", "sync"] }
+6 −3
Original line number Original line Diff line number Diff line
@@ -9,7 +9,6 @@ use libc;
use log::{debug, error, info, warn};
use log::{debug, error, info, warn};
use nix::sys::signal::{self, Signal};
use nix::sys::signal::{self, Signal};
use nix::unistd::Pid;
use nix::unistd::Pid;
use regex::Regex;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, HashMap};
use std::convert::TryFrom;
use std::convert::TryFrom;
use std::fmt::{Display, Formatter};
use std::fmt::{Display, Formatter};
@@ -286,8 +285,11 @@ fn pid_inotify_async_fd() -> AsyncFd<inotify::Inotify> {


/// Given an pid path, returns the adapter index for that pid path.
/// Given an pid path, returns the adapter index for that pid path.
fn get_hci_index_from_pid_path(path: &str) -> Option<VirtualHciIndex> {
fn get_hci_index_from_pid_path(path: &str) -> Option<VirtualHciIndex> {
    let re = Regex::new(r"bluetooth([0-9]+).pid").unwrap();
    path.rsplit_once('/')
    re.captures(path)?.get(1)?.as_str().parse().ok().map(VirtualHciIndex)
        .and_then(|tup| tup.1.strip_prefix("bluetooth"))
        .and_then(|s| s.strip_suffix(".pid"))
        .and_then(|p| p.parse::<i32>().ok())
        .map(VirtualHciIndex)
}
}


fn event_name_to_string(name: Option<&std::ffi::OsStr>) -> Option<String> {
fn event_name_to_string(name: Option<&std::ffi::OsStr>) -> Option<String> {
@@ -2191,5 +2193,6 @@ mod tests {
            Some(VirtualHciIndex(10))
            Some(VirtualHciIndex(10))
        );
        );
        assert_eq!(get_hci_index_from_pid_path("/var/run/bluetooth/garbage"), None);
        assert_eq!(get_hci_index_from_pid_path("/var/run/bluetooth/garbage"), None);
        assert_eq!(get_hci_index_from_pid_path("garbage"), None);
    }
    }
}
}