• 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
7sourcedir=$(cd "$(dirname "$0")"; pwd -P)
8rootdir=$sourcedir/../../
9testdir=$rootdir/test/unittests/
10
11maingn=$rootdir/BUILD.gn
12testgn=$testdir/BUILD.gn
13
14function fail {
15  echo -e "\033[0;31m$1\033[0m" > /dev/stderr
16  exit 1
17}
18
19function cleanup {
20  rm $cmakelists
21  if [[ -d "$tempdir" ]]; then
22    rm -rf $tempdir
23  fi
24}
25
26trap "exit 1" HUP INT PIPE QUIT TERM
27trap cleanup EXIT
28
29if [[ ! -f "$maingn" || ! -f "$testgn" ]]; then
30  fail "Expected GN files are not present"
31fi
32
33cmakelists=$rootdir/CMakeLists.txt
34
35# Generate CMakeLists.txt in the root project directory.
36$sourcedir/gen_cmake.py --out=$cmakelists --main-gn=$maingn --test-gn=$testgn
37if [ $? -ne 0 ]; then
38  fail "CMakeLists.txt generation has failed"
39fi
40
41# Create a temporary build directory.
42tempdir=$(mktemp -d)
43if [[ ! "$tempdir" || ! -d "$tempdir" ]]; then
44  fail "Failed to create temporary dir"
45fi
46
47# Configure project with cmake.
48cd $tempdir
49cmake -GNinja $rootdir || fail "Failed to execute cmake"
50
51# Build all targets.
52ninja cppgc || fail "Failed to build cppgc"
53ninja cppgc_hello_world || fail "Failed to build sample"
54ninja cppgc_unittests || fail "Failed to build unittests"
55
56# Run unittests.
57./cppgc_unittests || fail "Failed to run unittests"
58
59echo -e "\033[0;32mThe test has succesfully passed\033[0m"
60