Skip to content

Commit b5d6c80

Browse files
authored
[CI] Update deps script (flutter#12427)
- Unblocks flutter/packages#12423 Fixes a Pub version solver failure during release PR testing (`make-deps-path-based`) for co-dependent packages (specifically `material_ui` and `cupertino_ui`). When creating a release PR for `material_ui` (e.g., `release-material_ui-0.0.3+1`), the `make-deps-path-based` CI step failed during `flutter test` on `packages/cupertino_ui` with the following Pub version solver error: ``` Resolving dependencies in `./example`... Because every version of material_ui from path depends on cupertino_ui from hosted and cupertino_ui_examples depends on cupertino_ui from path, material_ui from path is forbidden. So, because cupertino_ui_examples depends on material_ui from path, version solving failed. Failed to update packages. ``` `material_ui` and `cupertino_ui` share an asymmetric co-dependency in the repository: - **`material_ui`** has a **direct dependency** on `cupertino_ui` (`dependencies: cupertino_ui: ^0.0.3`). - **`cupertino_ui`** has a **dev dependency** on `material_ui` (`dev_dependencies: material_ui: ^0.0.2`). When `make-deps-path-based --target-dependencies=material_ui` runs: 1. `make-deps-path-based` adds `dependency_overrides: material_ui: {path: ../material_ui}` to `cupertino_ui/pubspec.yaml` and `cupertino_ui/example/pubspec.yaml`. 2. `cupertino_ui/example` depends directly on `cupertino_ui` (`path: ..`). 3. `material_ui` (from `path`) depends on `cupertino_ui: ^0.0.3` (from hosted `pub.dev`). 4. Without `cupertino_ui` in `cupertino_ui/example`'s `dependency_overrides`, Pub detects `cupertino_ui` sourced from **`path`** (in `cupertino_ui_examples`) and **`hosted`** (in `material_ui`), causing Pub's version solver to reject the resolution graph. Updated `make-deps-path-based` (`script/tool/lib/src/make_deps_path_based_command.dart`): When `_addDependencyOverridesIfNecessary` recursively updates example apps of a package (`for (final RepositoryPackage example in package.getExamples())`), it now explicitly includes the parent `package` itself in the local package mapping and `additionalPackagesToOverride`. This ensures `cupertino_ui/example/pubspec.yaml` receives a path override for its parent package (`dependency_overrides: cupertino_ui: {path: ...}`) alongside the target package override (`material_ui: {path: ...}`). Consequently, Pub solver resolves both local path dependencies cleanly without requiring recursive dependency expansion (thereby preserving the safety net of `--target-dependencies`). --- #### Why `cupertino_ui` Has a `dev_dependency` on `material_ui` `cupertino_ui` declares `material_ui` in its `dev_dependencies` because multiple files across `cupertino_ui/lib/src/` (e.g., `text_field.dart`, `dialog.dart`, `scrollbar.dart`, `theme.dart`) use Dart `@docImport` directives referencing Material design widgets in public API documentation: ```dart /// @DocImport 'package:material_ui/material_ui.dart'; ``` Per Dart doc guidelines, packages referenced in `@docImport` must be declared in `dev_dependencies` so static analysis and `dartdoc` can resolve the cross-referenced symbols. --- #### Didn't we fix this last week? - **Aug 4, 09:06 AM (`material_ui 0.0.3` release flutter#12352)**: Both packages still used Dart Workspaces (`resolution: workspace`). Under Dart Workspaces, Pub dependency resolution was handled at the top-level workspace root, hiding the Pub solver conflict. - **Aug 4, 12:44 PM (PR flutter#12351)**: PR flutter#12351 landed to unblock `cupertino_ui 0.0.3` by removing Dart workspaces from `cupertino_ui` and `material_ui`. - When releasing **`cupertino_ui`** (`targetDependencies=cupertino_ui`), `material_ui` got path overrides for `cupertino_ui`. Since `cupertino_ui` didn't depend on a third package pulling hosted `cupertino_ui`, `cupertino_ui`'s release succeeded. - However, when releasing **`material_ui`** (`targetDependencies=material_ui`), `material_ui`'s direct dependency on `cupertino_ui` caused `cupertino_ui/example` to fail. - **Aug 10 (`material_ui 0.0.3+1` release flutter#12423)**: This was the first release attempt of `material_ui` since Dart workspaces were removed, exposing the non-workspace Pub solver requirement. ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent cdbe30f commit b5d6c80

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎script/tool/lib/src/make_deps_path_based_command.dart‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ class MakeDepsPathBasedCommand extends PackageCommand {
236236

237237
// Find the relative path from the common base to the local package.
238238
final List<String> repoRelativePathComponents = path.split(
239-
path.relative(localDependencies[packageName]!.path, from: repoRootPath),
239+
path.relative(
240+
localDependencies[packageName]!.directory.absolute.path,
241+
from: repoRootPath,
242+
),
240243
);
241244
final String pathValue = p.posix.joinAll(<String>[
242245
...relativeBasePathComponents,
@@ -272,11 +275,14 @@ ${newOverrideLines.join('\n')}
272275
// example app doesn't. Since integration tests are run in the example app,
273276
// it needs the overrides in order for tests to pass.
274277
for (final RepositoryPackage example in package.getExamples()) {
278+
final String parentPackageName = package.parsePubspec().name;
275279
await _addDependencyOverridesIfNecessary(
276280
example,
277-
localDependencies,
281+
<String, RepositoryPackage>{...localDependencies, parentPackageName: package},
278282
versions,
279-
additionalPackagesToOverride: packagesToOverride,
283+
// Add an override to the parent package in case a transitive dependency has a dependency on it,
284+
// since that (non-path) dependency would conflict with the path-based dependency in the example.
285+
additionalPackagesToOverride: <String>{...packagesToOverride, parentPackageName},
280286
);
281287
}
282288

‎script/tool/test/make_deps_path_based_command_test.dart‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ ${overrides.map((String dep) => ' $dep:\n path: $path').join('\n')}
226226
final Map<String, String?> exampleOverrides = getDependencyOverrides(
227227
pluginAppFacing.getExamples().first,
228228
);
229-
expect(exampleOverrides.length, 1);
229+
expect(exampleOverrides.length, 2);
230+
expect(exampleOverrides['bar'], '../../../../packages/bar/bar');
230231
expect(exampleOverrides['bar_android'], '../../../../packages/bar/bar_android');
231232
});
232233

@@ -248,8 +249,9 @@ ${overrides.map((String dep) => ' $dep:\n path: $path').join('\n')}
248249
final Map<String, String?> exampleOverrides = getDependencyOverrides(
249250
pluginAppFacing.getExamples().first,
250251
);
251-
expect(exampleOverrides.length, 2);
252+
expect(exampleOverrides.length, 3);
252253
expect(exampleOverrides['another_package'], '../../../../packages/another_package');
254+
expect(exampleOverrides['bar'], '../../../../packages/bar/bar');
253255
expect(exampleOverrides['bar_android'], '../../../../packages/bar/bar_android');
254256
});
255257

