11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci#
31cb0ef41Sopenharmony_ci# Copyright 2020 the V8 project authors. All rights reserved.
41cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
51cb0ef41Sopenharmony_ci# found in the LICENSE file.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cisourcedir=$(cd "$(dirname "$0")"; pwd -P)
81cb0ef41Sopenharmony_cirootdir=$sourcedir/../../
91cb0ef41Sopenharmony_citestdir=$rootdir/test/unittests/
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cimaingn=$rootdir/BUILD.gn
121cb0ef41Sopenharmony_citestgn=$testdir/BUILD.gn
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cifunction fail {
151cb0ef41Sopenharmony_ci  echo -e "\033[0;31m$1\033[0m" > /dev/stderr
161cb0ef41Sopenharmony_ci  exit 1
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction cleanup {
201cb0ef41Sopenharmony_ci  rm $cmakelists
211cb0ef41Sopenharmony_ci  if [[ -d "$tempdir" ]]; then
221cb0ef41Sopenharmony_ci    rm -rf $tempdir
231cb0ef41Sopenharmony_ci  fi
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_citrap "exit 1" HUP INT PIPE QUIT TERM
271cb0ef41Sopenharmony_citrap cleanup EXIT
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciif [[ ! -f "$maingn" || ! -f "$testgn" ]]; then
301cb0ef41Sopenharmony_ci  fail "Expected GN files are not present"
311cb0ef41Sopenharmony_cifi
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cicmakelists=$rootdir/CMakeLists.txt
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci# Generate CMakeLists.txt in the root project directory.
361cb0ef41Sopenharmony_ci$sourcedir/gen_cmake.py --out=$cmakelists --main-gn=$maingn --test-gn=$testgn
371cb0ef41Sopenharmony_ciif [ $? -ne 0 ]; then
381cb0ef41Sopenharmony_ci  fail "CMakeLists.txt generation has failed"
391cb0ef41Sopenharmony_cifi
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci# Create a temporary build directory.
421cb0ef41Sopenharmony_citempdir=$(mktemp -d)
431cb0ef41Sopenharmony_ciif [[ ! "$tempdir" || ! -d "$tempdir" ]]; then
441cb0ef41Sopenharmony_ci  fail "Failed to create temporary dir"
451cb0ef41Sopenharmony_cifi
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci# Configure project with cmake.
481cb0ef41Sopenharmony_cicd $tempdir
491cb0ef41Sopenharmony_cicmake -GNinja $rootdir || fail "Failed to execute cmake"
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci# Build all targets.
521cb0ef41Sopenharmony_cininja cppgc || fail "Failed to build cppgc"
531cb0ef41Sopenharmony_cininja cppgc_hello_world || fail "Failed to build sample"
541cb0ef41Sopenharmony_cininja cppgc_unittests || fail "Failed to build unittests"
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci# Run unittests.
571cb0ef41Sopenharmony_ci./cppgc_unittests || fail "Failed to run unittests"
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciecho -e "\033[0;32mThe test has succesfully passed\033[0m"
60