@@ -67,8 +67,8 @@ Future<run_process.RunProcessResult> runProcess({
6767 filesystem: const LocalFileSystem (),
6868 );
6969
70- Future <void > copyTestProjects (
71- Uri copyTargetUri, Logger logger, Uri packageLocation, Uri sdkRoot ) async {
70+ Future <void > copyTestProjects (Uri copyTargetUri, Logger logger,
71+ Uri packageLocation, Uri sdkRoot, bool usePubWorkspace ) async {
7272 // Reuse the test projects from `pkg:native`.
7373 final testProjectsUri = packageLocation.resolve ('test_data/' );
7474 final manifestUri = testProjectsUri.resolve ('manifest.yaml' );
@@ -82,7 +82,7 @@ Future<void> copyTestProjects(
8282 .where ((e) => ! (e.pathSegments.last.startsWith ('pubspec' ) &&
8383 e.pathSegments.last.endsWith ('.yaml' )))
8484 .toList ();
85- final filesToModify = manifest
85+ final pubspecPaths = manifest
8686 .where ((e) =>
8787 e.pathSegments.last.startsWith ('pubspec' ) &&
8888 e.pathSegments.last.endsWith ('.yaml' ))
@@ -98,17 +98,7 @@ Future<void> copyTestProjects(
9898 }
9999 await sourceFile.copy (targetUri.toFilePath ());
100100 }
101- for (final pathToModify in filesToModify) {
102- final sourceFile = File .fromUri (testProjectsUri.resolveUri (pathToModify));
103- final targetUri = copyTargetUri.resolveUri (pathToModify);
104- final sourceString = await sourceFile.readAsString ();
105- final pubspec = YamlEditor (sourceString);
106- if ((loadYamlNode (sourceString) as Map )['resolution' ] != null ) {
107- pubspec.remove (['resolution' ]);
108- }
109- pubspec.update ([
110- 'dependency_overrides'
111- ], {
101+ final dependencyOverrides = {
112102 'native_assets_cli' : {
113103 'path' : sdkRoot
114104 .resolve ('third_party/pkg/native/pkgs/native_assets_cli/' )
@@ -125,10 +115,36 @@ Future<void> copyTestProjects(
125115 'record_use' : {
126116 'path' : sdkRoot.resolve ('pkg/record_use/' ).toFilePath (),
127117 },
128- });
118+ };
119+ for (final pubspecPath in pubspecPaths) {
120+ final sourceFile = File .fromUri (testProjectsUri.resolveUri (pubspecPath));
121+ final targetUri = copyTargetUri.resolveUri (pubspecPath);
122+ final sourceString = await sourceFile.readAsString ();
123+ final pubspec = YamlEditor (sourceString);
124+ if (! usePubWorkspace) {
125+ if ((loadYamlNode (sourceString) as Map )['resolution' ] != null ) {
126+ pubspec.remove (['resolution' ]);
127+ }
128+ pubspec.update (['dependency_overrides' ], dependencyOverrides);
129+ }
129130 final modifiedString = pubspec.toString ();
130131 await File .fromUri (targetUri).writeAsString (modifiedString);
131132 }
133+ if (usePubWorkspace) {
134+ final workspacePubspec = YamlEditor ('' );
135+ workspacePubspec.update ([], {
136+ 'name' : 'my_pub_workspace' ,
137+ 'environment' : {'sdk' : '>=3.7.0 <4.0.0' },
138+ 'workspace' : [
139+ for (final pubspec in pubspecPaths)
140+ if (! pubspec.toFilePath ().contains ('version_skew' ))
141+ pubspec.toFilePath ().replaceAll ('pubspec.yaml' , '' ),
142+ ],
143+ 'dependency_overrides' : dependencyOverrides,
144+ });
145+ final pubspecUri = copyTargetUri.resolve ('pubspec.yaml' );
146+ await File .fromUri (pubspecUri).writeAsString (workspacePubspec.toString ());
147+ }
132148
133149 // If we're copying `my_native_library/` we need to simulate that its
134150 // native assets are pre-built
@@ -198,6 +214,7 @@ Future<void> nativeAssetsTest(
198214 String packageUnderTest,
199215 Future <void > Function (Uri ) fun, {
200216 bool skipPubGet = false ,
217+ bool usePubWorkspace = false ,
201218}) async =>
202219 await runPackageTest (
203220 packageUnderTest,
@@ -218,6 +235,7 @@ Future<void> nativeAssetsTest(
218235 Platform .script.resolve (
219236 '../../../../third_party/pkg/native/pkgs/native_assets_builder/' ),
220237 Platform .script.resolve ('../../../../' ),
238+ usePubWorkspace,
221239 );
222240
223241Future <void > recordUseTest (
@@ -232,19 +250,22 @@ Future<void> recordUseTest(
232250 const ['drop_dylib_recording' ],
233251 Platform .script.resolve ('../../../record_use/' ),
234252 Platform .script.resolve ('../../../../' ),
253+ false ,
235254 );
236255
237256Future <void > runPackageTest (
238257 String packageUnderTest,
239258 bool skipPubGet,
240259 Future <void > Function (Uri ) fun,
241260 List <String > validPackages,
242- Uri packageLocation,
243- Uri sdkRoot
261+ Uri packageLocation,
262+ Uri sdkRoot,
263+ bool usePubWorkspace,
244264) async {
245265 assert (validPackages.contains (packageUnderTest));
246266 return await inTempDir ((tempUri) async {
247- await copyTestProjects (tempUri, logger, packageLocation, sdkRoot);
267+ await copyTestProjects (
268+ tempUri, logger, packageLocation, sdkRoot, usePubWorkspace);
248269 final packageUri = tempUri.resolve ('$packageUnderTest /' );
249270 if (! skipPubGet) {
250271 await runPubGet (workingDirectory: packageUri, logger: logger);
0 commit comments