Files
sdk/pkg/dwds_test_common/lib/test_sdk_layout.dart
Jessy Yameogo e1d687cb9e [dwds][dwds_test_common] Base copy of DWDS and DWDS_TEST_COMMON from webdev@e43744b235531f409ab5e2f1271178943569697a
This CL migrates the `dwds` and `dwds_test_common` packages into the Dart SDK
repository.

Key Changes:
- Migration: Moved source code and tests into `pkg/dwds` & `pkg/dwds_test_common`.
- Linting and path resolution were updated in https://github.com/dart-lang/webdev/pull/2797, https://github.com/dart-lang/webdev/pull/2798 & https://github.com/dart-lang/webdev/pull/2799 to support both environments (webdev and sdk).


Testing:
- All tests passing locally.
- CI try bots are green.

Design Doc: http://goto.google.com/migrating-webdev and http://goto.google.com/migrating-dwds

Fixes https://github.com/dart-lang/sdk/issues/62100
Fixes https://github.com/dart-lang/sdk/issues/62101
Fixes https://github.com/dart-lang/sdk/issues/62102
Fixes https://github.com/dart-lang/sdk/issues/62103

Cq-Include-Trybots: luci.dart.try:pkg-win-release-try,pkg-win-release-arm64-try,pkg-mac-release-try,pkg-mac-release-arm64-try,pkg-linux-release-try,pkg-linux-release-arm64-try,pkg-linux-debug-try
Change-Id: Icc2bf9a86efb79d04a67053962a4548fe6e894f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494640
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2026-04-23 13:18:18 -07:00

200 lines
5.7 KiB
Dart

// Copyright (c) 2023, 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:dwds/sdk_configuration.dart';
import 'package:path/path.dart' as p;
/// Test Dart SDK layout.
///
/// Contains definition of the default SDK layout required for tests.
/// We keep all the path constants in one place for ease of update.
class TestSdkLayout {
static final defaultSdkDirectory = SdkLayout.defaultSdkDirectory;
static TestSdkLayout defaultSdkLayout = TestSdkLayout.createDefault(
defaultSdkDirectory,
);
static SdkConfiguration defaultSdkConfiguration = createConfiguration(
defaultSdkLayout,
);
factory TestSdkLayout.createDefault(String sdkDirectory) =>
TestSdkLayout.createDefaultFromSdkLayout(
SdkLayout.createDefault(sdkDirectory),
);
factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) =>
TestSdkLayout(
sdkDirectory: sdkLayout.sdkDirectory,
summaryPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'_internal',
'ddc_outline.dill',
),
fullDillPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'_internal',
'ddc_platform.dill',
),
amdJsPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'kernel',
'amd',
'dart_sdk.js',
),
amdJsMapPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'kernel',
'amd',
'dart_sdk.js.map',
),
ddcJsPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'kernel',
'ddc',
'dart_sdk.js',
),
ddcJsMapPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'kernel',
'ddc',
'dart_sdk.js.map',
),
ddcModuleLoaderJsPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'ddc',
'ddc_module_loader.js',
),
requireJsPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'amd',
'require.js',
),
stackTraceMapperPath: p.join(
sdkLayout.sdkDirectory,
'lib',
'dev_compiler',
'web',
'dart_stack_trace_mapper.js',
),
dartPath: p.join(
sdkLayout.sdkDirectory,
'bin',
Platform.isWindows ? 'dart.exe' : 'dart',
),
dartAotRuntimePath: p.join(
sdkLayout.sdkDirectory,
'bin',
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime',
),
frontendServerSnapshotPath: p.join(
sdkLayout.sdkDirectory,
'bin',
'snapshots',
'frontend_server_aot.dart.snapshot',
),
dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath,
kernelWorkerSnapshotPath: p.join(
sdkLayout.sdkDirectory,
'bin',
'snapshots',
'kernel_worker_aot.dart.snapshot',
),
devToolsDirectory: p.join(
sdkLayout.sdkDirectory,
'bin',
'resources',
'devtools',
),
);
final String sdkDirectory;
String get amdJsFileName => p.basename(amdJsPath);
String get amdJsMapFileName => p.basename(amdJsMapPath);
String get ddcJsFileName => p.basename(ddcJsPath);
String get ddcJsMapFileName => p.basename(ddcJsMapPath);
String get summaryFileName => p.basename(summaryPath);
String get fullDillFileName => p.basename(fullDillPath);
final String amdJsPath;
final String amdJsMapPath;
final String ddcJsPath;
final String ddcJsMapPath;
final String summaryPath;
final String fullDillPath;
final String ddcModuleLoaderJsPath;
final String requireJsPath;
final String stackTraceMapperPath;
final String dartPath;
final String dartAotRuntimePath;
final String frontendServerSnapshotPath;
final String dartdevcSnapshotPath;
final String kernelWorkerSnapshotPath;
final String devToolsDirectory;
const TestSdkLayout({
required this.sdkDirectory,
required this.amdJsPath,
required this.amdJsMapPath,
required this.ddcJsPath,
required this.ddcJsMapPath,
required this.summaryPath,
required this.fullDillPath,
required this.ddcModuleLoaderJsPath,
required this.requireJsPath,
required this.stackTraceMapperPath,
required this.dartPath,
required this.dartAotRuntimePath,
required this.frontendServerSnapshotPath,
required this.dartdevcSnapshotPath,
required this.kernelWorkerSnapshotPath,
required this.devToolsDirectory,
});
/// Creates configuration from sdk layout.
static SdkConfiguration createConfiguration(TestSdkLayout sdkLayout) =>
SdkConfiguration(
sdkDirectory: sdkLayout.sdkDirectory,
sdkSummaryPath: sdkLayout.summaryPath,
compilerWorkerPath: sdkLayout.dartdevcSnapshotPath,
);
}
// Update modified files.
Future<void> copyDirectory(String from, String to) async {
if (!Directory(from).existsSync()) return;
await Directory(to).create(recursive: true);
await for (final file in Directory(from).list(followLinks: false)) {
final copyTo = p.join(to, p.relative(file.path, from: from));
if (file is Directory) {
await copyDirectory(file.path, copyTo);
} else if (file is File) {
await File(file.path).copy(copyTo);
} else if (file is Link) {
await Link(copyTo).create(await file.target(), recursive: true);
}
}
}