Skip to content

Commit b92bc35

Browse files
dcharkesCommit Queue
authored andcommitted
[dartdev] Make dart install from git test hermetic
Don't depend on an external repo, instead create a git repo locally. TEST=pkg/dartdev/test/native_assets/install_test.dart Closes: #61638 Change-Id: I61df102812814ba2b83fd65a6cc5f607daa531f7 Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453000 Reviewed-by: Slava Egorov <[email protected]> Auto-Submit: Daco Harkes <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent 273fe8e commit b92bc35

File tree

4 files changed

+84
-29
lines changed

4 files changed

+84
-29
lines changed

pkg/dartdev/lib/src/commands/install.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ enum _SourceKind {
640640
if (parsedGitSshUrl != null) {
641641
return git;
642642
}
643+
644+
if (argument.endsWith('.git') ||
645+
argument.endsWith('.git/') ||
646+
argument.endsWith('.git\\')) {
647+
return git;
648+
}
643649
return path;
644650
}
645651

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void main() {
2+
print('Hello world');
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: dart_app
2+
3+
environment:
4+
sdk: ^3.8.0
5+
6+
executables:
7+
dart_app:

pkg/dartdev/test/native_assets/install_test.dart

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ final _pathEnvVarSeparator = Platform.isWindows ? ';' : ':';
3434
/// clone.
3535
const _gitPackageForTest = 'dart_app';
3636

37-
final _gitHttpsUrl = Uri.parse('https://dart.googlesource.com/native');
38-
39-
const _gitPath = 'pkgs/hooks_runner/test_data/dart_app/';
40-
41-
const _gitRef = '8ce789991cddb8864b0f3fa210c83d3d10e78316';
42-
4337
const String _dartDirectoryEnvKey = 'DART_DATA_HOME';
4438

4539
final _dartDevEntryScriptUri = resolveDartDevUri('bin/dartdev.dart');
@@ -52,6 +46,13 @@ final _packageDir = Directory.fromUri(
5246
_sdkUri.resolveUri(_packageRelativePath),
5347
);
5448

49+
/// Standalone, with its own pubspec.
50+
final _package2RelativePath = Uri.directory('pkg/dartdev/test/data/dart_app/');
51+
52+
final _package2Dir = Directory.fromUri(
53+
_sdkUri.resolveUri(_package2RelativePath),
54+
);
55+
5556
void main([List<String> args = const []]) async {
5657
if (!nativeAssetsExperimentAvailableOnCurrentChannel) {
5758
return;
@@ -242,28 +243,72 @@ Run "dart help" to see global options.
242243
}
243244

244245
final argumentssGit = [
245-
(
246-
null,
247-
[_gitHttpsUrl.toString(), '--git-path', _gitPath],
248-
),
249-
(
250-
null,
251-
[_gitHttpsUrl.toString(), '--git-path', _gitPath, '--git-ref', _gitRef],
252-
),
246+
['git'],
247+
[
248+
'git',
249+
'--git-path',
250+
'--git-ref',
251+
],
253252
];
254253

255-
for (final (workingDirectory, arguments) in argumentssGit) {
256-
var testName = arguments.join(' ');
257-
if (workingDirectory != null) {
258-
testName += ' in ${workingDirectory.toFilePath()}';
259-
}
254+
for (final testArguments in argumentssGit) {
255+
var testName = testArguments.join(' ');
260256

261257
skippableTest('dart install $testName', timeout: longTimeout, () async {
262258
await inTempDir((tempUri) async {
263-
final binDir = Directory.fromUri(tempUri.resolve('install/bin'));
259+
final gitUri = tempUri.resolve('app.git/');
260+
await Directory.fromUri(gitUri.resolve('bin/')).create(recursive: true);
261+
for (final file in [
262+
'pubspec.yaml',
263+
'bin/dart_app.dart',
264+
]) {
265+
await File.fromUri(_package2Dir.uri.resolve(file))
266+
.copy(gitUri.resolve(file).toFilePath());
267+
}
268+
for (final commands in [
269+
['init'],
270+
['add', '.'],
271+
['commit', '-m', '"Initial commit"'],
272+
]) {
273+
final gitResult = await Process.run(
274+
'git',
275+
commands,
276+
workingDirectory: gitUri.toFilePath(),
277+
);
278+
if (gitResult.exitCode != 0) {
279+
throw ProcessException(
280+
'git',
281+
commands,
282+
gitResult.stderr,
283+
);
284+
}
285+
}
286+
final gitRef = ((await Process.run(
287+
'git',
288+
['rev-parse', 'HEAD'],
289+
workingDirectory: gitUri.toFilePath(),
290+
))
291+
.stdout as String)
292+
.trim();
293+
final gitPath = './';
294+
final arguments = [
295+
gitUri.toFilePath(),
296+
if (testArguments.contains('--git-path')) ...[
297+
'--git-path',
298+
gitPath,
299+
],
300+
if (testArguments.contains('--git-ref')) ...[
301+
'--git-ref',
302+
gitRef,
303+
],
304+
];
305+
306+
final dartDataHome = tempUri.resolve('dart_home/');
307+
await Directory.fromUri(dartDataHome).create();
308+
final binDir = Directory.fromUri(dartDataHome.resolve('install/bin'));
264309

265310
final environment = {
266-
_dartDirectoryEnvKey: tempUri.toFilePath(),
311+
_dartDirectoryEnvKey: dartDataHome.toFilePath(),
267312
'PATH':
268313
'${binDir.path}$_pathEnvVarSeparator${Platform.environment['PATH']!}',
269314
};
@@ -272,7 +317,7 @@ Run "dart help" to see global options.
272317
fromDartdevSource,
273318
'install',
274319
arguments,
275-
workingDirectory,
320+
null,
276321
environment,
277322
);
278323

@@ -292,14 +337,8 @@ Run "dart help" to see global options.
292337
);
293338
expect(
294339
installedLine,
295-
contains(' from Git repository "${_gitHttpsUrl.toString()}"'),
340+
contains(' at "${gitRef.substring(0, 8)}"'),
296341
);
297-
if (arguments.contains('--git-ref')) {
298-
expect(
299-
installedLine,
300-
contains(' at "${_gitRef.substring(0, 8)}"'),
301-
);
302-
}
303342

304343
await _runDartdev(
305344
fromDartdevSource,

0 commit comments

Comments
 (0)