Skip to content

Commit

Permalink
Improved tor.sh build script stability: Ensure, the project is config…
Browse files Browse the repository at this point in the history
…ured before calling `make show-libs`. Ensure, project gets rebuilt, when configure script was missing. (Most probably because of update!)
  • Loading branch information
tladesignz committed Apr 16, 2020
1 parent fd9ff0d commit 8881bfb
Showing 1 changed file with 51 additions and 29 deletions.
80 changes: 51 additions & 29 deletions Tor/tor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,58 @@

ARCHS=($ARCHS)

# We need gettext to build tor
# This extends the path to look in some common locations (for example, if installed via Homebrew)
# We need gettext to build Tor.
# This extends the path to look in some common locations (for example, if installed via Homebrew).
PATH=$PATH:/usr/local/bin:/usr/local/opt/gettext/bin:/usr/local/opt/automake/bin:/usr/local/opt/aclocal/bin

# Disable PT_DENY_ATTACH because it is private API.
PSEUDO_SYS_INCLUDE_DIR="${CONFIGURATION_TEMP_DIR}/tor-sys"
mkdir -p "${PSEUDO_SYS_INCLUDE_DIR}/sys"
touch "${PSEUDO_SYS_INCLUDE_DIR}/sys/ptrace.h"

if [[ "${BITCODE_GENERATION_MODE}" = "bitcode" ]]; then
BITCODE_CFLAGS="-fembed-bitcode"
elif [[ "${BITCODE_GENERATION_MODE}" = "marker" ]]; then
BITCODE_CFLAGS="-fembed-bitcode-marker"
fi

if [[ "${CONFIGURATION}" = "Debug" ]]; then
DEBUG_CFLAGS="-g -O0"
fi

mkdir -p "${BUILT_PRODUCTS_DIR}"

LAST_CONFIGURED_ARCH=

function configure {
ARCH=$1

# Don't re-run, if we already configured this architecture recently.
if [[ $LAST_CONFIGURED_ARCH = $ARCH ]]; then
return
fi

./configure --enable-restart-debugging --enable-silent-rules --enable-pic --disable-module-dirauth --disable-tool-name-check --disable-unittests --enable-static-openssl --enable-static-libevent --disable-asciidoc --disable-system-torrc --disable-linker-hardening --disable-dependency-tracking --disable-manpage --disable-html-manual --prefix="${CONFIGURATION_TEMP_DIR}/tor-${ARCH}" --with-libevent-dir="${BUILT_PRODUCTS_DIR}" --with-openssl-dir="${BUILT_PRODUCTS_DIR}" --enable-lzma --enable-zstd=no CC="$(xcrun -f --sdk ${PLATFORM_NAME} clang) -arch ${ARCH} -isysroot ${SDKROOT}" CPP="$(xcrun -f --sdk ${PLATFORM_NAME} clang) -E -arch ${ARCH} -isysroot ${SDKROOT}" CPPFLAGS="${DEBUG_CFLAGS} ${BITCODE_CFLAGS} -I${SRCROOT}/Tor/tor/core -I${SRCROOT}/Tor/openssl/include -I${BUILT_PRODUCTS_DIR}/openssl-${ARCH} -I${SRCROOT}/Tor/libevent/include -I${BUILT_PRODUCTS_DIR}/libevent-${ARCH} -I${BUILT_PRODUCTS_DIR}/libevent-${ARCH}/include -I${BUILT_PRODUCTS_DIR}/liblzma-${ARCH} -I${BUILT_PRODUCTS_DIR}/liblzma-${ARCH}/include -I${PSEUDO_SYS_INCLUDE_DIR} -isysroot ${SDKROOT}" cross_compiling="yes" ac_cv_func__NSGetEnviron="no" ac_cv_func_clock_gettime="no" ac_cv_func_getentropy="no" LDFLAGS="-lz ${BITCODE_CFLAGS}"

LAST_CONFIGURED_ARCH=$ARCH
}

REBUILD=0

# Generate the configure script (necessary for version control distributions)
if [[ ! -f ./configure ]]; then
./autogen.sh --add-missing
fi

REBUILD=0
# make show-libs needs a full configure, otherwise it will trigger that and return a lot of garbage.
configure ${ARCHS[0]}

declare -a LIBS=(`make show-libs`)
REBUILD=1
fi

declare -a LIBS=$(make show-libs)
echo "LIBRARIES: ${LIBS[@]}"

