From 060ce610309a64349eb1b2245b21cf8dd48172a9 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 1 Sep 2017 11:16:09 -0400 Subject: [PATCH] Fix ./build's targets interpretation & other improvements. --- platform-darwin/Scripts/build_libjson-c-ios | 4 ++-- platform-darwin/Scripts/build_libjson-c-osx | 2 +- platform-darwin/Scripts/build_libsodium-ios | 4 ++-- platform-darwin/Scripts/build_libsodium-osx | 2 +- platform-independent/cli-c/build | 4 +++- platform-independent/cli-c/cli/mpw-cli-util.c | 6 +++--- platform-independent/cli-c/cli/mpw-cli.c | 11 +++-------- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/platform-darwin/Scripts/build_libjson-c-ios b/platform-darwin/Scripts/build_libjson-c-ios index 56d17c03..24f79ee8 100755 --- a/platform-darwin/Scripts/build_libjson-c-ios +++ b/platform-darwin/Scripts/build_libjson-c-ios @@ -2,7 +2,7 @@ set -e cd "${BASH_SOURCE%/*}/../External/libjson-c" -[[ -d libjson-c-ios ]] && exit +[[ -e "${prefix=$PWD/libjson-c-ios}/lib/libjson-c.a" ]] && exit # Prepare autoreconf -Iautoconf-archive/m4 --verbose --install --symlink 2>&1 | sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /' @@ -72,6 +72,7 @@ mkdir -p "$prefix/lib" \ ) # Merge Binaries +mv -f -- "$prefix_arm64/include" "$prefix/" lipo -create \ "$prefix_i386/lib/libjson-c.a" \ "$prefix_x86_64/lib/libjson-c.a" \ @@ -79,7 +80,6 @@ lipo -create \ "$prefix_armv7s/lib/libjson-c.a" \ "$prefix_arm64/lib/libjson-c.a" \ -output "$prefix/lib/libjson-c.a" -mv -f -- "$prefix_arm64/include" "$prefix/" # Cleanup rm -rf -- "$prefix/tmp" diff --git a/platform-darwin/Scripts/build_libjson-c-osx b/platform-darwin/Scripts/build_libjson-c-osx index 79f2728d..406d3ae1 100755 --- a/platform-darwin/Scripts/build_libjson-c-osx +++ b/platform-darwin/Scripts/build_libjson-c-osx @@ -2,7 +2,7 @@ set -e cd "${BASH_SOURCE%/*}/../External/libjson-c" -[[ -d libjson-c-osx ]] && exit +[[ -e "${prefix=$PWD/libjson-c-osx}/lib/libjson-c.a" ]] && exit # Prepare autoreconf -Iautoconf-archive/m4 --verbose --install --symlink 2>&1 | sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /' diff --git a/platform-darwin/Scripts/build_libsodium-ios b/platform-darwin/Scripts/build_libsodium-ios index 026ce4dd..f97ee7b4 100755 --- a/platform-darwin/Scripts/build_libsodium-ios +++ b/platform-darwin/Scripts/build_libsodium-ios @@ -2,7 +2,7 @@ set -e cd "${BASH_SOURCE%/*}/../External/libsodium" -[[ -d libsodium-ios ]] && exit +[[ -e "${prefix=$PWD/libsodium-ios}/lib/libsodium.a" ]] && exit # Prepare autoreconf --verbose --install --symlink 2>&1 | sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /' @@ -72,6 +72,7 @@ mkdir -p "$prefix/lib" \ ) # Merge Binaries +mv -f -- "$prefix_arm64/include" "$prefix/" lipo -create \ "$prefix_i386/lib/libsodium.a" \ "$prefix_x86_64/lib/libsodium.a" \ @@ -79,7 +80,6 @@ lipo -create \ "$prefix_armv7s/lib/libsodium.a" \ "$prefix_arm64/lib/libsodium.a" \ -output "$prefix/lib/libsodium.a" -mv -f -- "$prefix_arm64/include" "$prefix/" # Cleanup rm -rf -- "$prefix/tmp" diff --git a/platform-darwin/Scripts/build_libsodium-osx b/platform-darwin/Scripts/build_libsodium-osx index 2d62ab56..a30dd39f 100755 --- a/platform-darwin/Scripts/build_libsodium-osx +++ b/platform-darwin/Scripts/build_libsodium-osx @@ -2,7 +2,7 @@ set -e cd "${BASH_SOURCE%/*}/../External/libsodium" -[[ -d libsodium-osx ]] && exit +[[ -e "${prefix=$PWD/libsodium-osx}/lib/libsodium.a" ]] && exit # Inspired by libsodium/dist-build/osx.sh # Prepare diff --git a/platform-independent/cli-c/build b/platform-independent/cli-c/build index f7bb4064..220679e2 100755 --- a/platform-independent/cli-c/build +++ b/platform-independent/cli-c/build @@ -197,7 +197,9 @@ use_mpw_xml() { ### BUILD TARGETS for target in "${targets_all[@]}"; do - if [[ ${targets:-$targets_default} == 'all' || " $target " = *" ${targets:-$targets_default} "* ]]; then + echo "target: $target in ' $targets '." + + if [[ ${targets:-$targets_default} == 'all' || " ${targets:-$targets_default} " = *" $target "* ]]; then echo echo "Building target: $target..." ( "$target" "$@" ) diff --git a/platform-independent/cli-c/cli/mpw-cli-util.c b/platform-independent/cli-c/cli/mpw-cli-util.c index b67a7010..3f5345d0 100644 --- a/platform-independent/cli-c/cli/mpw-cli-util.c +++ b/platform-independent/cli-c/cli/mpw-cli-util.c @@ -213,7 +213,7 @@ bool mpw_mkdirs(const char *filePath) { } /** Read until EOF from the given file descriptor. - * @return A newly allocated string or NULL the read buffer couldn't be allocated. */ + * @return A newly allocated string or NULL if the read buffer couldn't be allocated or an error occurred. */ char *mpw_read_fd(int fd) { char *buf = NULL; @@ -222,13 +222,13 @@ char *mpw_read_fd(int fd) { while ((mpw_realloc( &buf, &bufSize, blockSize )) && ((readSize = read( fd, buf + bufOffset, blockSize )) > 0)); if (readSize == ERR) - dbg( "While reading: %s\n", strerror( errno ) ); + mpw_free( &buf, bufSize ); return buf; } /** Read the file contents of a given file. - * @return A newly allocated string or NULL the read buffer couldn't be allocated. */ + * @return A newly allocated string or NULL if the read buffer couldn't be allocated. */ char *mpw_read_file(FILE *file) { if (!file) diff --git a/platform-independent/cli-c/cli/mpw-cli.c b/platform-independent/cli-c/cli/mpw-cli.c index 60b8e55c..80d50cf4 100644 --- a/platform-independent/cli-c/cli/mpw-cli.c +++ b/platform-independent/cli-c/cli/mpw-cli.c @@ -203,14 +203,9 @@ int main(const int argc, char *const argv[]) { return EX_DATAERR; } if ((!masterPassword || !strlen( masterPassword )) && masterPasswordFDArg) { - FILE *masterPasswordFile = fdopen( atoi( masterPasswordFDArg ), "r" ); - if (!masterPasswordFile) - wrn( "Error opening master password FD %s: %s\n", masterPasswordFDArg, strerror( errno ) ); - else { - masterPassword = mpw_read_file( masterPasswordFile ); - if (ferror( masterPasswordFile )) - wrn( "Error reading master password from %s: %d\n", masterPasswordFDArg, ferror( masterPasswordFile ) ); - } + masterPassword = mpw_read_fd( atoi( masterPasswordFDArg ) ); + if (!masterPassword && errno) + wrn( "Error reading master password from FD %s: %s\n", masterPasswordFDArg, strerror( errno ) ); } if ((!masterPassword || !strlen( masterPassword )) && masterPasswordArg) masterPassword = strdup( masterPasswordArg );