blob: 438d2a9d6566e2cdd3c2f9da968fa6ca9fed6a86 [file] [log] [blame]
#
# Copyright 2021 Google LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
EAPI=7
inherit cros-constants
CROS_WORKON_REPO="https://cos.googlesource.com"
CROS_WORKON_PROJECT="cos/policymanager"
CROS_WORKON_LOCALNAME="policymanager"
CROS_WORKON_DESTDIR="${S}"
inherit cros-workon cros-go systemd
DESCRIPTION="Policy Manager Client for managing Lakitu updates"
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~*"
IUSE="stackdriver_alpha"
RDEPEND="chromeos-base/update_engine
!chromeos-base/chromeos-login"
DEPEND="${RDEPEND}
dev-go/dbus
dev-go/glog
dev-go/mock
dev-go/net
dev-go/oauth2
dev-go/protobuf"
src_compile() {
ebegin "Building Policy Manager ${CROS_WORKON_COMMIT}"
# Enables/disables IUSE controlled feature flags.
BUILDTAGS=()
if use stackdriver_alpha; then
BUILDTAGS+=("stackdriver_alpha")
fi
if [ ${#BUILDTAGS[@]} -ne 0 ]; then
BUILD_FLAGS=("-tags" "${BUILDTAGS[@]}")
fi
# Compile protobuf definitions.
pushd ${CROS_WORKON_DESTDIR}/src
./gen_proto.sh
popd
cros_go build -v -o device_policy_manager "${BUILD_FLAGS[@]}" "policy_manager"
# Compile install_attributes proto for "enterprise enrollment"
protoc -I "${FILESDIR}" \
--encode=cryptohome.SerializedInstallAttributes \
"${FILESDIR}/install_attributes.proto" \
< "${FILESDIR}/install_attributes.textproto" \
> install_attributes.pb
eend ${?}
}
# Unit tests for Policy Manager.
# The tests are run as part of the build process.
src_test() {
ebegin "Running Policy Manager unit tests"
# Enables/disables IUSE controlled feature flags.
BUILDTAGS=()
if use stackdriver_alpha; then
BUILDTAGS+=("stackdriver_alpha")
fi
if [ ${#BUILDTAGS[@]} -ne 0 ]; then
BUILD_FLAGS=("-tags" "${BUILDTAGS[@]}")
fi
# Generate interface mocks.
pushd ${CROS_WORKON_DESTDIR}/src
GOPATH="$(cros-go_gopath)" ./gen_mock.sh
popd
# Recursively test all packages in Policy Manager.
cros_go test -v "${BUILD_FLAGS[@]}" policy_manager/...
if [ $? -ne 0 ]
then
die "Policy Manager unit tests failed :("
fi
eend ${?}
}
src_install() {
ebegin "Installing Policy Manager"
dosbin device_policy_manager
systemd_dounit "${FILESDIR}"/device_policy_manager.service
systemd_enable_service multi-user.target device_policy_manager.service
systemd_dounit "${FILESDIR}"/init-device-policy.service
systemd_enable_service multi-user.target init-device-policy.service
systemd_dounit "${FILESDIR}"/setup-install-attributes.service
systemd_enable_service sysinit.target setup-install-attributes.service
insinto /etc/dbus-1/system.d
doins src/policy_manager/dbus/SessionManager.conf
insinto /usr/share/cloud
doins install_attributes.pb
eend ${?}
}