diff --git a/BuildServiceShim/BUILD b/BuildServiceShim/BUILD index 8dd01a0..603dee9 100644 --- a/BuildServiceShim/BUILD +++ b/BuildServiceShim/BUILD @@ -5,8 +5,13 @@ cc_binary( srcs = ["main.c"], ) +sh_library( + name = "BuildServiceShim_deps", + data = ["stub.sh"], +) + sh_binary( name = "BuildServiceShim", srcs = [":main"], - data = glob(["*.sh"]), + deps = [":BuildServiceShim_deps"] ) diff --git a/BuildServiceShim/main.c b/BuildServiceShim/main.c index 5ae330b..7528692 100644 --- a/BuildServiceShim/main.c +++ b/BuildServiceShim/main.c @@ -1,7 +1,15 @@ #include int main(int ac, char** av) { - // Run a bash script "stub" adjacent to the binary - system("/bin/bash -c \"$(dirname $XCBBUILDSERVICE_PATH)/BuildServiceShim.runfiles/__main__/BuildServiceShim/stub.sh\""); - return 0; + // FIXME: not good assumptions: + // - the BUILDSERVICE_PATH ( self ) is deep in bazel-out + // https://github.com/jerrymarino/xcbuildkit/issues/36 + int st = system("/bin/bash -c \"$(dirname $(dirname $(dirname $XCBBUILDSERVICE_PATH)))/BuildServiceShim/stub.sh\""); + + // This atleast crashes it if its wrong + if (WEXITSTATUS(st) == 0x10) { + return 0; + } else { + return 1; + } } diff --git a/BuildServiceShim/stub.sh b/BuildServiceShim/stub.sh index 1f7bb8e..d49416e 100755 --- a/BuildServiceShim/stub.sh +++ b/BuildServiceShim/stub.sh @@ -1,12 +1,6 @@ #!/bin/bash -# The service is adjacent to this program -# The layer of indirection is useful for debugging and not -# a production component -SERVICE="$(dirname $(dirname $XCBBUILDSERVICE_PATH))/BazelBuildService_app_dir/BazelBuildService.app/Contents/MacOS/BazelBuildService" - function redirect() { - #tee >($SERVICE) /tmp/xcbuild.out /usr/bin/env - XCBUILD_TRACING_URL=/tmp/xcbuild.trace TERM="${TERM}" SHELL="${SHELL}" PATH="${PATH}" HOME="${HOME}" \ tee /tmp/xcbuild.in | \ $XCODE/Contents/SharedFrameworks/XCBuild.framework/PlugIns/XCBBuildService.bundle/Contents/MacOS/XCBBuildService | \ @@ -14,13 +8,15 @@ function redirect() { } function replace() { + local SERVICE="$DEBUG_BUILDSERVICE_PATH" /usr/bin/env - TERM="${TERM}" SHELL="${SHELL}" PATH="${PATH}" HOME="${HOME}" \ tee /tmp/xcbuild.in | $SERVICE | tee /tmp/xcbuild.out } -# This simply redirects stdin and stdout of Xcode's build service -if [[ "${BUILD_SERVICE_REDIRECT:-false}" == "true" ]]; then - redirect -else +if [[ -n "$DEBUG_BUILDSERVICE_PATH" ]]; then + echo "[stub.sh] Replacing ($DEBUG_BUILDSERVICE_PATH)" >> /tmp/xcbuild.log replace +else + echo "[stub.sh] Shimming" >> /tmp/xcbuild.log + redirect fi