Repository navigation
Conversation
…UT=1. When Briefcase launches an app on a physical iOS device, it streams the process console with `devicectl --console`. Python's stdout and stderr go to the Apple system log, so print() output never reached that console. If BRIEFCASE_CONSOLE_OUTPUT=1 is set in the environment, the launcher now leaves config.use_system_logger disabled on Python 3.14+, and on Python 3.13 and earlier restores sys.stdout/sys.stderr to the original streams on file descriptors 1 and 2 after initialization. Without the variable, behavior is unchanged. Assisted-by: Claude Code (claude-opus-5-5)
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a "console output" mode to the iOS launcher (
main.m) so Briefcase can capture Python output when it runs an app on a physical device.When Briefcase runs an app on a physical device (beeware/briefcase#860), it launches it with
xcrun devicectl device process launch --consoleand reads the process's console to detect test results and errors. Python'ssys.stdoutandsys.stderrare written to the Apple system log, though, soprint()output never shows up there; only the launcher'sNSLoglines do.The contract
If the environment variable
BRIEFCASE_CONSOLE_OUTPUTis set to1when the app launches, Python'ssys.stdoutandsys.stderrwrite to the process's real stdout and stderr (file descriptors 1 and 2) instead of the system log. Briefcase passes this in the--environment-variablesargument todevicectl. Any other value, or no value, keeps the current behavior, so simulator logging and normal launches are unaffected. In console mode the launcher logs one extra line:Python stdout and stderr will be written to the console.All existingNSLogmessages stay as they are.Implementation
config.use_system_loggeris now set to!console_outputinstead of always1._apple_support.init_streams()always replacessys.stdoutandsys.stderrwithSystemLogwrappers during startup (all three support packages ship_apple_support.py). In console mode, the launcher runs a shortPyRun_SimpleStringafterPy_InitializeFromConfigthat rebindssys.stdoutandsys.stderrtosys.__stdout__andsys.__stderr__. Those are the original UTF-8 streams on fds 1 and 2, unbuffered because ofconfig.buffered_stdio = 0. If that call fails, the crash dialog is shown and the app exits.Verification
I generated a probe app from this branch with Briefcase 0.4.7 for Python 3.13 (support b18) and 3.14, built it for the iPhone 16 simulator, and launched it with
xcrun simctl launch --console-pty. The probe printsrepr(sys.stdout)to stdout andrepr(sys.stderr)to stderr, then raisesSystemExit(0).BRIEFCASE_CONSOLE_OUTPUTlog show)NSLoglines only<SystemLog (level 0)>/<SystemLog (level 16)>1<_io.TextIOWrapper name='<stdout>' ... encoding='utf-8'>and<stderr>NSLoglines only<SystemLog (level 0)>/<SystemLog (level 16)>1<_io.TextIOWrapper name='<stdout>' ... encoding='utf-8'>and<stderr>On the simulator the variable was passed as
SIMCTL_CHILD_BRIEFCASE_CONSOLE_OUTPUT=1. I did not test Python 3.11, 3.12, or 3.15 directly: 3.11 and 3.12 use the same_apple_supportpath as 3.13, and 3.15 uses the sameuse_system_loggerpath as 3.14. I also haven't run this on a physical device yet; that will happen through the Briefcase side of #860.Refs beeware/briefcase#860
PR Checklist:
Assisted-by: Claude Code (Claude Opus 5.5)