blob: 680e08b7a16c98ebb12365e51541235acdcae692 [file] [log] [blame]
Viet-Trung Luu10fc7242016-03-04 15:40:04 -08001#!/bin/bash
2# Copyright 2016 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Script that "builds" and uploads a C++ SDK to GCS.
7
8set -e
9
10SCRIPT_DIR=$(dirname $0)
11BUILD_SDK=${SCRIPT_DIR}/build_sdk.py
12
13WORK_DIR=$(mktemp -d -t build_cpp_sdk.XXXXXXXX)
14function cleanup_work_dir {
15 rm -rf "$WORK_DIR"
16}
17trap cleanup_work_dir EXIT
18
19# Build the SDK.
20SDK_DIRNAME=mojo_cpp_sdk
21SDK_DIR=${WORK_DIR}/${SDK_DIRNAME}
22"$BUILD_SDK" "${SCRIPT_DIR}/data/cpp/cpp.sdk" "$SDK_DIR"
23
24# Get the version (hash).
25VERSION=$(cat "${SDK_DIR}/MOJO_SDK_VERSION")
26# Abbreviate it to 12 hex digits.
27SHORT_VERSION=${VERSION:0:12}
28echo "SDK version (hash): ${VERSION} (${SHORT_VERSION})"
29
30# Make a tarball.
31TARBALL_FILENAME=mojo_cpp_sdk-${SHORT_VERSION}.tar.gz
32TARBALL_FILE=${WORK_DIR}/${TARBALL_FILENAME}
33# In a subshell, change to WORK_DIR so that the tarball will only have the
34# mojo_cpp_sdk part of the path.
35(
36 cd "${WORK_DIR}"
37 tar c --owner=root --group=root -z -f "$TARBALL_FILENAME" "$SDK_DIRNAME"
38)
39
40# Assume that we're the "latest". Make a file containing the abbreviated hash.
41LATEST_FILENAME=LATEST
42LATEST_FILE=${WORK_DIR}/${LATEST_FILENAME}
43echo "$SHORT_VERSION" > "$LATEST_FILE"
44
45echo "Press enter to upload ${TARBALL_FILENAME} to GCS"
46read
47
48GCS_BASE_URL="gs://mojo/sdk/cpp"
49# Don't clobber existing tarballs.
50gsutil cp -n "$TARBALL_FILE" "${GCS_BASE_URL}/${TARBALL_FILENAME}"
51# But allow "LATEST" to be clobbered.
52gsutil cp "$LATEST_FILE" "${GCS_BASE_URL}/${LATEST_FILENAME}"
53
54echo "Done!"