File: target-libraries-do-not-have-bitcode.test-sh

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (129 lines) | stat: -rwxr-xr-x 4,023 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
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
#!/usr/bin/env bash

# This test makes sure that if lto is enabled and bitcode is not that no runtime
# libraries contain bitcode. We do not support this now.
#
# *NOTE* This will not trigger for embedded bitcode sections since to file these
# are still mach-o files and come up as such.

# REQUIRES: lto
# REQUIRES: OS=macosx
# RUN: %s %swift_obj_root %t

set -u
set -e
set -o pipefail

function check_thin_archive_for_bitcode() {
    set -u
    set -e

    pushd . 1>/dev/null

    local BASE_TEMPDIR=$1
    local ARCHIVE=$2

    local LIB_NAME
    LIB_NAME=$(basename ${ARCHIVE})
    local LIB_ARCH
    LIB_ARCH=$(basename $(dirname ${ARCHIVE}))
    local LIB_PLATFORM
    LIB_PLATFORM=$(basename $(dirname $(dirname ${ARCHIVE})))

    LIB_TEMP_DIR="${BASE_TEMPDIR}/${LIB_PLATFORM}-${LIB_ARCH}-${LIB_NAME}"
    mkdir -p "${LIB_TEMP_DIR}"
    cd "${LIB_TEMP_DIR}"
    ar -x ${ARCHIVE}
    if find ./ -iname '*.o' -exec file {} \; | grep -q -e bitcode -e bit-code; then
        echo "Found bitcode file in thin archive: ${ARCHIVE}"
        exit 1
    else
        echo "No bitcode in thin archive: ${ARCHIVE}"
    fi
    popd 1>/dev/null
    set +e
    set +u
}
export -f check_thin_archive_for_bitcode

function check_thick_archive_for_bitcode() {
    set -u
    set -e

    pushd . 1>/dev/null

    local BASE_TEMPDIR=$1
    local ARCHIVE=$2

    local LIB_NAME
    LIB_NAME=$(basename ${ARCHIVE})
    local LIB_PLATFORM
    LIB_PLATFORM=$(basename $(dirname ${ARCHIVE}))

    LIB_TEMP_DIR="${BASE_TEMPDIR}/${LIB_PLATFORM}-thick-${LIB_NAME}"
    LIB_ARCHIVE_DIR="${LIB_TEMP_DIR}/archive"
    LIB_OBJECT_DIR="${LIB_TEMP_DIR}/object"

    mkdir -p "${LIB_TEMP_DIR}"
    mkdir -p "${LIB_ARCHIVE_DIR}"
    mkdir -p "${LIB_OBJECT_DIR}"

    ARCHS=( $(lipo -info ${ARCHIVE} | cut -f 3 -d ":" ) )
    cd ${LIB_OBJECT_DIR}
    for arch in "${ARCHS[@]}"; do
        pushd . 1>/dev/null
        local THIN_ARCHIVE="${LIB_NAME}.${arch}"
        lipo -thin "${arch}" -output "${LIB_ARCHIVE_DIR}/${THIN_ARCHIVE}" "${ARCHIVE}"
        mkdir ${arch}
        cd ${arch}
        ar -x "${LIB_ARCHIVE_DIR}/${THIN_ARCHIVE}"

        if find ./ -iname '*.o' -exec file {} \; | grep -q -e bitcode -e bit-code; then
            echo "Found bitcode file in thin archive: ${THIN_ARCHIVE}. Taken from thick archive: ${ARCHIVE}"
            exit 1
        else
            echo "No bitcode in thin archive: ${THIN_ARCHIVE}. Taken from thick archive: ${ARCHIVE}"
        fi

        popd 1>/dev/null
    done
    popd 1>/dev/null

    set +e
    set +u
}
export -f check_thick_archive_for_bitcode

# Make sure we have an absolute path to the OBJROOT. It makes code below
# simpler.
OBJROOT=$(cd ${1} && pwd)
TEMPDIR=${2}

rm -rf $TEMPDIR
mkdir -p $TEMPDIR

# *NOTE* We do not find directly in ./lib/swift_static since we want to not fail
# in the case where we are not building a static standard library and thus
# ./lib/swift_static is not created.
THIN_ARCHIVES=( \
    $(find ${OBJROOT}/lib/swift -iname '*.a' -exec lipo -info {} \; | grep "Non-fat file" | cut -f 3 -d " ") \
    $(find ${OBJROOT}/lib -iname '*.a' -path "*swift_static*" -exec lipo -info {} \; | grep "Non-fat file" | cut -f 3 -d " ") \
)
if [[ ${#THIN_ARCHIVES[@]} -gt 0 ]]; then
    echo "${THIN_ARCHIVES[@]}" | xargs -n 1 -P 8 bash -c "check_thin_archive_for_bitcode \"${TEMPDIR}\" \${1}" --
fi

# *NOTE* We do not find directly in ./lib/swift_static since we want to not fail
# in the case where we are not building a static standard library and thus
# ./lib/swift_static is not created.
THICK_ARCHIVES=( \
   $(find ${OBJROOT}/lib/swift -iname '*.a' -exec lipo -info {} \; | grep "Architectures in the fat file" | cut -f 6 -d " ") \
   $(find ${OBJROOT}/lib -iname '*.a' -path "*swift_static*" -exec lipo -info {} \; | grep "Architectures in the fat file" | cut -f 6 -d " ") \
)
if [[ ${#THICK_ARCHIVES[@]} -gt 0 ]]; then
    echo "${THICK_ARCHIVES[@]}" | xargs -n 1 -P 8 bash -c "check_thick_archive_for_bitcode \"${TEMPDIR}\" \${1}" --
fi

set +o pipefail
set +e
set +u