Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/entrypoint_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ For more details: https://github.com/jake-dev-99/quicktype_dart
/// previous subscription before attaching a new one.
static void _installLogForwarder() {
Logger.root.level = Level.INFO;
_logSubscription?.cancel();
// Fire-and-forget: cancel() stops delivering records synchronously;
// the Future it returns just signals completion of any async cleanup,
// which doesn't block attaching the next listener.
unawaited(_logSubscription?.cancel());
// Subscription lives for the process lifetime (CLI is a short-lived
Comment thread
jake-dev-99 marked this conversation as resolved.
Resolved
// binary); test re-entries cancel it via the unawaited() above.
// cancel_subscriptions fires on the .listen() site, not the field,
// so the ignore belongs here.
// ignore: cancel_subscriptions
_logSubscription = Logger.root.onRecord.listen((record) {
// Process stdout/stderr are owned by the runtime; never close them.
if (record.level >= Level.WARNING) {
Expand All @@ -151,8 +159,5 @@ For more details: https://github.com/jake-dev-99/quicktype_dart
});
}

// ignore: cancel_subscriptions
// Subscription lives for the process lifetime; cancellation happens
// on re-entry (tests) via _installLogForwarder above.
static StreamSubscription<LogRecord>? _logSubscription;
}
31 changes: 25 additions & 6 deletions native/shim/embed_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
const unsigned char qt_bundle_js[] — bundle bytes + trailing NUL
const unsigned long qt_bundle_js_len — bundle length
"""
import io
import os
import sys

# Characters that must not appear raw inside a C string literal.
Expand Down Expand Up @@ -74,18 +76,35 @@ def main():
print(__doc__, file=sys.stderr)
sys.exit(1)
prelude, bundle, out_path = sys.argv[1:]

# Buffer everything into memory first so a read failure on `prelude`
# or `bundle` (or a disk-full during emit) doesn't truncate the
# existing out_path. The atomic rename at the end guarantees
# consumers either see the complete old file or the complete new
# file — never a half-written one.
buf = io.BytesIO()
buf.write(b'// Auto-generated by embed_bundle.py \xe2\x80\x94 do not edit.\n\n')
emit(prelude, 'qt_prelude_js', buf)
emit(bundle, 'qt_bundle_js', buf)

tmp_path = f'{out_path}.tmp-{os.getpid()}'
try:
out = open(out_path, 'wb')
with open(tmp_path, 'wb') as tmp:
tmp.write(buf.getvalue())
tmp.flush()
os.fsync(tmp.fileno())
os.replace(tmp_path, out_path)
except OSError as e:
print(
f'embed_bundle.py: cannot open output {out_path} for writing: {e}',
f'embed_bundle.py: cannot write output {out_path}: {e}',
file=sys.stderr,
)
if os.path.exists(tmp_path):
try:
os.unlink(tmp_path)
except OSError:
pass
sys.exit(2)
with out:
out.write(b'// Auto-generated by embed_bundle.py \xe2\x80\x94 do not edit.\n\n')
emit(prelude, 'qt_prelude_js', out)
emit(bundle, 'qt_bundle_js', out)


if __name__ == '__main__':
Expand Down
Loading