• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright 2020 the V8 project authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7source_dir=$(cd "$(dirname "$0")"; pwd -P)
8
9copybara_exe=copybara
10copybara_file="$source_dir/copy.bara.sky"
11init_history=''
12
13for arg in "$@"; do
14  case $arg in
15    --copybara-exe=*)
16      copybara_exe="${arg#*=}"
17      shift
18      ;;
19    --copybara-file=*)
20      copybara_file="${arg#*=}"
21      shift
22      ;;
23    --init-history)
24      init_history='--init-history --force'
25      shift
26      ;;
27    *)
28      echo -e "Usage:$arg"
29      echo -e "    export_to_github.sh [--copybara-exe=<path-to-copybara>]\n" \
30              "                       [--copybara-file=<path-to-copy.bara.sky>]"
31      exit 1
32  esac
33done
34
35v8_origin="https://chromium.googlesource.com/v8/v8.git"
36v8_ref="master"
37
38NOCOLOR="\033[0m"
39RED="\033[0;31m"
40GREEN="\033[0;32m"
41BLUE="\033[0;34m"
42
43function fail {
44  echo -e "${RED}${1}${NOCOLOR}" > /dev/stderr
45  exit 1
46}
47
48function success {
49  echo -e "${BLUE}${1}${NOCOLOR}" > /dev/stderr
50  exit 0
51}
52
53function message {
54  echo -e "${GREEN}${1}${NOCOLOR}" > /dev/stderr
55}
56
57function cleanup {
58  if [ -d "$git_temp_dir" ]; then
59    rm -rf $git_temp_dir
60  fi
61}
62
63trap "exit 1" HUP INT PIPE QUIT TERM
64trap cleanup EXIT
65
66[ ! -x $copybara_exe ] && fail "$copybara_exe doesn't exist or was not found in PATH!"
67[ ! -f $copybara_file ] && fail "Input $copybara_file doesn't exist!"
68
69git_temp_dir=$(mktemp -d)
70if [[ ! "$git_temp_dir" || ! -d "$git_temp_dir" ]]; then
71  fail "Failed to create temporary dir"
72fi
73
74if [[ $init_history ]]; then
75  read -p "--init-history is only supposed to be used on the first export of \
76cppgc. Is this what is really intended? (y/N)" answer
77  if [ "$answer" != "y" ]; then
78    exit 0
79  fi
80fi
81
82message "Running copybara..."
83$copybara_exe $init_history $copybara_file --dry-run --git-destination-path $git_temp_dir
84result=$?
85if [ "$result" -eq 4 ]; then
86  success "Nothing needs to be done, exiting..."
87elif [ "$result" -ne 0 ]; then
88  fail "Failed to run copybara"
89fi
90
91cd $git_temp_dir
92
93main_gn="BUILD.gn"
94test_gn="test/unittests/BUILD.gn"
95gen_cmake="tools/cppgc/gen_cmake.py"
96
97message "Checking out BUILD.gn files..."
98git remote add v8_origin "$v8_origin"
99git fetch --depth=1 v8_origin $v8_ref
100git checkout v8_origin/master -- "$main_gn" "$test_gn" "$gen_cmake" \
101  || fail "Failed to checkout BUILD.gn from V8 origin"
102
103message "Generating CMakeLists.txt..."
104cmakelists="$git_temp_dir/CMakeLists.txt"
105$gen_cmake --out=$cmakelists --main-gn=$main_gn --test-gn=$test_gn \
106  || fail "CMakeLists.txt generation has failed!"
107
108git rm -f $main_gn $test_gn $gen_cmake > /dev/null
109
110if git status -s | grep -q $(basename $cmakelists); then
111  message "CMakeLists.txt needs to be changed"
112  git add $cmakelists
113  git commit --amend --no-edit > /dev/null
114else
115  message "No changes in CMakeLists.txt need to be done"
116fi
117
118message "Pushing changes to GitHub..."
119git push copybara_remote master
120
121success "CppGC GitHub mirror was successfully updated"
122