summaryrefslogtreecommitdiff
path: root/script/build.sh
blob: 79d9c14721308587cf5ea4963a6518912e8d5428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash -e

SCRIPT_DIR=$(dirname $(readlink -f $0))
BUILD_ROOT="gbsbuild"
BUILD_RPM="local/repos/tizen/armv7l/RPMS"

cmd_usage() {
  echo "Usage: $0 [command] [args]"
  echo "Commands:"
  echo "    build                  Build rpm packages to $BUILD_ROOT"
  echo "    install [target]       Install RPM packages to the target device"
  echo "    clean                  gbs build root"
  echo "    test_setup [target]    Setup test resources to the target device"
  echo "    test_run [target]      Run unit test on the target device"
  echo "    test_clean [target]    Clean test resources on the target device"
}

cmd_clean() {
  echo "Clean gbsroot require sudo privilege, type"
  echo "$(tput setaf 2)sudo rm -rf $PWD/$BUILD_ROOT$(tput setaf 0)"
}

cmd_build() {
  gbs build -A armv7l --include-all -B $PWD/$BUILD_ROOT
}

check_target() {

  DEVICE_ID=$1
  device_cnt=$(sdb devices | grep -v "List" | wc -l)

  if [ $device_cnt -eq 0 ]; then
    echo "No connected devices"
    exit 1
  fi

  if [ $device_cnt -gt 1 ] && [ -z "$DEVICE_ID" ]; then
    echo "Multiple devices are connected. Specify the device. (ex: ./build.sh install [device-id])"
    sdb devices
    exit 1
  fi

  SDB_OPTIONS=""
  if [ -n "$DEVICE_ID" ]; then
    SDB_OPTIONS="-s $DEVICE_ID"
  fi

  sdb $SDB_OPTIONS root on
  sdb $SDB_OPTIONS shell mount -o remount,rw /
}

cmd_install() {
  check_target $@

  sdb $SDB_OPTIONS push $PWD/$BUILD_ROOT/$BUILD_RPM/* /root

  echo "$(tput setaf 2)Packages are copied to target /root $(tput setaf 0)"
  echo "$(tput setaf 2)Install packages what you needed.$(tput setaf 0)"
}

cmd_test_setup() {
  check_target $@

  sdb $SDB_OPTIONS shell mkdir -p /tmp/mvtest/

  # check [test/tct/native/api.git] /src/utc/capi-media-vision/res/ is on target
  res_exist=$(sdb $SDB_OPTIONS shell '[ -d "/tmp/mvtest/res" ] && echo 1')
  if [ -z $res_exist ]; then
    echo 'download https://review.tizen.org/gerrit/gitweb?p=test/tct/native/api.git;a=snapshot;h=1c301c79f082ac7a43f7f0791bbac609b1c34eb3;sf=tgz'
    echo 'and copy to /tmp/mvtest/res on target'
    sdb $SDB_OPTIONS shell mkdir -p /tmp/mvtest/res
  fi

  # check libcheck is installed
  n_libcheck=$(sdb $SDB_OPTIONS shell ldconfig -p | grep libcheck | wc -l)
  if [ $n_libcheck -eq 0 ]; then
    echo "$(tput setaf 1)libcheck is not installed$(tput setaf 0)"
    wget -r -nd --no-parent -A 'check-[0-9]*.armv7l.rpm' http://download.tizen.org/snapshots/tizen/unified/latest/repos/standard/packages/armv7l/
    sdb $SDB_OPTIONS push check*.rpm /root
    sdb $SDB_OPTIONS shell rpm -iv check*.rpm
    rm check*.rpm
  fi
}

cmd_test_run() {
  check_target $@
  echo "$(tput setaf 2)Test mv_barcode_test_suite$(tput setaf 0)"
  sdb $SDB_OPTIONS shell mv_barcode_test_suite
}

cmd_test_clean() {
  check_target $@

  sdb $SDB_OPTIONS shell rm -rf /tmp/mvtest/
  sdb $SDB_OPTIONS shell rpm -e check
}

cmd=$1
[ $# -gt 0 ] && shift
case "$cmd" in
build | --build | -b) cmd_build ;;
install | --install | -i) cmd_install $@ ;;
clean | --clean | -c) cmd_clean ;;
test_setup | --test_setup | -ts) cmd_test_setup $@ ;;
test_run | --test_run | -tr) cmd_test_run $@ ;;
test_clean | --test_clean | -tc) cmd_test_clean $@ ;;
*) cmd_usage ;;
esac