blob: 6f34a0b2b4a2dfd614a96b6378008b546eea8f00 [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script takes an existing llvm ebuild file and generate a llvm-extra
# ebuild. The newly generated llvm-extra ebuild can be installed as a regular
# host package.
# The new ebuild should be generated in sys-devel/llvm-extra directory.
# The script also copies all the files from files/ directory.
# The generated llvm-extra ebuild is slotted so multiple instances of
# llvm-extra ebuilds can be installed at same time.
# The slot is derived based on the _pre<num> string in the llvm ebuild name.
# e.g. For llvm-7.0_pre331547_p20180529-r8.ebuild, the slot will be
# 7.0_pre331547.
# Usage:
# ./ /path/to/llvm-7.0_pre331547_p20180529-r8.ebuild
# To use the clang installed by llvm-extra, modify the CFLAGS and
# LDFLAGS of a pckage to pass the patch of the clang binary installed by
# the llvm-extra package.
# e.g. append-flags -Xclang-path=/usr/llvm-extra/version/clang
# append-ldflags -Xclang-path=/usr/llvm-extra/version/clang
SCRIPT_DIR=$(realpath $(dirname "$0"))
function check_cmd() {
if [[ "$#" -ne 1 ]]; then
echo "Exactly 1 argument expected"
echo "Usage $0 <path_to_llvm_ebuild>"
exit 1
if [[ ! -f "$1" ]]; then
echo "$1 is not a file"
exit 1;
function create_llvm_extra_ebuild() {
EBUILD_DIR=$(dirname "$1")
EBUILD_FILE_NAME=$(basename "$1")
mkdir -p "${NEW_EBUILD_DIR}"
if [[ -d "${EBUILD_DIR}/files" ]]; then
cp -rf "${EBUILD_DIR}/files" "${NEW_EBUILD_DIR}"
if [[ -f "${NEW_EBUILD_DIR}/${NEW_EBUILD_FILE_NAME}" ]]; then
echo "Removing existing ebuild file ${NEW_EBUILD_FILE_NAME}"
# Generate the llvm-extra ebuild file.
if [[ $? -ne 0 ]]; then
echo "Creation of ${NEW_EBUILD_DIR}/${NEW_EBUILD_FILE_NAME} failed"
exit 1
echo "***"
echo "***"
echo "${NEW_EBUILD_DIR}/${NEW_EBUILD_FILE_NAME} has been created."
echo "***"
echo "Test if it builds by running \$ sudo emerge ${EBUILD_PREFIX}:${NEW_EBUILD_SLOT}"
echo "***"
echo "If it works, Go ahead and submit the newly generated ebuild"\
"and any other files in ${NEW_EBUILD_DIR}."
echo "***"
echo "Don't forget to add sys-devel/${EBUILD_PREFIX}:${NEW_EBUILD_SLOT} to"\
"the dependencies in virtual/target-chromium-os-sdk ebuild."
echo "***"
echo "***"
set -e
# Sanity checks.
check_cmd "${@}"
# Create llvm-extra ebuild.
create_llvm_extra_ebuild "${@}"