Skip to content

Commit

Permalink
Fix debugging issues
Browse files Browse the repository at this point in the history
#36
A stopgap for ^
  • Loading branch information
jerrymarino committed Aug 3, 2022
1 parent 2832146 commit 5e96708
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
7 changes: 6 additions & 1 deletion BuildServiceShim/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
14 changes: 11 additions & 3 deletions BuildServiceShim/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include <stdlib.h>

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;
}
}
16 changes: 6 additions & 10 deletions BuildServiceShim/stub.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#!/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 | \
tee /tmp/xcbuild.out
}

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

0 comments on commit 5e96708

Please sign in to comment.