diff --git a/pkg/analysis_server/test/utils/package_root.dart b/pkg/analysis_server/test/utils/package_root.dart index 1957a61e2ae..ab5cdac2e88 100644 --- a/pkg/analysis_server/test/utils/package_root.dart +++ b/pkg/analysis_server/test/utils/package_root.dart @@ -11,7 +11,8 @@ import 'package:path/path.dart' as pathos; String get packageRoot { // If the package root directory is specified on the command line using // -DpkgRoot=..., use it. - String pkgRootVar = const String.fromEnvironment('pkgRoot'); + const String pkgRootVar = + bool.hasEnvironment('pkgRoot') ? String.fromEnvironment('pkgRoot') : null; if (pkgRootVar != null) { String path = pathos.join(Directory.current.path, pkgRootVar); if (!path.endsWith(pathos.separator)) path += pathos.separator; diff --git a/pkg/analyzer/test/utils/package_root.dart b/pkg/analyzer/test/utils/package_root.dart index 1957a61e2ae..8055970c39e 100644 --- a/pkg/analyzer/test/utils/package_root.dart +++ b/pkg/analyzer/test/utils/package_root.dart @@ -11,7 +11,9 @@ import 'package:path/path.dart' as pathos; String get packageRoot { // If the package root directory is specified on the command line using // -DpkgRoot=..., use it. - String pkgRootVar = const String.fromEnvironment('pkgRoot'); + String pkgRootVar = const bool.hasEnvironment('pkgRoot') + ? const String.fromEnvironment('pkgRoot') + : null; if (pkgRootVar != null) { String path = pathos.join(Directory.current.path, pkgRootVar); if (!path.endsWith(pathos.separator)) path += pathos.separator; diff --git a/pkg/analyzer_plugin/test/utils/package_root.dart b/pkg/analyzer_plugin/test/utils/package_root.dart index 47d0e31f211..98c24ba9d30 100644 --- a/pkg/analyzer_plugin/test/utils/package_root.dart +++ b/pkg/analyzer_plugin/test/utils/package_root.dart @@ -11,7 +11,9 @@ import 'package:path/path.dart' as pathos; String get packageRoot { // If the package root directory is specified on the command line using // -DpkgRoot=..., use it. - String pkgRootVar = const String.fromEnvironment('pkgRoot'); + String pkgRootVar = bool.hasEnvironment('pkgRoot') + ? const String.fromEnvironment('pkgRoot') + : null; if (pkgRootVar != null) { String path = pathos.join(Directory.current.path, pkgRootVar); if (!path.endsWith(pathos.separator)) path += pathos.separator; diff --git a/pkg/compiler/lib/src/tracer.dart b/pkg/compiler/lib/src/tracer.dart index e42352baf0a..66564af65ca 100644 --- a/pkg/compiler/lib/src/tracer.dart +++ b/pkg/compiler/lib/src/tracer.dart @@ -17,8 +17,7 @@ String get TRACE_FILTER_PATTERN => TRACE_FILTER_PATTERN_FROM_ENVIRONMENT != '' : TRACE_FILTER_PATTERN_FOR_TEST; const String TRACE_FILTER_PATTERN_FROM_ENVIRONMENT = - // TODO(sigmund): remove `?? ''` once #40678 is backported. - const String.fromEnvironment("DUMP_IR") ?? ''; + String.fromEnvironment("DUMP_IR", defaultValue: ""); String TRACE_FILTER_PATTERN_FOR_TEST; /// Dumps the intermediate representation after each phase in a format diff --git a/pkg/front_end/tool/_fasta/abcompile.dart b/pkg/front_end/tool/_fasta/abcompile.dart index 4ccde2ac1c2..63ea80b6dec 100644 --- a/pkg/front_end/tool/_fasta/abcompile.dart +++ b/pkg/front_end/tool/_fasta/abcompile.dart @@ -9,11 +9,10 @@ import 'dart:io'; import 'standard_deviation.dart'; -const String bRootPath = const String.fromEnvironment("bRoot"); -const int abIterations = - const int.fromEnvironment("abIterations", defaultValue: 15); -const int iterations = - const int.fromEnvironment("iterations", defaultValue: 15); +const String bRootPath = + bool.hasEnvironment("bRoot") ? String.fromEnvironment("bRoot") : null; +const int abIterations = int.fromEnvironment("abIterations", defaultValue: 15); +const int iterations = int.fromEnvironment("iterations", defaultValue: 15); /// Compare the performance of two different fast implementations /// by alternately launching the compile application in this directory diff --git a/pkg/testing/lib/src/discover.dart b/pkg/testing/lib/src/discover.dart index 9b82e8ad026..3fd09e996dd 100644 --- a/pkg/testing/lib/src/discover.dart +++ b/pkg/testing/lib/src/discover.dart @@ -64,9 +64,15 @@ Uri computePackageConfig() { return Uri.base.resolve(".packages"); } +// TODO(eernst): Use `bool.hasEnvironment` below when possible; +// for now we use a dual `defaultValue` rewrite. +const _dartSdk = (String.fromEnvironment("DART_SDK", defaultValue: "1") == + String.fromEnvironment("DART_SDK", defaultValue: "2")) + ? String.fromEnvironment("DART_SDK") + : null; + Uri computeDartSdk() { - String dartSdkPath = Platform.environment["DART_SDK"] ?? - const String.fromEnvironment("DART_SDK"); + String dartSdkPath = Platform.environment["DART_SDK"] ?? _dartSdk; if (dartSdkPath != null) { return Uri.base.resolveUri(new Uri.file(dartSdkPath)); } else { diff --git a/pkg/vm/lib/transformations/type_flow/utils.dart b/pkg/vm/lib/transformations/type_flow/utils.dart index 164a6e9a07a..379c1ed6f99 100644 --- a/pkg/vm/lib/transformations/type_flow/utils.dart +++ b/pkg/vm/lib/transformations/type_flow/utils.dart @@ -32,7 +32,7 @@ const bool kScopeTrace = const bool.fromEnvironment('global.type.flow.scope.trace'); const int kScopeIndent = - const int.fromEnvironment('global.type.flow.scope.indent'); + const int.fromEnvironment('global.type.flow.scope.indent', defaultValue: 1); /// Extended 'assert': always checks condition. assertx(bool cond, {details}) { @@ -57,7 +57,7 @@ class _ScopedLogger implements _Logger { "\u001b[35m", // magenta "\u001b[36m", // cyan ]; - static const int _scopeIndent = kScopeIndent ?? 1; + static const int _scopeIndent = kScopeIndent; int _scope = 0; List _scopePrefixes = [""]; diff --git a/runtime/observatory/lib/src/app/analytics.dart b/runtime/observatory/lib/src/app/analytics.dart index 484f7da7ff7..a34c2daf774 100644 --- a/runtime/observatory/lib/src/app/analytics.dart +++ b/runtime/observatory/lib/src/app/analytics.dart @@ -4,10 +4,17 @@ part of app; +// TODO(eernst): Use 'bool.fromEnvironment' below when possible; +// for now we use a dual `defaultValue` rewrite. +const _obsVer = (String.fromEnvironment('OBS_VER', defaultValue: '1') == + String.fromEnvironment('OBS_VER', defaultValue: '2')) + ? String.fromEnvironment('OBS_VER') + : null; + class Analytics { static final _UA = 'UA-26406144-17'; static final _name = 'Observatory'; - static final _version = const String.fromEnvironment('OBS_VER'); + static final _version = _obsVer; static final _googleAnalytics = new AnalyticsHtml(_UA, _name, _version); static initialize() { diff --git a/tests/compiler/dart2js_extra/new_from_env_test.dart b/tests/compiler/dart2js_extra/new_from_env_test.dart index cec8a78a48b..7138c6be16e 100644 --- a/tests/compiler/dart2js_extra/new_from_env_test.dart +++ b/tests/compiler/dart2js_extra/new_from_env_test.dart @@ -11,7 +11,7 @@ import 'package:expect/expect.dart'; /// `new` instead of `const`. main() { Expect.isFalse(const bool.fromEnvironment('X')); - Expect.isNull(const String.fromEnvironment('X')); + Expect.equals('', const String.fromEnvironment('X', defaultValue: '')); Expect.equals(const int.fromEnvironment('X', defaultValue: 0), 0); Expect.throws(() => new bool.fromEnvironment('X')); diff --git a/tests/corelib_2/from_environment_const_type_undefined_test.dart b/tests/corelib_2/from_environment_const_type_undefined_test.dart index c2e90ef6344..d63d75f96cb 100644 --- a/tests/corelib_2/from_environment_const_type_undefined_test.dart +++ b/tests/corelib_2/from_environment_const_type_undefined_test.dart @@ -25,14 +25,14 @@ const int // //# 10: ok String //# 11: compile-time error Foo // //# 12: compile-time error - c = const int.fromEnvironment('c'); + c = const int.fromEnvironment('c', defaultValue: 0); const bool // //# 13: compile-time error int // //# 14: compile-time error String //# 15: ok Foo // //# 16: compile-time error - d = const String.fromEnvironment('d'); + d = const String.fromEnvironment('d', defaultValue: ''); main() { Expect.equals(false, a); diff --git a/tests/language/bool/has_environment_not_new_test.dart b/tests/language/bool/has_environment_not_new_test.dart new file mode 100644 index 00000000000..947c6bed579 --- /dev/null +++ b/tests/language/bool/has_environment_not_new_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import "package:expect/expect.dart"; + +main() { + Expect.throws(() => new bool.hasEnvironment("Anything")); +} diff --git a/tests/language/bool/has_environment_test.dart b/tests/language/bool/has_environment_test.dart new file mode 100644 index 00000000000..df593f1fa8b --- /dev/null +++ b/tests/language/bool/has_environment_test.dart @@ -0,0 +1,15 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// SharedOptions=-Da= -Db=b -Dc=Something + +import 'package:expect/expect.dart'; + +main() { + Expect.isTrue(const bool.hasEnvironment('dart.library.core')); + Expect.isTrue(const bool.hasEnvironment('a')); + Expect.isTrue(const bool.hasEnvironment('b')); + Expect.isTrue(const bool.hasEnvironment('c')); + Expect.isFalse(const bool.hasEnvironment('d')); +} diff --git a/tests/language_2/string/const_interpolation2_test.dart b/tests/language_2/string/const_interpolation2_test.dart index 968d2c2c740..c9c373cb41c 100644 --- a/tests/language_2/string/const_interpolation2_test.dart +++ b/tests/language_2/string/const_interpolation2_test.dart @@ -9,9 +9,15 @@ import "package:expect/expect.dart"; const u1 = null; const int u2 = null; const List u3 = null; -const u4 = const String.fromEnvironment("XXXXX"); -const u5 = const int.fromEnvironment("XXXXX"); -const u6 = const bool.fromEnvironment("XXXXX", defaultValue: null); +const u4 = const bool.hasEnvironment("XXXXX") + ? const String.fromEnvironment("XXXXX") + : null; +const u5 = const bool.hasEnvironment("XXXXX") + ? const int.fromEnvironment("XXXXX") + : null; +const u6 = bool.hasEnvironment("XXXXX") + ? const bool.fromEnvironment("XXXXX") + : null; const n1 = 42; const n2 = 3.1415; const int n3 = 37; @@ -88,7 +94,7 @@ main() { Expect.equals(b2.toString(), sb2); Expect.equals(b3.toString(), sb3); Expect.equals(b4.toString(), sb4); - var expect = "null null null 0 null 42 3.1415 37 4.6692 2.71828 87 " + var expect = "null null null null null null 42 3.1415 37 4.6692 2.71828 87 " "s1 s2 s1s2 s4 true false false true"; Expect.equals(expect, interpolation1); Expect.equals(expect, interpolation2); diff --git a/tests/language_2/unsorted/unevaluated_field.dart b/tests/language_2/unsorted/unevaluated_field.dart index 3567a7cef4f..5c701db0947 100644 --- a/tests/language_2/unsorted/unevaluated_field.dart +++ b/tests/language_2/unsorted/unevaluated_field.dart @@ -6,11 +6,13 @@ import "package:expect/expect.dart"; -const int gx = const int.fromEnvironment("x"); +const int gx = + const bool.hasEnvironment("x") ? const int.fromEnvironment("x") : null; class A { final int x = gx; - final int y = const int.fromEnvironment("y"); + final int y = + const bool.hasEnvironment("y") ? const int.fromEnvironment("y") : null; const A(); } diff --git a/tests/lib/isolate/string_from_environment_default_value_test.dart b/tests/lib/isolate/string_from_environment_default_value_test.dart index 153ab6e8b61..78b2febe6fd 100644 --- a/tests/lib/isolate/string_from_environment_default_value_test.dart +++ b/tests/lib/isolate/string_from_environment_default_value_test.dart @@ -10,7 +10,7 @@ import "dart:isolate"; import "package:expect/expect.dart"; void test(port) { - Expect.identical(const String.fromEnvironment('NOT_FOUND'), ""); + Expect.equals('', const String.fromEnvironment('NOT_FOUND')); Expect.equals( 'x', const String.fromEnvironment('NOT_FOUND', defaultValue: 'x')); if (port != null) port.send(null);