Bug 1441336 - Use addon permissions for PerformanceTiming properties r=bz,kmag
[gecko.git] / testing / geckodriver / build.sh
blob8bf54e98239dfca75266d87a3eaa56893de3a9db
1 set -ex
3 print_versions() {
4 rustc -V
5 cargo -V
6 cc --version
9 rustup_install() {
10 export PATH="$PATH:$HOME/.cargo/bin"
11 curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$1
14 # Add provided target to current Rust toolchain if it is not already
15 # the default or installed.
16 rustup_target_add() {
17 if ! rustup target list | grep -E "$1 \((default|installed)\)"
18 then
19 rustup target add $1
23 setup_docker() {
24 apt-get -qq -y install zip
25 cd /mnt/host
28 mingw_i686_install() {
29 curl https://static.rust-lang.org/dist/rust-mingw-nightly-i686-pc-windows-gnu.tar.gz \
30 | tar xzvf - -C /tmp
31 /tmp/rust-mingw-nightly-i686-pc-windows-gnu/install.sh --prefix=`rustc --print sysroot`
34 # Configure rustc target for cross compilation. Provided with a build
35 # target, this will determine which linker to use for cross compilation.
36 cargo_config() {
37 local prefix
39 case "$TARGET" in
40 aarch64-unknown-linux-gnu)
41 prefix=aarch64-linux-gnu
43 arm*-unknown-linux-gnueabihf)
44 prefix=arm-linux-gnueabihf
46 arm-unknown-linux-gnueabi)
47 prefix=arm-linux-gnueabi
49 mipsel-unknown-linux-musl)
50 prefix=mipsel-openwrt-linux
52 x86_64-pc-windows-gnu)
53 prefix=x86_64-w64-mingw32
55 i686-pc-windows-gnu)
56 prefix=i686-w64-mingw32
59 return
61 esac
63 mkdir -p ~/.cargo
64 cat >~/.cargo/config <<EOF
65 [target.$TARGET]
66 linker = "$prefix-gcc"
67 EOF
69 cat ~/.cargo/config
72 # Build current crate for given target and print file type information.
73 # If the second argument is set, a release build will be made.
74 cargo_build() {
75 local mode
76 if [ -z "$2" ]
77 then
78 mode=debug
79 else
80 mode=release
83 local modeflag
84 if [ "$mode" == "release" ]
85 then
86 modeflag=--release
89 cargo build --target $1 $modeflag
91 file $(get_binary $1 $mode)
94 # Run current crate's tests if the current system supports it.
95 cargo_test() {
96 if echo "$1" | grep -E "(i686|x86_64)-unknown-linux-(gnu|musl)|darwin"
97 then
98 cargo test --target $1
102 # Returns relative path to binary
103 # based on build target and type ("release"/"debug").
104 get_binary() {
105 local ext
106 if [[ "$1" =~ "windows" ]]
107 then
108 ext=".exe"
110 echo "target/$1/$2/geckodriver$ext"
113 # Create a compressed archive of the binary
114 # for the given given git tag, build target, and build type.
115 package_binary() {
116 local bin
117 bin=$(get_binary $2 $4)
118 cp $bin .
120 if [[ "$2" =~ "windows" ]]
121 then
122 filename="geckodriver-$1-$3.zip"
123 zip "$filename" geckodriver.exe
124 file "$filename"
125 else
126 filename="geckodriver-$1-$3.tar.gz"
127 tar zcvf "$filename" geckodriver
128 file "$filename"
130 if [ ! -z "$DOCKER_IMAGE" ]
131 then
132 chown "$USER_ID:$GROUP_ID" "$filename"
136 main() {
137 TOOLCHAIN=${TOOLCHAIN:=stable}
139 if [ ! -z "$DOCKER_IMAGE" ]
140 then
141 setup_docker
144 rustup_install $TOOLCHAIN
145 print_versions
146 rustup_target_add $TARGET
148 # custom mingw component required
149 # when compiling on 32-bit windows
150 # see https://github.com/mozilla/geckodriver/pull/138#issuecomment-232139097
151 if [[ $TARGET == "i686-pc-windows-gnu" ]]
152 then
153 mingw_i686_install
156 cargo_config $TARGET
157 cargo_build $TARGET
158 cargo_test $TARGET
160 # when something is tagged,
161 # also create a release build and package it
162 if [ ! -z "$TRAVIS_TAG" ]
163 then
164 cargo_build $TARGET 1
165 package_binary $TRAVIS_TAG $TARGET $NAME "release"
169 main