File: install_s2n_head.sh

package info (click to toggle)
aws-crt-python 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 75,932 kB
  • sloc: ansic: 418,984; python: 23,626; makefile: 6,035; sh: 4,075; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (67 lines) | stat: -rwxr-xr-x 2,042 bytes parent folder | download
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
#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. 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.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file 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.

set -eu

usage() {
    echo "install_s2n_head.sh build_dir"
    exit 1
}

BUILD_DIR=$1
SRC_ROOT=${SRC_ROOT:-$(pwd)}

if [ "$#" -ne "1" ]; then
    usage
fi

# CMake(nix) and Make are using different directory structures.
set +u
if [[ "$IN_NIX_SHELL" ]]; then
    export DEST_DIR="$SRC_ROOT"/build/bin
    export EXTRA_BUILD_FLAGS=""
    # Work around issue cloning inside a nix devshell https://github.com/NixOS/nixpkgs/issues/299949 
    export CLONE_SRC="."
else
    export DEST_DIR="$SRC_ROOT"/bin
    export EXTRA_BUILD_FLAGS="-DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT"
    # Work around different pathing issues for internal rel.
    export CLONE_SRC="https://github.com/aws/s2n-tls"
fi
set -u

s2nc_head="$DEST_DIR/s2nc_head"
if [[ -f "$s2nc_head" ]]; then
    now=$(date +%s)
    last_modified=$(stat -c %Y "$s2nc_head")
    days_old=$(( (now - last_modified) / 86400))
    if ((days_old <= 1)); then
        echo "Reusing s2n_head: s2nc_head exists and is $days_old days old."
        exit 0
    fi
fi

git clone --branch main --single-branch "$CLONE_SRC" "$BUILD_DIR"

cmake "$BUILD_DIR" -B"$BUILD_DIR"/build "$EXTRA_BUILD_FLAGS" \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DBUILD_SHARED_LIBS=on \
    -DBUILD_TESTING=on
cmake --build "$BUILD_DIR"/build --target s2nc -- -j $(nproc) 
cmake --build "$BUILD_DIR"/build --target s2nd -- -j $(nproc) 

cp -f "$BUILD_DIR"/build/bin/s2nc "$s2nc_head"
cp -f "$BUILD_DIR"/build/bin/s2nd "$DEST_DIR"/s2nd_head

exit 0