• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3DRY_RUN=""
4if [ $# -gt 0 ]; then
5    if [ "$1" == "--dry-run" ]; then
6        DRY_RUN="echo "
7    fi
8fi
9
10REQUIRED="git cargo"
11
12for name in $(echo ${REQUIRED});
13do
14    type -P "$name" &>/dev/null || { echo "Install '$name'" >&2; exit 1;}
15done
16
17FIRST_DIR="$(pwd)"
18
19# Vars
20URL_GN="http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/gn-3e43fac03281e2f5e5ae5f27c8e9a6bb45966ea9.bin"
21URL_PLATFORM2_GIT="https://chromium.googlesource.com/chromiumos/platform2"
22URL_RUST_CRATES_GIT="https://chromium.googlesource.com/chromiumos/third_party/rust_crates"
23URL_PROTO_LOGGING_GIT="https://android.googlesource.com/platform/frameworks/proto_logging"
24CHROMIUM_BRANCH="release-R92-13982.B"
25
26SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
27PARENT_DIR="$(readlink -f ${SCRIPT_DIR}/../)"
28TMP_DIR=$(mktemp -d)
29
30trap ctrl_c INT
31
32function ctrl_c() {
33    rm -rf "${TMP_DIR}"
34    exit 1
35}
36
37echo Generating source package in "${TMP_DIR}"
38OUT_DIR="${TMP_DIR}/out"
39BIN_DIR="${TMP_DIR}/bin"
40
41${DRY_RUN} mkdir -p "${OUT_DIR}"
42${DRY_RUN} mkdir -p "${BIN_DIR}"
43
44pushd "${BIN_DIR}"
45wget -O gn "${URL_GN}"
46popd
47export PATH="${PATH}:${BIN_DIR}"
48
49# Check dependencies
50# libchrome requires modp_b64
51APT_REQUIRED="modp-b64 libchrome flatbuffers-compiler flex g++-multilib gcc-multilib generate-ninja gnupg gperf libc++-dev libdbus-1-dev libevent-dev libevent-dev libflatbuffers-dev libflatbuffers1 libgl1-mesa-dev libglib2.0-dev liblz4-tool libncurses5 libnss3-dev libprotobuf-dev libre2-9 libssl-dev libtinyxml2-dev libx11-dev libxml2-utils ninja-build openssl protobuf-compiler unzip x11proto-core-dev xsltproc zip zlib1g-dev"
52
53# SPEED UP TEST, REMOVE ME
54APT_REQUIRED="modp-b64 libchrome flatbuffers-compiler"
55
56APT_MISSING=()
57for name in $(echo ${APT_REQUIRED});
58do
59    R="$(apt -qq list "${name}" 2>/dev/null | grep "installed")"
60    if [ "${R}" == "" ]; then
61        echo "Need to install '${name}'" >&2;
62        if [ "${name}" == "modp-b64" ]; then
63            echo "${name} source is available to build in this repository"
64            echo Run the following to build and install:
65            echo "  pushd ${PARENT_DIR}/${name}/"
66            echo "  ./gen-src-pkg.sh ${OUT_DIR}"
67            echo "  sudo dpkg -i ${OUT_DIR}"/${name}*.deb || ctrl_c
68            echo "  popd"
69            ${DRY_RUN} rm -rf ${TMP_DIR}
70            exit 1
71        elif [ "${name}" == "libchrome" ]; then
72            echo "${name} source is available to build in this repository"
73            echo Run the following to build and install:
74            echo   pushd "${PARENT_DIR}/${name}/"
75            echo   ./gen-src-pkg.sh "${OUT_DIR}"
76            echo   sudo dpkg -i "${OUT_DIR}"/${name}*.deb || ctrl_c
77            echo   popd
78            ${DRY_RUN} rm -rf ${TMP_DIR}
79            exit 1
80        else
81            APT_MISSING+=("${name}")
82        fi
83    fi
84done
85
86APT_MISSING_LEN="${#APT_MISSING[@]}"
87
88if [ $APT_MISSING_LEN -gt 0 ]; then
89    echo "Missing Packages:"
90    echo "    ${APT_MISSING[*]}"
91    echo
92    echo Run the following to build and install:
93    echo "  sudo apt install" "${APT_MISSING[*]}" || ctrl_c
94    ${DRY_RUN} rm -rf ${TMP_DIR}
95    exit 1
96fi
97
98# Check cargo for cxxbridge-cmd
99HAS_CXX="$(cargo install --list | grep cxxbridge-cmd)"
100if [ "$HAS_CXX" == "" ]; then
101    echo "Missing cxxbridge-cmd cargo package"
102    echo Run the following to build and install:
103    echo   cargo install cxxbridge-cmd || ctrl_c
104    ${DRY_RUN} rm -rf ${TMP_DIR}
105    exit 1
106fi
107
108HAS_CXX="$(cargo install --list | grep cargo-proc-macro)"
109if [ "$HAS_CXX" == "" ]; then
110    echo "Missing cargo-proc-macro cargo package"
111    echo Run the following to build and install:
112    echo   cargo install cargo-proc-macro || ctrl_c
113    ${DRY_RUN} rm -rf ${TMP_DIR}
114    exit 1
115fi
116
117# Git
118GIT_DIR="${OUT_DIR}/repos"
119GIT_DIR_PLATFORM2="${GIT_DIR}/platform2"
120GIT_DIR_PLATFORM2_COMMON_MK="${GIT_DIR_PLATFORM2}/common-mk"
121GIT_DIR_PLATFORM2_GN="${GIT_DIR_PLATFORM2}/.gn"
122GIT_DIR_RUST_CRATES="${GIT_DIR}/rust_crates"
123GIT_DIR_PROTO_LOGGING="${GIT_DIR}/proto_logging"
124GIT_DIR_BT="$(readlink -f $PARENT_DIR/../../../)"
125
126# Staging
127STAGING_DIR="${OUT_DIR}/staging"
128STAGING_DIR_PLATFORM2="${STAGING_DIR}/platform2"
129STAGING_DIR_COMMON_MK="${STAGING_DIR}/common-mk"
130STAGING_DIR_GN="${STAGING_DIR}/.gn"
131STAGING_DIR_BT="${STAGING_DIR}/bt"
132# No it isn't a typo, use 'rust'
133STAGING_DIR_RUST_CRATES="${STAGING_DIR}/rust"
134STAGING_DIR_PROTO_LOGGING="${STAGING_DIR}/proto_logging"
135
136OUTPUT_DIR="${OUT_DIR}/output"
137EXTERNAL_DIR="${STAGING_DIR}/external"
138EXTERNAL_DIR_RUST="${EXTERNAL_DIR}/rust"
139EXTERNAL_DIR_PROTO_LOGGING="${EXTERNAL_DIR}/proto_logging"
140
141${DRY_RUN} mkdir -p "${GIT_DIR}"
142${DRY_RUN} mkdir -p "${STAGING_DIR}"
143${DRY_RUN} mkdir -p "${OUTPUT_DIR}"
144${DRY_RUN} mkdir -p "${EXTERNAL_DIR}"
145
146${DRY_RUN} git clone -b "${CHROMIUM_BRANCH}" "${URL_PLATFORM2_GIT}" "${GIT_DIR_PLATFORM2}"
147
148${DRY_RUN} git clone "${URL_RUST_CRATES_GIT}" "${GIT_DIR_RUST_CRATES}"
149${DRY_RUN} git clone "${URL_PROTO_LOGGING_GIT}" "${GIT_DIR_PROTO_LOGGING}"
150
151${DRY_RUN} ln -s "${GIT_DIR_PLATFORM2_COMMON_MK}" "${STAGING_DIR_COMMON_MK}" || ctrl_c
152${DRY_RUN} ln -s "${GIT_DIR_PLATFORM2_GN}" "${STAGING_DIR_GN}" || ctrl_c
153${DRY_RUN} ln -s "${GIT_DIR_BT}" "${STAGING_DIR_BT}" || ctrl_c
154${DRY_RUN} ln -s "${GIT_DIR_RUST_CRATES}" "${EXTERNAL_DIR_RUST}" || ctrl_c
155${DRY_RUN} ln -s "${GIT_DIR_PROTO_LOGGING}" "${EXTERNAL_DIR_PROTO_LOGGING}" || ctrl_c
156
157${DRY_RUN} "${GIT_DIR_BT}"/build.py --bootstrap-dir "$(readlink -f "${OUT_DIR}")" --libdir /usr/lib || ctrl_c
158
159PKG_DIR="${SCRIPT_DIR}/package"
160PKG_USR_DIR="${PKG_DIR}/usr"
161
162OUT_PKG_DIR="${OUT_DIR}/package"
163OUT_PKG_USR_DIR="${OUT_PKG_DIR}/usr"
164
165BIN_OUTPUT="${OUTPUT_DIR}/debug"
166
167BTCLIENT_BIN="${BIN_OUTPUT}/btclient"
168BTMANAGERD_BIN="${BIN_OUTPUT}/btmanagerd"
169BTADAPTERD_BIN="${BIN_OUTPUT}/btadapterd"
170
171${DRY_RUN} cp -r "${PKG_DIR}" "${OUT_DIR}/"
172
173${DRY_RUN} mkdir -p "${OUT_PKG_USR_DIR}/bin"
174${DRY_RUN} cp "${BTCLIENT_BIN}" "${OUT_PKG_USR_DIR}/bin/"
175
176${DRY_RUN} mkdir -p "${OUT_PKG_USR_DIR}/libexec/bluetooth"
177${DRY_RUN} cp "${BTMANAGERD_BIN}" "${OUT_PKG_USR_DIR}/libexec/bluetooth/"
178${DRY_RUN} cp "${BTADAPTERD_BIN}" "${OUT_PKG_USR_DIR}/libexec/bluetooth/"
179
180# Directory with control file needs the right permissions
181${DRY_RUN} chmod -R 0755 "${TMP_DIR}"
182${DRY_RUN} dpkg-deb --build "${OUT_PKG_DIR}" "${FIRST_DIR}/floss.deb"
183
184${DRY_RUN} rm -rf ${TMP_DIR}
185
186echo
187echo "Now run:"
188echo "    sudo dpkg -i "${FIRST_DIR}"/floss.deb"
189