Skip to content

Commit e514bec

Browse files
authored
Use coreutils to force-enable line buffering instead of depending on VM (#1771)
* GNU coreutils force-enabling line buffering instead of depending on VM to do buffering right * remove debugging and wrong show-progress * core dumps on * pub get in script? * skip install on macos * syntax error fix * travis * fix syntax * Remove if statement * Fix up travis hack for better usefulness for dartdoc, and disable the hack on macos * Make install_travis not return non-zero
1 parent 7cef552 commit e514bec

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ os:
1414
- osx
1515
- linux
1616

17+
18+
install:
19+
- ./tool/install_travis.sh
20+
21+
before_script:
22+
- ulimit -c unlimited -S
23+
- pub get
24+
25+
after_failure:
26+
- ./tool/after_failure_travis.sh
27+
1728
before_install:
1829
# Disable non-blocking I/O for stdout, stderr https://github.com/travis-ci/travis-ci/issues/4704#issuecomment-348435959
1930
- python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'

lib/src/io_utils.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,22 @@ class SubprocessLauncher {
186186

187187
if (Platform.environment.containsKey('DRY_RUN')) return null;
188188

189-
Process process = await Process.start(executable, arguments,
189+
String realExecutable = executable;
190+
final List<String> realArguments = [];
191+
if (Platform.isLinux) {
192+
// Use GNU coreutils to force line buffering. This makes sure that
193+
// subprocesses that die due to fatal signals do not chop off the
194+
// last few lines of their output.
195+
//
196+
// Dart does not actually do this (seems to flush manually) unless
197+
// the VM crashes.
198+
realExecutable = 'stdbuf';
199+
realArguments.addAll(['-o', 'L', '-e', 'L']);
200+
realArguments.add(executable);
201+
}
202+
realArguments.addAll(arguments);
203+
204+
Process process = await Process.start(realExecutable, realArguments,
190205
workingDirectory: workingDirectory, environment: environment);
191206
Future<void> stdoutFuture = _printStream(process.stdout, stdout,
192207
prefix: prefix, filter: jsonCallback);

tool/after_failure_travis.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
4+
# for details. All rights reserved. Use of this source code is governed by a
5+
# BSD-style license that can be found in the LICENSE file.
6+
7+
# Echo commands as they execute.
8+
set -x
9+
10+
# Display backtrace for a single core.
11+
function do_core() {
12+
local corefile="$1"
13+
14+
echo "Processing core file: $corefile"
15+
gdb -c "$corefile" -ex "thread apply all bt" -ex "set pagination 0" -batch
16+
}
17+
18+
# Find core files in likely locations for dartdoc.
19+
if uname | grep -q Linux ; then
20+
COREFILES=$(find . -type f -name "core*" 2>/dev/null | egrep -v '(.yaml|.dart|.expect|.gni)$') # find core files
21+
COREFILES_TMP="$(cd /tmp ; find . -type f -name "core*" 2>/dev/null | egrep -v '(.yaml|.dart|.expect|.gni)$')"
22+
for f in ${COREFILES} ; do {
23+
do_core "$f"
24+
} ; done
25+
for f in ${COREFILES_TMP} ; do {
26+
do_core "/tmp/$f"
27+
} ; done
28+
fi
29+

tool/install_travis.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
4+
# for details. All rights reserved. Use of this source code is governed by a
5+
# BSD-style license that can be found in the LICENSE file.
6+
7+
# Echo commands as they execute.
8+
set -x
9+
10+
if uname | grep -q Linux ; then
11+
sudo apt-get install -y gdb
12+
fi
13+
14+
exit 0

0 commit comments

Comments
 (0)