Force all dart:io usage to go through 'base/io.dart' (#7390)
This ensures that accidental usages of dart:io's file API don't creep in over time.
This commit is contained in:
@@ -6,7 +6,7 @@ trap detect_error_on_exit EXIT HUP INT QUIT TERM
|
||||
|
||||
detect_error_on_exit() {
|
||||
exit_code=$?
|
||||
set +x
|
||||
{ set +x; } 2>/dev/null
|
||||
if [[ $exit_code -ne 0 ]]; then
|
||||
echo -e "\x1B[31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1B[0m"
|
||||
echo -e "\x1B[1mError:\x1B[31m script exited early due to error ($exit_code)\x1B[0m"
|
||||
@@ -14,6 +14,27 @@ detect_error_on_exit() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_for_dart_io() {
|
||||
{ set +x; } 2>/dev/null
|
||||
(
|
||||
cd packages/flutter_tools
|
||||
for f in $(grep -Erl '^import.*dart:io' lib bin test); do
|
||||
if [[ "$f" == "lib/src/base/io.dart" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
IFS=$'\n' matches=( $(grep -E '^import.*dart:io' $f) )
|
||||
for match in "${matches[@]}"; do
|
||||
if [[ "$match" != *"ignore: dart_io_import"* ]]; then
|
||||
echo -e "\x1B[31mError: $f imports 'dart:io'; import 'lib/src/base/io.dart' instead\x1B[0m"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
)
|
||||
set -ex
|
||||
}
|
||||
|
||||
set -ex
|
||||
|
||||
# analyze all the Dart code in the repo
|
||||
@@ -40,6 +61,7 @@ SRC_ROOT=$PWD
|
||||
(cd packages/flutter_driver; dart -c test/all.dart)
|
||||
(cd packages/flutter_test; flutter test)
|
||||
(cd packages/flutter_tools; FLUTTER_ROOT=$SRC_ROOT dart -c test/all.dart)
|
||||
check_for_dart_io
|
||||
|
||||
(cd dev/devicelab; dart -c test/all.dart)
|
||||
(cd dev/manual_tests; flutter test)
|
||||
|
||||
Reference in New Issue
Block a user