Debian Codegraph @

crt/s2n/codebuild/bin/install_s2n_head.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License").
5 # You may not use this file except in compliance with the License.
6 # A copy of the License is located at
7 #
8 # http://aws.amazon.com/apache2.0
9 #
10 # or in the "license" file accompanying this file. This file is distributed
11 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 # express or implied. See the License for the specific language governing
13 # permissions and limitations under the License.
14
15 set -eux
16
17 usagescip-shell shell shell-project 0.0.0 usage().() {
18 echoscip-shell system . . echo. "install_s2n_head.sh build_dir"
19 exit 1
20 }
21
22 BUILD_DIR=$1
23 SRC_ROOT=${SRC_ROOT:-$(pwdscip-shell system . . pwd.)}
24
25 if [scip-shell system . . `[`. "$#" -ne "1" ]; then
26 usagescip-shell shell shell-project 0.0.0 usage().
27 fi
28
29 # CMake(nix) and Make are using different directory structures.
30 set +u
31 if [[ "$IN_NIX_SHELL" ]]; then
32 export DEST_DIR="$SRC_ROOT"/build/bin
33 export EXTRA_BUILD_FLAGS=""
34 # Work around issue cloning inside a nix devshell https://github.com/NixOS/nixpkgs/issues/299949
35 export CLONE_SRC="."
36 # Make sure main is available in our workspace.
37 # This is a workaround for the merge queue workflow.
38 gitscip-shell system . . git. fetch origin
39 gitscip-shell system . . git. checkout main
40 gitscip-shell system . . git. checkout $CODEBUILD_SOURCE_VERSION
41 else
42 export DEST_DIR="$SRC_ROOT"/bin
43 export EXTRA_BUILD_FLAGS="-DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT"
44 # Work around different pathing issues for internal rel.
45 export CLONE_SRC="https://github.com/aws/s2n-tls"
46 fi
47 set -eu
48
49 s2nc_head="$DEST_DIR/s2nc_head"
50 if [[ -f "$s2nc_head" ]]; then
51 now=$(datescip-shell system . . date. +%s)
52 last_modified=$(statscip-shell system . . stat. -c %Y "$s2nc_head")
53 days_old=$(( (now - last_modified) / 86400))
54 if ((days_old <= 1)); then
55 echoscip-shell system . . echo. "Reusing s2n_head: s2nc_head exists and is $days_old days old."
56 exit 0
57 fi
58 fi
59
60 gitscip-shell system . . git. clone --branch "main" --single-branch "$CLONE_SRC" "$BUILD_DIR"
61
62 cmakescip-shell system . . cmake. "$BUILD_DIR" -B"$BUILD_DIR"/build "$EXTRA_BUILD_FLAGS" \
63 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
64 -DBUILD_SHARED_LIBS=on \
65 -DBUILD_TESTING=on
66 cmakescip-shell system . . cmake. --build "$BUILD_DIR"/build --target s2nc -- -j $(nprocscip-shell system . . nproc.)
67 cmakescip-shell system . . cmake. --build "$BUILD_DIR"/build --target s2nd -- -j $(nprocscip-shell system . . nproc.)
68
69 cpscip-shell system . . cp. -f "$BUILD_DIR"/build/bin/s2nc "$s2nc_head"
70 cpscip-shell system . . cp. -f "$BUILD_DIR"/build/bin/s2nd "$DEST_DIR"/s2nd_head
71
72 if [[ -f "$s2nc_head" ]]; then
73 echoscip-shell system . . echo. "Successfully installed s2n?_head"
74 else
75 echoscip-shell system . . echo. "$s2nc_head not found, head build failed"
76 exit 255
77 fi
78
79 exit 0