aboutsummaryrefslogtreecommitdiff
path: root/dacapo/setup_dacapo.sh
blob: ac94e60450ddc3e9fcc0f05f6c76061cd0d1adec (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
#
# Copyright (C) 2021 Linaro Limited. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

unset DEST_DIR

readonly CRED="\033[0;31m"
readonly CORANGE="\033[0;33m"
readonly CGREEN="\033[0;32m"
readonly CNC="\033[0m"

# Print error message
#   ${1} - error message
error() {
  echo -e "${CRED}ERROR: $*${CNC}" >&2
}

# Print info message
#   ${1} - info message
info() {
  echo -e "${CORANGE}INFO: $*${CNC}" >&2
}

# Print error message and exit from the script
#   ${1} - error message.
exit_with_error() {
  error "$1"
  exit 1
}

# Check exit code of the previous command; if non-zero, abort.
# Arguments:
#   ${1} - error message.
if_error() {
  # shellcheck disable=SC2181
  if [[ $? -ne 0 ]]; then
    exit_with_error "$1"
  fi
}

# Execute the arguments; if the exit code is non-zero, abort.
safe() {
  "$@"
  if_error "Failed command: $*"
}

readonly usage="Usage: $(basename "$0") -d dest_dir
Setup DaCapo binaries and resource files and workloads runners into
a provided destination directory.

Options:
    -h                  Show this help message.
    -d                  A path to the directory where to put all needed files.
"

main() {
  while getopts ":hd:" option; do
    if [[ ${OPTARG} == -* ]]; then
      exit_with_error "Option -${option} requires an argument." >&2
    fi
    case "${option}" in
      h) info "${usage}"; exit ;;
      d) DEST_DIR=${OPTARG}
        ;;
      \?)
        error "Illegal option: -${OPTARG}" >&2
        error "${usage}"
        exit 1
        ;;
      :)
        exit_with_error "Option -${OPTARG} requires an argument." >&2
        ;;
    esac
  done

  if [ -z ${DEST_DIR} ]; then
    exit_with_error "Please, use -d argument to specify the location of Linaro tree."
  fi

  if [ ! -d ${DEST_DIR} ]; then
    exit_with_error "The directory ${DEST_DIR} does not exist. Please specify a valid path" \
                    "to your Linaro tree."
  fi

  if [ -z "${JAVA_HOME}" ]; then
    exit_with_error "Please, set JAVA_HOME environment variable to path to Java8 jdk and" \
                    "re-run the script."
  else
    JAVA_VERSION=$("${JAVA_HOME}/bin/java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
    info "Detected Java version ${JAVA_VERSION:0:3}"
    if [[ ${JAVA_VERSION:0:3} != "1.8" ]]; then
      exit_with_error "Please update JAVA_HOME environment variable with the location of Java 8"
    fi
  fi

  cd $(dirname "$0")

  # copy wrappers
  info "Copying wrappers"
  safe cp -r wrappers/dacapo ${DEST_DIR}/benchmarks/benchmarks

  # build DaCapo
  if [[ -d dacapo_src ]]; then
    safe rm -rf dacapo_src
  fi
  mkdir dacapo_src
  cd dacapo_src

  local -r DACAPO_REPO="https://github.com/dacapobench/dacapobench.git"
  info "Cloning ${DACAPO_REPO} into dacapo_src..."
  safe git clone --branch master ${DACAPO_REPO}

  safe cd dacapobench
  # commit id that is used as a base for all patches
  local -r DACAPO_COMMIT="6cf03808b686896eb092c038d6add7d9384f03f5"
  info "Reseting to ${DACAPO_COMMIT}"
  safe git reset --hard ${DACAPO_COMMIT}

  info "Applying patches..."
  safe patch -p1 <../../patches/dacapo_patch.patch

  safe cd benchmarks

  # See https://github.com/dacapobench/dacapobench/tree/dev-chopin "Building" section
  # for more info on how to build DaCapo
  info "Building DaCapo benchmarks..."
  safe ant

  # Ant is expected to package everything into JAR file
  # with the name that includes commit id
  local -r GENERATED_JAR_NAME="dacapo-9.12-MR1-git+6cf03808.jar"
  safe mv ${GENERATED_JAR_NAME} dacapo.jar

  # Removing these JAR files to fix an error for duplicate .class files
  safe zip -d dacapo.jar /jar/dacapo-digest.jar
  safe zip -d dacapo.jar /jar/xercesImpl.jar /jar/xml-apis.jar
  safe zip -d dacapo.jar /jar/derby.jar /jar/derbyclient.jar /jar/derbynet.jar /jar/derbytools.jar

  info "Copying dacapo.jar..."
  local -r LIB_DIR=${DEST_DIR}/benchmarks/benchmarks/lib
  if [[ ! -d ${LIB_DIR} ]]; then
    safe mkdir -p ${LIB_DIR}
  else
    if [[ -f ${LIB_DIR}/dacapo.jar ]]; then
      safe rm ${LIB_DIR}/dacapo.jar
    fi
  fi
  safe cp dacapo.jar ${LIB_DIR}/

  local -r DACAPO_RESOURCES_DIR=${DEST_DIR}/benchmarks/benchmarks/resources/dacapo
  if [[ -d ${DACAPO_RESOURCES_DIR} ]]; then
    safe rm -rf ${DACAPO_RESOURCES_DIR}
  fi
  safe mkdir -p ${DACAPO_RESOURCES_DIR}/dat
  safe mkdir -p ${DACAPO_RESOURCES_DIR}/cnf

  local -r DACAPO_PATCHES_DIR="../../../patches"
  #avrora
  info "Copying Avrora files..."
  safe patch bms/avrora/avrora.cnf <${DACAPO_PATCHES_DIR}/avrora_conf.patch
  safe cp bms/avrora/dist/dat/* ${DACAPO_RESOURCES_DIR}/dat/
  safe cp bms/avrora/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/

  #h2
  info "Copying H2 files..."
  safe patch bms/h2/h2.cnf <${DACAPO_PATCHES_DIR}/h2_conf.patch
  safe cp bms/h2/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/

  #xalan
  info "Copying Xalan files..."
  safe patch bms/xalan/xalan.cnf <${DACAPO_PATCHES_DIR}/xalan_conf.patch
  safe cp bms/xalan/dist/dat/* ${DACAPO_RESOURCES_DIR}/dat/
  safe cp bms/xalan/*.cnf ${DACAPO_RESOURCES_DIR}/cnf/
}

main "$@"