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

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

Merge changes I10fef1a8,Ifb805a35,Iba7324a3,If9862343,Ib5c6ed10, ...

* changes:
  floss: Fix build-dpkg after git move
  floss: Add install target to build.py
  floss: Update symlinks when re-running --run-bootstrap
  floss: Implement Get/Set Bluetooth Class
  floss: Fix slice copy in topshim
  floss: Add checks to adapter command
parents 35306441 45a33d6a
Loading
Loading
Loading
Loading
+75 −15
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import shutil
import six
import subprocess
import sys
import tarfile
import time

# Use flags required by common-mk (find -type f | grep -nE 'use[.]' {})
@@ -185,6 +186,7 @@ class HostBuild():
        self.platform_dir = os.path.join(self.bootstrap_dir, 'staging')
        self.sysroot = self.args.sysroot
        self.libdir = self.args.libdir
        self.install_dir = os.path.join(self.output_dir, 'install')

        # If default target isn't set, build everything
        self.target = 'all'
@@ -415,10 +417,6 @@ class HostBuild():
        """ Build rust artifacts in an already prepared environment.
        """
        self._rust_build()
        rust_dir = os.path.join(self._gn_default_output(), 'rust')
        if os.path.exists(rust_dir):
            shutil.rmtree(rust_dir)
        shutil.copytree(os.path.join(self.output_dir, 'debug'), rust_dir)

    def _target_main(self):
        """ Build the main GN artifacts in an already prepared environment.
@@ -438,12 +436,70 @@ class HostBuild():
                cwd=os.path.join(self.output_dir),
                env=self.env)

    def _target_install(self):
        """ Installs files required to run Floss to install directory.
        """
        # First make the install directory
        prefix = self.install_dir
        os.makedirs(prefix, exist_ok=True)

        # Next save the cwd and change to install directory
        last_cwd = os.getcwd()
        os.chdir(prefix)

        bindir = os.path.join(self.output_dir, 'debug')
        srcdir = os.path.dirname(__file__)

        install_map = [
            {
                'src': os.path.join(bindir, 'btadapterd'),
                'dst': 'usr/libexec/bluetooth/btadapterd',
                'strip': True
            },
            {
                'src': os.path.join(bindir, 'btmanagerd'),
                'dst': 'usr/libexec/bluetooth/btmanagerd',
                'strip': True
            },
            {
                'src': os.path.join(bindir, 'btclient'),
                'dst': 'usr/local/bin/btclient',
                'strip': True
            },
        ]

        for v in install_map:
            src, partial_dst, strip = (v['src'], v['dst'], v['strip'])
            dst = os.path.join(prefix, partial_dst)

            # Create dst directory first and copy file there
            os.makedirs(os.path.dirname(dst), exist_ok=True)
            print('Installing {}'.format(dst))
            shutil.copy(src, dst)

            # Binary should be marked for strip and no-strip option shouldn't be
            # set. No-strip is useful while debugging.
            if strip and not self.args.no_strip:
                self.run_command('install', ['llvm-strip', dst])

        # Put all files into a tar.gz for easier installation
        tar_location = os.path.join(prefix, 'floss.tar.gz')
        with tarfile.open(tar_location, 'w:gz') as tar:
            for v in install_map:
                tar.add(v['dst'])

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

    def _target_clean(self):
        """ Delete the output directory entirely.
        """
        shutil.rmtree(self.output_dir)

        # Remove Cargo.lock that may have become generated
        try:
            os.remove(os.path.join(self.platform_dir, 'bt', 'Cargo.lock'))
        except FileNotFoundError:
            pass

    def _target_all(self):
        """ Build all common targets (skipping test and clean).
@@ -470,6 +526,8 @@ class HostBuild():
            self._target_test()
        elif self.target == 'clean':
            self._target_clean()
        elif self.target == 'install':
            self._target_install()
        elif self.target == 'all':
            self._target_all()

