Files
sdk/pkg/dwds/lib/data/utils.dart
Jessy Yameogo a909051679 [dwds][dwds_test_common] Migrate package to the SDK repository
This CL migrates the `dwds` and `dwds_test_common` packages into the Dart SDK
repository.

Key Changes:
- Monorepo Compliance: Updated the pubspecs to align with the SDK pub workspace setup.
- Excluded `pkg/dwds_test_common/fixtures/` from `package_deps.dart`.
- Updated pkg to status to skip `dwds/test/integration/*` & `dwds_test_common/fixtures/*` until DWDS migration is complete.
- Remove package `build_daemon` from DWDS' `pubspec.yaml` as it's not approved for SDK env.
- Added `@skip_package_deps_validation` to the following files to ignore import checks for package:build_daemon: `server.dart`, `utilities.dart`, `context.dart`.
- Created `pkg/dwds/lib/src/utilities/test_path_utils.dart` to fix path resolution failures in tests (ie. `build_script_test.dart` and `ensure_version_test.dart`).

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: I6130be8b7e0b42fbbf81b26a4950a2c4282e3a48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494660
Commit-Queue: Jessy Yameogo <yjessy@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2026-04-23 13:18:18 -07:00

41 lines
1.2 KiB
Dart

// Copyright (c) 2026, 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.
/// Converts a list of key-value pairs into a map.
///
/// The list is expected to be in the format:
/// ['key1', value1, 'key2', value2, ...]
///
/// Or, if [type] is provided:
/// ['Type', 'key1', value1, 'key2', value2, ...]
///
/// If [type] is provided, the first element of the list must match [type],
/// and the key-value pairs start from the second element.
Map<String, dynamic> listToMap(List<dynamic> list, {String? type}) {
var startIndex = 0;
if (type != null) {
if (list.isEmpty || list.first != type) {
throw FormatException('Expected "$type" as first element', list);
}
startIndex = 1;
}
if ((list.length - startIndex).isOdd) {
throw FormatException(
'Expected an even number of elements'
'${type != null ? " after $type" : ""}',
list,
);
}
final map = <String, dynamic>{};
var i = startIndex;
while (i < list.length - 1) {
final key = list[i] as String;
final value = list[i + 1];
map[key] = value;
i += 2;
}
return map;
}