blob: 6fd5a467eea930b6f062b2a271e776ca58541514 [file] [log] [blame]
Mike Frysinger4ed918e2012-05-09 15:44:12 -04001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Kenneth Waters512eb162010-06-02 10:19:12 -07002# Distributed under the terms of the GNU General Public License v2
3
4#
5# Original Author: The Chromium OS Authors <chromium-os-dev@chromium.org>
6# Purpose: Install binary packages for Chromium OS
7#
8
Mike Frysinger4d7d4fa2015-11-30 16:44:40 -05009# Reject old users of cros-binary eclass that expected us to download files
10# directly rather than going through SRC_URI.
11cros-binary_dead_usage() {
12 die "You must add files to SRC_URI now"
13}
14if [[ ${CROS_BINARY_STORE_DIR:+set} == "set" ||
15 ${CROS_BINARY_SUM:+set} == "set" ||
16 ${CROS_BINARY_FETCH_REQUIRED:+set} == "set" ]]; then
17 cros-binary_dead_usage
18fi
Brian Harringcf0c7662012-12-19 23:06:44 -080019
20# @ECLASS-FUNCTION: cros-binary_add_uri
21# @DESCRIPTION:
22# Add a fetch uri to SRC_URI for the given uri. See
23# CROS_BINARY_URI for what is accepted. Note you cannot
24# intermix a non-rewritten ssh w/ (http|https|gs).
25cros-binary_add_uri()
26{
27 if [[ $# -ne 1 ]]; then
28 die "cros-binary_add_uri takes exactly one argument; $# given."
29 fi
30 local uri="$1"
31 if [[ "${uri}" =~ ^ssh://([^@]+)@git.chromium.org[^/]*/(.*)$ ]]; then
32 uri="gs://chromeos-binaries/HOME/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
33 fi
34 case "${uri}" in
35 http://*|https://*|gs://*)
36 SRC_URI+=" ${uri}"
37 CROS_BINARY_FETCH_REQUIRED=false
38 CROS_BINARY_STORE_DIR="${DISTDIR}"
39 ;;
40 *)
41 die "Unknown protocol: ${uri}"
42 ;;
43 esac
Mike Frysinger6300c4b2013-04-06 22:48:39 -040044 RESTRICT+=" mirror"
Brian Harringcf0c7662012-12-19 23:06:44 -080045}
46
47# @ECLASS-FUNCTION: cros-binary_add_gs_uri
48# @DESCRIPTION:
49# Wrapper around cros-binary_add_uri. Invoked with 3 arguments;
50# the bcs user, the overlay, and the filename (or bcs://<uri> for
51# backwards compatibility).
52cros-binary_add_gs_uri() {
53 if [[ $# -ne 3 ]]; then
54 die "cros-binary_add_bcs_uri needs 3 arguments; $# given."
55 fi
56 # Strip leading bcs://...
57 [[ "${3:0:6}" == "bcs://" ]] && set -- "${1}" "${2}" "${3#bcs://}"
58 cros-binary_add_uri "gs://chromeos-binaries/HOME/$1/$2/$3"
59}
60
61# @ECLASS-FUNCTION: cros-binary_add_overlay_uri
62# @DESCRIPTION:
63# Wrapper around cros-binary_add_bcs_uri. Invoked with 2 arguments;
64# the basic board target (x86-alex for example), and the filename; that filename
65# is automatically prefixed with "${CATEGORY}/${PN}/" .
66cros-binary_add_overlay_uri() {
67 if [[ $# -ne 2 ]]; then
68 die "cros-binary_add_bcs_uri_simple needs 2 arguments; $# given."
69 fi
70 cros-binary_add_gs_uri bcs-"$1" overlay-"$1" "${CATEGORY}/${PN}/$2"
71}
72
Kenneth Waters512eb162010-06-02 10:19:12 -070073# @ECLASS-VARIABLE: CROS_BINARY_URI
74# @DESCRIPTION:
75# URI for the binary may be one of:
76# http://
77# https://
78# ssh://
Brian Harringcf0c7662012-12-19 23:06:44 -080079# gs://
Kenneth Waters512eb162010-06-02 10:19:12 -070080# file:// (file is relative to the files directory)
Brian Harringcf0c7662012-12-19 23:06:44 -080081# Additionally, all bcs ssh:// urls are rewritten to gs:// automatically
82# the appropriate GS bucket- although cros-binary_add_uri is the preferred
83# way to do that.
84# TODO: Deprecate this variable's support for ssh and http/https.
Kenneth Waters512eb162010-06-02 10:19:12 -070085: ${CROS_BINARY_URI:=}
Brian Harringcf0c7662012-12-19 23:06:44 -080086if [[ -n "${CROS_BINARY_URI}" ]]; then
87 cros-binary_add_uri "${CROS_BINARY_URI}"
88fi
Kenneth Waters512eb162010-06-02 10:19:12 -070089
Puneet Kumar0cc9c652010-08-25 13:35:17 -070090# @ECLASS-VARIABLE: CROS_BINARY_INSTALL_FLAGS
91# @DESCRIPTION:
92# Optional Flags to use while installing the binary
93: ${CROS_BINARY_INSTALL_FLAGS:=}
94
Allen Martin967a8242012-03-27 04:51:34 +000095# @ECLASS-VARIABLE: CROS_BINARY_LOCAL_URI_BASE
96# @DESCRIPTION:
97# Optional URI to override CROS_BINARY_URI location. If this variable
98# is used the filename from CROS_BINARY_URI will be used, but the path
99# to the binary will be changed.
100: ${CROS_BINARY_LOCAL_URI_BASE:=}
101
Mike Frysinger4ed918e2012-05-09 15:44:12 -0400102# Check for EAPI 2+
Kenneth Waters512eb162010-06-02 10:19:12 -0700103case "${EAPI:-0}" in
Mike Frysinger4ed918e2012-05-09 15:44:12 -0400104 4|3|2) ;;
105 *) die "unsupported EAPI" ;;
Kenneth Waters512eb162010-06-02 10:19:12 -0700106esac
107
108cros-binary_check_file() {
109 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
Nick Sanders97c10552011-03-11 21:25:36 -0800110 elog "Checking for cached $target"
Kenneth Waters512eb162010-06-02 10:19:12 -0700111 if [[ -z "${CROS_BINARY_SUM}" ]]; then
Allen Martin967a8242012-03-27 04:51:34 +0000112 return 1
Kenneth Waters512eb162010-06-02 10:19:12 -0700113 else
114 echo "${CROS_BINARY_SUM} ${target}" |
115 sha1sum -c --quiet >/dev/null 2>&1
116 return
117 fi
118}
119
120cros-binary_fetch() {
Mike Frysinger4d7d4fa2015-11-30 16:44:40 -0500121 cros-binary_dead_usage
Kenneth Waters512eb162010-06-02 10:19:12 -0700122}
123
124cros-binary_src_unpack() {
Mike Frysinger4d7d4fa2015-11-30 16:44:40 -0500125 cros-binary_dead_usage
Kenneth Waters512eb162010-06-02 10:19:12 -0700126}
127
128cros-binary_src_install() {
Brian Harringcf0c7662012-12-19 23:06:44 -0800129 local target="${CROS_BINARY_URI##*/}"
130 if ${CROS_BINARY_FETCH_REQUIRED}; then
131 target="${CROS_BINARY_STORE_DIR}/${target}"
132 else
133 target="${DISTDIR}/${target}"
134 fi
Kenneth Waters512eb162010-06-02 10:19:12 -0700135
136 local extension="${CROS_BINARY_URI##*.}"
137 local flags
138
139 case "${CROS_BINARY_URI##*.}" in
140 gz|tgz) flags="z";;
141 bz2|tbz2) flags="j";;
142 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
143 esac
144
145 cd "${D}" || die
Puneet Kumar0cc9c652010-08-25 13:35:17 -0700146 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters512eb162010-06-02 10:19:12 -0700147}
148
Mike Frysinger4d7d4fa2015-11-30 16:44:40 -0500149EXPORT_FUNCTIONS src_install
Kenneth Waters512eb162010-06-02 10:19:12 -0700150