# If the built binaries include a different set of architectures, then rebuild the target
# If the built binaries include a different set of architectures, then rebuild the target.
if [[ ${ACTION:-build} = "build" ]] || [[ $ACTION = "install" ]]; then
for LIB in ${LIBS[@]}
do
Expand All @@ -29,48 +66,32 @@ if [[ ${ACTION:-build} = "build" ]] || [[ $ACTION = "install" ]]; then
done
fi

# If rebuilding or cleaning then delete the built products
# If rebuilding or cleaning then delete the built products.
if [[ ${ACTION:-build} = "clean" ]] || [[ $REBUILD = 1 ]]; then
make clean 2>/dev/null
make clean 2> /dev/null
for LIB in ${LIBS[@]}
do
rm "${BUILT_PRODUCTS_DIR}/$(basename $LIB)" 2> /dev/null
done
fi

if [[ $REBUILD = 0 ]]; then
# If cleaning or no rebuild, we're done.
if [[ ${ACTION:-build} = "clean" ]] || [[ $REBUILD = 0 ]]; then
exit;
fi

# Disable PT_DENY_ATTACH because it is private API
PSEUDO_SYS_INCLUDE_DIR="${CONFIGURATION_TEMP_DIR}/tor-sys"
mkdir -p "${PSEUDO_SYS_INCLUDE_DIR}/sys"
touch "${PSEUDO_SYS_INCLUDE_DIR}/sys/ptrace.h"

if [[ "${BITCODE_GENERATION_MODE}" = "bitcode" ]]; then
BITCODE_CFLAGS="-fembed-bitcode"
elif [[ "${BITCODE_GENERATION_MODE}" = "marker" ]]; then
BITCODE_CFLAGS="-fembed-bitcode-marker"
fi

if [[ "${CONFIGURATION}" = "Debug" ]]; then
DEBUG_CFLAGS="-g -O0"
fi

mkdir -p "${BUILT_PRODUCTS_DIR}"

# Build each architecture one by one using clang
# Build each architecture one by one using clang.
for ARCH in ${ARCHS[@]}
do
make clean

./configure --enable-restart-debugging --enable-silent-rules --enable-pic --disable-module-dirauth --disable-tool-name-check --disable-unittests --enable-static-openssl --enable-static-libevent --disable-asciidoc --disable-system-torrc --disable-linker-hardening --disable-dependency-tracking --disable-manpage --disable-html-manual --prefix="${CONFIGURATION_TEMP_DIR}/tor-${ARCH}" --with-libevent-dir="${BUILT_PRODUCTS_DIR}" --with-openssl-dir="${BUILT_PRODUCTS_DIR}" --enable-lzma --enable-zstd=no CC="$(xcrun -f --sdk ${PLATFORM_NAME} clang) -arch ${ARCH} -isysroot ${SDKROOT}" CPP="$(xcrun -f --sdk ${PLATFORM_NAME} clang) -E -arch ${ARCH} -isysroot ${SDKROOT}" CPPFLAGS="${DEBUG_CFLAGS} ${BITCODE_CFLAGS} -I${SRCROOT}/Tor/tor/core -I${SRCROOT}/Tor/openssl/include -I${BUILT_PRODUCTS_DIR}/openssl-${ARCH} -I${SRCROOT}/Tor/libevent/include -I${BUILT_PRODUCTS_DIR}/libevent-${ARCH} -I${BUILT_PRODUCTS_DIR}/libevent-${ARCH}/include -I${BUILT_PRODUCTS_DIR}/liblzma-${ARCH} -I${BUILT_PRODUCTS_DIR}/liblzma-${ARCH}/include -I${PSEUDO_SYS_INCLUDE_DIR} -isysroot ${SDKROOT}" cross_compiling="yes" ac_cv_func__NSGetEnviron="no" ac_cv_func_clock_gettime="no" ac_cv_func_getentropy="no" LDFLAGS="-lz ${BITCODE_CFLAGS}"
configure $ARCH

# There seems to be a race condition with the above configure and the later cp.
# Just sleep a little so the correct file is copied and delete the old one before.
sleep 2s
rm src/lib/cc/orconfig.h

cp orconfig.h "src/lib/cc/"

make -j$(sysctl hw.ncpu | awk '{print $2}')
Expand All @@ -81,10 +102,11 @@ do
do
cp $LIB "${BUILT_PRODUCTS_DIR}/$(basename $LIB).${ARCH}.a"
done

make clean
done

# Combine the built products into a fat binary
# Combine the built products into a fat binary.
for LIB in ${LIBS[@]}
do
FILENAME=$(basename $LIB)
Expand Down

0 comments on commit 8881bfb

Please sign in to comment.