blob: 1c5b307d36fd0d41b5c21fdfdecfdb638f5c1589 [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
EAPI=7
CROS_WORKON_COMMIT="828bcffbe06a20dd65427d294723b6bf30cd6dbb"
CROS_WORKON_TREE=("52a8a8b6d3bbca5e90d4761aa308a5541d52b1bb" "15d392511855fd12421e2bb0d735d75278a92065" "4dc9e176d315085cb2b8c8ad66d1965575ef5280" "e7dba8c91c1f3257c34d4a7ffff0ea2537aeb6bb")
CROS_WORKON_LOCALNAME="platform2"
CROS_WORKON_PROJECT="chromiumos/platform2"
# TODO(amoylan): Set CROS_WORKON_OUTOFTREE_BUILD=1 after crbug.com/833675.
CROS_WORKON_DESTDIR="${S}/platform2"
CROS_WORKON_SUBTREE="common-mk ml ml_benchmark .gn"
PLATFORM_SUBDIR="ml"
inherit cros-workon platform user
DESCRIPTION="Machine learning service for Chromium OS"
HOMEPAGE="https://chromium.googlesource.com/chromiumos/platform2/+/master/ml"
# Clients of the ML service should place the URIs of their model files into
# MODELS_TO_INSTALL if they are installed into rootfs (built-in models), or
# DOWNLOADABLE_MODELS if they are downloaded via component updater (downloadable
# models).
MODELS_TO_INSTALL=(
"gs://chromeos-localmirror/distfiles/mlservice-model-test_add-20180914.tflite"
"gs://chromeos-localmirror/distfiles/mlservice-model-search_ranker-20190923.tflite"
"gs://chromeos-localmirror/distfiles/mlservice-model-smart_dim-20181115.tflite"
"gs://chromeos-localmirror/distfiles/mlservice-model-smart_dim-20190221.tflite"
"gs://chromeos-localmirror/distfiles/mlservice-model-smart_dim-20190521-v3.tflite"
)
DOWNLOADABLE_MODELS=(
"gs://chromeos-localmirror/distfiles/mlservice-model-smart_dim-20200206-downloadable.tflite"
)
SRC_URI="
${DOWNLOADABLE_MODELS[*]}
${MODELS_TO_INSTALL[*]}
"
LICENSE="BSD-Google"
KEYWORDS="*"
IUSE="
dlc
fuzzer
ml_benchmark_drivers
nnapi
ondevice_grammar
ondevice_handwriting
ondevice_handwriting_dlc
ondevice_speech
"
RDEPEND="
chromeos-base/chrome-icu:=
>=chromeos-base/metrics-0.0.1-r3152:=
ondevice_speech? ( chromeos-soda/libsoda:=[dlc=] )
nnapi? ( chromeos-base/aosp-frameworks-ml-nn )
>=dev-libs/libgrammar-0.0.3:=[ondevice_grammar=]
dev-libs/libhandwriting:=[ondevice_handwriting=,ondevice_handwriting_dlc=]
>=dev-libs/libtextclassifier-0.0.1-r79:=
sci-libs/tensorflow:=
"
DEPEND="
${RDEPEND}
chromeos-base/system_api:=[fuzzer?]
dev-cpp/absl:=
dev-libs/libutf:=
dev-libs/marisa-aosp:=
"
# SODA will not be supported on rootfs and only be supported through DLC.
REQUIRED_USE="ondevice_speech? ( dlc )"
src_install() {
dobin "${OUT}"/ml_service
# Install upstart configuration.
insinto /etc/init
doins init/*.conf
# Install seccomp policy file.
insinto /usr/share/policy
newins "seccomp/ml_service-seccomp-${ARCH}.policy" ml_service-seccomp.policy
# Install D-Bus configuration file.
insinto /etc/dbus-1/system.d
doins dbus/org.chromium.MachineLearning.conf
# Install D-Bus service activation configuration.
insinto /usr/share/dbus-1/system-services
doins dbus/org.chromium.MachineLearning.service
# Create distfile array of model filepaths.
local model_files=( "${MODELS_TO_INSTALL[@]##*/}" )
local distfile_array=( "${model_files[@]/#/${DISTDIR}/}" )
# Install system ML models.
insinto /opt/google/chrome/ml_models
doins "${distfile_array[@]}"
# Install system ML models to fuzzer dir.
insinto /usr/libexec/fuzzers
doins "${distfile_array[@]}"
# Install fuzzer targets.
for fuzzer in "${OUT}"/*_fuzzer; do
platform_fuzzer_install "${S}"/OWNERS "${fuzzer}"
done
if use ml_benchmark_drivers; then
insinto /usr/local/ml_benchmark/ml_service
insopts -m0755
doins "${OUT}"/lib/libml_for_benchmark.so
insopts -m0644
fi
}
pkg_preinst() {
enewuser "ml-service"
enewgroup "ml-service"
}
platform_pkg_test() {
# Recreate model dir in the temp directory and copy both
# MODELS_TO_INSTALL and DOWNLOADABLE_MODELS into it for use in unit
# tests.
mkdir "${T}/ml_models" || die
local all_test_models=( "${DOWNLOADABLE_MODELS[@]}" "${MODELS_TO_INSTALL[@]}" )
local distfile_uri
for distfile_uri in "${all_test_models[@]}"; do
cp "${DISTDIR}/${distfile_uri##*/}" "${T}/ml_models" || die
done
platform_test "run" "${OUT}/ml_service_test"
}