@@ -264,6 +266,50 @@ ${overrides.map((String dep) => ' $dep:\n path: $path').join('\n')}
264266
expect(exampleOverrides.length, 0);
265267
});
266268

269+
test(
270+
'example overrides include parent package to resolve dependency overrides cleanly',
271+
() async {
272+
createFakePackage('material_ui', packagesDir);
273+
final RepositoryPackage cupertinoUi = createFakePlugin('cupertino_ui', packagesDir);
274+
275+
addDevDependenciesSection(cupertinoUi, <String>['material_ui']);
276+
277+
await runCapturingPrint(runner, <String>[
278+
'make-deps-path-based',
279+
'--target-dependencies=material_ui',
280+
]);
281+
282+
final Map<String, String?> exampleOverrides = getDependencyOverrides(
283+
cupertinoUi.getExamples().first,
284+
);
285+
expect(exampleOverrides['material_ui'], '../../../packages/material_ui');
286+
expect(exampleOverrides['cupertino_ui'], '../../../packages/cupertino_ui');
287+
},
288+
);
289+
290+
test(
291+
'does not recursively override dependencies of target packages to preserve safety net',
292+
() async {
293+
final RepositoryPackage clientPkg = createFakePackage('pkg_client', packagesDir);
294+
final RepositoryPackage targetPkg = createFakePackage('pkg_target', packagesDir);
295+
createFakePackage('pkg_dependency', packagesDir);
296+
297+
addDependencies(clientPkg, <String>['pkg_target', 'pkg_dependency']);
298+
addDependencies(targetPkg, <String>['pkg_dependency']);
299+
300+
await runCapturingPrint(runner, <String>[
301+
'make-deps-path-based',
302+
'--target-dependencies=pkg_target',
303+
]);
304+
305+
final Map<String, String?> clientOverrides = getDependencyOverrides(clientPkg);
306+
expect(clientOverrides['pkg_target'], '../../packages/pkg_target');
307+
// Dependencies of target packages must not be recursively pathified,
308+
// ensuring clients are tested against published versions to preserve safety.
309+
expect(clientOverrides['pkg_dependency'], isNull);
310+
},
311+
);
312+
267313
test(
268314
'alphabetizes overrides from different sections to avoid lint warnings in analysis',
269315
() async {

0 commit comments

Comments
 (0)