97baa6efd1
This reverts commit 58860f4814.
Reason for revert: Broke bots. Will investigate.
Original change's description:
> Improve handling of disable-dartdev-analytics
>
> This is second try of https://dart-review.googlesource.com/c/sdk/+/171284
> that was reverted to to faulty logic in main_options.
>
> Some other refactorings are piggy-backed along.
>
> TestProject.runSync no longer takes a 'command' argument. It was anyway
> often not an argument.
>
> Also stop the messy handling of pub arguments. It is no longer needed.
>
> BUG: https://github.com/dart-lang/sdk/issues/44135
> Change-Id: I49abf5810d9ea262409ba9d93f0471037cb8a753
> TEST=The VM change is tested via all the pkg/dartdev/test/command/* tests that invoke dart with the --no-analytics flag.
> TEST=Furthermore manual test that the --no-analytics flag is passed to dartdev.
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174261
> Reviewed-by: Jonas Jensen <jonasfj@google.com>
> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
TBR=bkonyi@google.com,sigurdm@google.com,jonasfj@google.com
Change-Id: I754bcebdcfc595158b04d431662b65bf25f5b89d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174466
Reviewed-by: Sigurd Meldgaard <sigurdm@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
122 lines
3.3 KiB
Dart
122 lines
3.3 KiB
Dart
// 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 'dart:io';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
|
|
/// A long [Timeout] is provided for tests that start a process on
|
|
/// `bin/dartdev.dart` as the command is not compiled ahead of time, and each
|
|
/// invocation requires the VM to compile the entire dependency graph.
|
|
const Timeout longTimeout = Timeout(Duration(minutes: 5));
|
|
|
|
/// This version of dart is the last guaranteed pre-null safety language
|
|
/// version:
|
|
const String dartVersionFilePrefix2_9 = '// @dart = 2.9\n';
|
|
|
|
TestProject project(
|
|
{String mainSrc,
|
|
String analysisOptions,
|
|
bool logAnalytics = false,
|
|
String name = TestProject._defaultProjectName}) =>
|
|
TestProject(
|
|
mainSrc: mainSrc,
|
|
analysisOptions: analysisOptions,
|
|
logAnalytics: logAnalytics);
|
|
|
|
class TestProject {
|
|
static const String _defaultProjectName = 'dartdev_temp';
|
|
|
|
Directory dir;
|
|
|
|
String get dirPath => dir.path;
|
|
|
|
final String name;
|
|
|
|
String get relativeFilePath => 'lib/main.dart';
|
|
|
|
final bool logAnalytics;
|
|
|
|
TestProject({
|
|
String mainSrc,
|
|
String analysisOptions,
|
|
this.name = _defaultProjectName,
|
|
this.logAnalytics = false,
|
|
}) {
|
|
dir = Directory.systemTemp.createTempSync(name);
|
|
file('pubspec.yaml', '''
|
|
name: $name
|
|
environment:
|
|
sdk: '>=2.10.0 <3.0.0'
|
|
|
|
dev_dependencies:
|
|
test: any
|
|
''');
|
|
if (analysisOptions != null) {
|
|
file('analysis_options.yaml', analysisOptions);
|
|
}
|
|
if (mainSrc != null) {
|
|
file(relativeFilePath, mainSrc);
|
|
}
|
|
}
|
|
|
|
void file(String name, String contents) {
|
|
var file = File(path.join(dir.path, name));
|
|
file.parent.createSync();
|
|
file.writeAsStringSync(contents);
|
|
}
|
|
|
|
void dispose() {
|
|
if (dir.existsSync()) {
|
|
dir.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
ProcessResult runSync(
|
|
String command,
|
|
List<String> args, {
|
|
String workingDir,
|
|
}) {
|
|
var arguments = [
|
|
command,
|
|
...?args,
|
|
];
|
|
|
|
arguments.add('--disable-dartdev-analytics');
|
|
return Process.runSync(Platform.resolvedExecutable, arguments,
|
|
workingDirectory: workingDir ?? dir.path,
|
|
environment: {if (logAnalytics) '_DARTDEV_LOG_ANALYTICS': 'true'});
|
|
}
|
|
|
|
String _sdkRootPath;
|
|
|
|
/// Return the root of the SDK.
|
|
String get sdkRootPath {
|
|
if (_sdkRootPath == null) {
|
|
// Assumes the script importing this one is somewhere under the SDK.
|
|
String current = path.canonicalize(Platform.script.toFilePath());
|
|
do {
|
|
String tryDir = path.dirname(current);
|
|
if (File(path.join(tryDir, 'pkg', 'dartdev', 'bin', 'dartdev.dart'))
|
|
.existsSync()) {
|
|
_sdkRootPath = tryDir;
|
|
return _sdkRootPath;
|
|
}
|
|
current = tryDir;
|
|
} while (path.dirname(current) != current);
|
|
throw StateError('can not find SDK repository root');
|
|
}
|
|
return _sdkRootPath;
|
|
}
|
|
|
|
String get absolutePathToDartdevFile =>
|
|
path.join(sdkRootPath, 'pkg', 'dartdev', 'bin', 'dartdev.dart');
|
|
|
|
File findFile(String name) {
|
|
var file = File(path.join(dir.path, name));
|
|
return file.existsSync() ? file : null;
|
|
}
|
|
}
|