David Zeuthen | d16471e | 2014-08-19 16:27:58 -0400 | [diff] [blame] | 1 | # Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | |
| 4 | |
| 5 | # @ECLASS: chromium-source.eclass |
| 6 | # @MAINTAINER: |
| 7 | # ChromiumOS Build Team |
| 8 | # @BUGREPORTS: |
| 9 | # Please report bugs via http://crbug.com/new (with label Build) |
| 10 | # @VCSURL: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/eclass/@ECLASS@ |
| 11 | # @BLURB: helper eclass for building packages using the Chromium source code. |
| 12 | # @DESCRIPTION: |
| 13 | # To use this eclass, call chromium-source_src_unpack() from |
| 14 | # src_unpack() in your ebuild. This will set CHROMIUM_SOURCE_DIR to |
| 15 | # where the Chromium source is stored and will also setup the right |
| 16 | # credentials needed by the Chromium build scripts. |
| 17 | # |
| 18 | # Additionally, the CHROMIUM_SOURCE_ORIGIN variable will be set to |
| 19 | # LOCAL_SOURCE if CHROMIUM_SOURCE_DIR points to a local checkout and |
| 20 | # SERVER_SOURCE is it points to a checkout from external VCS |
| 21 | # servers. By default, this is set to LOCAL_SOURCE for ebuilds that |
| 22 | # are being cros_workon'ed and SERVER_SOURCE otherwise. Users can |
| 23 | # override which behavior to use by setting the variable in the |
| 24 | # environment. |
| 25 | # |
| 26 | # This eclass also adds a dependency on chromeos-base/chromium-source |
| 27 | # which is the ebuild used for downloading the source code. |
| 28 | |
| 29 | IUSE="cros_internal" |
| 30 | |
| 31 | # If we're cros_workon'ing the ebuild, default to LOCAL_SOURCE, |
| 32 | # otherwise use SERVER_SOURCE. |
| 33 | chromium_source_compute_origin() { |
| 34 | if [[ -n "${CHROME_ORIGIN}" && -z "${CHROMIUM_SOURCE_ORIGIN}" ]]; then |
| 35 | ewarn "Using CHROME_ORIGIN instead of CHROMIUM_SOURCE_ORIGIN." |
| 36 | ewarn "Please update your workflow to use CHROMIUM_SOURCE_ORIGIN." |
| 37 | CHROMIUM_SOURCE_ORIGIN=${CHROME_ORIGIN} |
| 38 | fi |
| 39 | |
| 40 | local chrome_workon="=${CATEGORY}/${PN}-9999" |
| 41 | local cros_workon_file="${ROOT}etc/portage/package.keywords/cros-workon" |
| 42 | if [[ -e "${cros_workon_file}" ]] && grep -q "${chrome_workon}" "${cros_workon_file}"; then |
| 43 | # LOCAL_SOURCE is the default for cros_workon |
| 44 | # Warn the user if CHROMIUM_SOURCE_ORIGIN is already set |
| 45 | if [[ -n "${CHROMIUM_SOURCE_ORIGIN}" && "${CHROMIUM_SOURCE_ORIGIN}" != LOCAL_SOURCE ]]; then |
| 46 | ewarn "CHROMIUM_SOURCE_ORIGIN is already set to ${CHROMIUM_SOURCE_ORIGIN}." |
| 47 | ewarn "This will prevent you from building from your local checkout." |
| 48 | ewarn "Please run 'unset CHROMIUM_SOURCE_ORIGIN' to reset the build" |
| 49 | ewarn "to the default source location." |
| 50 | fi |
| 51 | : ${CHROMIUM_SOURCE_ORIGIN:=LOCAL_SOURCE} |
| 52 | else |
| 53 | # By default, pull from server |
| 54 | : ${CHROMIUM_SOURCE_ORIGIN:=SERVER_SOURCE} |
| 55 | fi |
| 56 | |
| 57 | case "${CHROMIUM_SOURCE_ORIGIN}" in |
| 58 | LOCAL_SOURCE|SERVER_SOURCE) |
| 59 | elog "CHROMIUM_SOURCE_ORIGIN is ${CHROMIUM_SOURCE_ORIGIN}" |
| 60 | ;; |
| 61 | *) |
| 62 | die "CHROMIUM_SOURCE_ORIGIN is not one of LOCAL_SOURCE, SERVER_SOURCE" |
| 63 | ;; |
| 64 | esac |
| 65 | } |
| 66 | |
| 67 | # Calculate the actual source directory, depending on whether we're |
| 68 | # using LOCAL_SOURCE or SERVER_SOURCE. |
| 69 | chromium_source_compute_source_dir() { |
| 70 | case "${CHROMIUM_SOURCE_ORIGIN}" in |
| 71 | LOCAL_SOURCE) |
| 72 | local WHOAMI=$(whoami) |
| 73 | CHROMIUM_SOURCE_DIR=/home/${WHOAMI}/chrome_root |
| 74 | if [[ ! -d "${CHROMIUM_SOURCE_DIR}/src" ]]; then |
| 75 | die "${CHROMIUM_SOURCE_DIR} does not contain a valid chromium checkout!" |
| 76 | fi |
| 77 | ;; |
| 78 | *) |
| 79 | local CHROME_SRC="chrome-src" |
| 80 | if use chrome_internal; then |
| 81 | CHROME_SRC="${CHROME_SRC}-internal" |
| 82 | fi |
| 83 | CHROMIUM_SOURCE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${CHROME_SRC}" |
| 84 | ;; |
| 85 | esac |
| 86 | } |
| 87 | |
| 88 | # Copy in credentials to fake home directory so that build process can |
| 89 | # access svn and ssh if needed. |
| 90 | chromium_source_copy_credentials() { |
| 91 | mkdir -p "${HOME}" |
| 92 | local WHOAMI=$(whoami) |
| 93 | SUBVERSION_CONFIG_DIR="/home/${WHOAMI}/.subversion" |
| 94 | if [[ -d "${SUBVERSION_CONFIG_DIR}" ]]; then |
| 95 | cp -rfp "${SUBVERSION_CONFIG_DIR}" "${HOME}" || die |
| 96 | fi |
| 97 | SSH_CONFIG_DIR="/home/${WHOAMI}/.ssh" |
| 98 | if [[ -d "${SSH_CONFIG_DIR}" ]]; then |
| 99 | cp -rfp "${SSH_CONFIG_DIR}" "${HOME}" || die |
| 100 | fi |
| 101 | NET_CONFIG="/home/${WHOAMI}/.netrc" |
| 102 | if [[ -f "${NET_CONFIG}" ]]; then |
| 103 | cp -fp "${NET_CONFIG}" "${HOME}" || die |
| 104 | fi |
| 105 | } |
| 106 | |
| 107 | chromium-source_src_unpack() { |
| 108 | chromium_source_compute_origin |
| 109 | chromium_source_compute_source_dir |
| 110 | chromium_source_copy_credentials |
| 111 | } |
| 112 | |
| 113 | if [[ ${PN} != "chromium-source" ]]; then |
| 114 | DEPEND="~chromeos-base/chromium-source-${PV}" |
| 115 | fi |