Improve handling of build failure/cancellation for tests

Previously if `bazel_build.py` was interrupted while it was trying
to acquire the file lock, we would exit with an uncaught
`KeyboardInterrupt` exception which Xcode would show to the user.

That behavior isn't great since it will likely hide the actual error
from the user (e.g. if targets are building in parallel and one of
them fails, Xcode will interrupt us).

PiperOrigin-RevId: 308318638
diff --git a/src/TulsiGenerator/Scripts/bazel_build.py b/src/TulsiGenerator/Scripts/bazel_build.py
index ef398f4..8263732 100755
--- a/src/TulsiGenerator/Scripts/bazel_build.py
+++ b/src/TulsiGenerator/Scripts/bazel_build.py
@@ -1706,13 +1706,15 @@
 
 
 if __name__ == '__main__':
+  # Register the interrupt handler immediately in case we receive SIGINT while
+  # trying to acquire the lock.
+  signal.signal(signal.SIGINT, _InterruptHandler)
   _LockFileAcquire(_LockFileCreate())
   _logger = tulsi_logging.Logger()
   logger_warning = tulsi_logging.validity_check()
   if logger_warning:
     _PrintXcodeWarning(logger_warning)
   _timer = Timer('Everything', 'complete_build').Start()
-  signal.signal(signal.SIGINT, _InterruptHandler)
   _exit_code = main(sys.argv)
   _timer.End()
   sys.exit(_exit_code)