@@ -511,16 +569,15 @@ class Bootstrap():
        This will check out all the git repos and symlink everything correctly.
        """

        # If already set up, exit early
        if os.path.isfile(self.dir_setup_complete):
            print('{} already set-up. Updating instead.'.format(self.base_dir))
            self._update_platform2()
            return

        # Create all directories we will need to use
        for dirpath in [self.git_dir, self.staging_dir, self.output_dir, self.external_dir]:
            os.makedirs(dirpath)
            os.makedirs(dirpath, exist_ok=True)

        # If already set up, only update platform2
        if os.path.isfile(self.dir_setup_complete):
            print('{} already set-up. Updating instead.'.format(self.base_dir))
            self._update_platform2()
        else:
            # Check out all repos in git directory
            for repo in BOOTSTRAP_GIT_REPOS.values():
                subprocess.check_call(['git', 'clone', repo], cwd=self.git_dir)
@@ -537,6 +594,7 @@ class Bootstrap():
        # Create symlinks
        for pairs in symlinks:
            (src, dst) = pairs
            os.unlink(dst)
            os.symlink(src, dst)

        # Write to setup complete file so we don't repeat this step
@@ -698,6 +756,8 @@ if __name__ == '__main__':
        default=False,
        action='store_true')
    parser.add_argument('--no-clang', help='Use clang compiler.', default=False, action='store_true')
    parser.add_argument(
        '--no-strip', help='Skip stripping binaries during install.', default=False, action='store_true')
    parser.add_argument('--use', help='Set a specific use flag.')
    parser.add_argument('--notest', help="Don't compile test code.", default=False, action='store_true')
    parser.add_argument('--target', help='Run specific build target')
+7 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ URL_PROTO_LOGGING_GIT="https://android.googlesource.com/platform/frameworks/prot
CHROMIUM_BRANCH="release-R92-13982.B"

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PARENT_DIR="$(echo ${SCRIPT_DIR} | rev | cut -d '/' -f 2- | rev )"
PARENT_DIR="$(readlink -f ${SCRIPT_DIR}/../)"
TMP_DIR=$(mktemp -d)

trap ctrl_c INT
@@ -121,7 +121,7 @@ GIT_DIR_PLATFORM2_COMMON_MK="${GIT_DIR_PLATFORM2}/common-mk"
GIT_DIR_PLATFORM2_GN="${GIT_DIR_PLATFORM2}/.gn"
GIT_DIR_RUST_CRATES="${GIT_DIR}/rust_crates"
GIT_DIR_PROTO_LOGGING="${GIT_DIR}/proto_logging"
GIT_DIR_BT="$(echo "${PARENT_DIR}" | rev | cut -d '/' -f 3- | rev)"
GIT_DIR_BT="$(readlink -f $PARENT_DIR/../../../)"

# Staging
STAGING_DIR="${OUT_DIR}/staging"
@@ -170,10 +170,15 @@ BTADAPTERD_BIN="${BIN_OUTPUT}/btadapterd"

${DRY_RUN} cp -r "${PKG_DIR}" "${OUT_DIR}/"

${DRY_RUN} mkdir -p "${OUT_PKG_USR_DIR}/bin"
${DRY_RUN} cp "${BTCLIENT_BIN}" "${OUT_PKG_USR_DIR}/bin/"

${DRY_RUN} mkdir -p "${OUT_PKG_USR_DIR}/libexec/bluetooth"
${DRY_RUN} cp "${BTMANAGERD_BIN}" "${OUT_PKG_USR_DIR}/libexec/bluetooth/"
${DRY_RUN} cp "${BTADAPTERD_BIN}" "${OUT_PKG_USR_DIR}/libexec/bluetooth/"

# Directory with control file needs the right permissions
${DRY_RUN} chmod -R 0755 "${TMP_DIR}"
${DRY_RUN} dpkg-deb --build "${OUT_PKG_DIR}" "${FIRST_DIR}/floss.deb"

${DRY_RUN} rm -rf ${TMP_DIR}
+16 −2
Original line number Diff line number Diff line
@@ -238,6 +238,11 @@ impl CommandHandler {
    }

    fn cmd_adapter(&mut self, args: &Vec<String>) {
        if !self.context.lock().unwrap().manager_dbus.get_floss_enabled() {
            println!("Floss is not enabled. First run, `floss enable`");
            return;
        }

        let default_adapter = self.context.lock().unwrap().default_adapter;
        enforce_arg_len(args, 1, "adapter <enable|disable|show>", || match &args[0][0..] {
            "enable" => {
@@ -247,8 +252,8 @@ impl CommandHandler {
                self.context.lock().unwrap().manager_dbus.stop(default_adapter);
            }
            "show" => {
                if !self.context.lock().unwrap().manager_dbus.get_floss_enabled() {
                    println!("Floss is not enabled. First run, `floss enable`");
                if !self.context.lock().unwrap().adapter_ready {
                    self.adapter_not_ready();
                    return;
                }

@@ -259,9 +264,18 @@ impl CommandHandler {
                };
                let name = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_name();
                let uuids = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_uuids();
                let cod = self
                    .context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_ref()
                    .unwrap()
                    .get_bluetooth_class();
                print_info!("Address: {}", address);
                print_info!("Name: {}", name);
                print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
                print_info!("Class: {:#06x}", cod);
                print_info!(
                    "Uuids: {}",
                    DisplayList(
+8 −0
Original line number Diff line number Diff line
@@ -301,6 +301,14 @@ impl IBluetooth for BluetoothDBus {
        self.client_proxy.method("SetName", (name,))
    }

    fn get_bluetooth_class(&self) -> u32 {
        self.client_proxy.method("GetBluetoothClass", ())
    }

    fn set_bluetooth_class(&self, cod: u32) -> bool {
        self.client_proxy.method("SetBluetoothClass", (cod,))
    }

    fn start_discovery(&self) -> bool {
        self.client_proxy.method("StartDiscovery", ())
    }
+10 −0
Original line number Diff line number Diff line
@@ -120,6 +120,16 @@ impl IBluetooth for IBluetoothDBus {
        true
    }

    #[dbus_method("GetBluetoothClass")]
    fn get_bluetooth_class(&self) -> u32 {
        0
    }

    #[dbus_method("SetBluetoothClass")]
    fn set_bluetooth_class(&self, cod: u32) -> bool {
        true
    }

    #[dbus_method("StartDiscovery")]
    fn start_discovery(&self) -> bool {
        true
Loading