OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:convert" show JSON; | 7 import "dart:convert" show JSON; |
8 import "package:path/path.dart" as p; | 8 import "package:path/path.dart" as p; |
9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
10 | 10 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // | 213 // |
214 // The combinations covers most configurations of implicit and explicit | 214 // The combinations covers most configurations of implicit and explicit |
215 // package configurations over both file: and http: file sources. | 215 // package configurations over both file: and http: file sources. |
216 // It also specifies the expected values of the following for a VM | 216 // It also specifies the expected values of the following for a VM |
217 // run in that configuration. | 217 // run in that configuration. |
218 // | 218 // |
219 // * `Process.packageRoot` | 219 // * `Process.packageRoot` |
220 // * `Process.packageConfig` | 220 // * `Process.packageConfig` |
221 // * `Isolate.packageRoot` | 221 // * `Isolate.packageRoot` |
222 // * `Isolate.packageRoot` | 222 // * `Isolate.packageRoot` |
223 // * `Isolate.resolvePacakgeUri` of various inputs. | 223 // * `Isolate.resolvePackageUri` of various inputs. |
224 // * A variable defined in a library loaded using a `package:` URI. | 224 // * A variable defined in a library loaded using a `package:` URI. |
225 // | 225 // |
226 // The configurations all have URIs as `root`, `config` and `mainFile` strings, | 226 // The configurations all have URIs as `root`, `config` and `mainFile` strings, |
227 // have empty argument lists and `mainFile` points to the the `main.dart` file. | 227 // have empty argument lists and `mainFile` points to the the `main.dart` file. |
228 void createConfigurations() { | 228 void createConfigurations() { |
229 add(String description, String mainDir, {String root, String config, | 229 add(String description, String mainDir, {String root, String config, |
230 Map file, Map http, Map expect}) { | 230 Map file, Map http, Map expect}) { |
231 var id = freshName("conf"); | 231 var id = freshName("conf"); |
232 | 232 |
233 file ??= {}; | 233 file ??= {}; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 fixPaths(file); | 285 fixPaths(file); |
286 fixPaths(http); | 286 fixPaths(http); |
287 // These expectations are default. If not overridden the value will be | 287 // These expectations are default. If not overridden the value will be |
288 // expected to be null. That is, you can't avoid testing the actual | 288 // expected to be null. That is, you can't avoid testing the actual |
289 // value of these, you can only change what value to expect. | 289 // value of these, you can only change what value to expect. |
290 // For values not included here (commented out), the result is not tested | 290 // For values not included here (commented out), the result is not tested |
291 // unless a value (maybe null) is provided. | 291 // unless a value (maybe null) is provided. |
292 fixPaths(expect); | 292 fixPaths(expect); |
293 | 293 |
294 expect = { | 294 expect = { |
295 "pconf": null, | 295 "pconf": null, |
296 "proot": null, | 296 "proot": null, |
297 "iconf": null, | 297 "iconf": null, |
298 "iroot": null, | 298 "iroot": null, |
299 // "foo": null, | 299 // "foo": null, |
300 "foo/": null, | 300 "foo/": null, |
301 "foo/bar": null, | 301 "foo/bar": null, |
302 "foo.x": "qux", | 302 "foo.x": "qux", |
| 303 "bar/bar": null, |
| 304 "relative": "relative/path", |
| 305 "nonpkg": "http://example.org/file" |
303 }..addAll(expect ?? const {}); | 306 }..addAll(expect ?? const {}); |
304 | 307 |
305 // Add http files to the http server. | 308 // Add http files to the http server. |
306 if (http.isNotEmpty) { | 309 if (http.isNotEmpty) { |
307 httpFiles[id] = http; | 310 httpFiles[id] = http; |
308 } | 311 } |
309 // Add file files to the file system. | 312 // Add file files to the file system. |
310 if (file.isNotEmpty) { | 313 if (file.isNotEmpty) { |
311 createFiles(fileRoot, id, file); | 314 createFiles(fileRoot, id, file); |
312 } | 315 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 addScheme("no resolution", | 349 addScheme("no resolution", |
347 "%$scheme/", | 350 "%$scheme/", |
348 files: {}, | 351 files: {}, |
349 expect: (scheme == "file") ? { | 352 expect: (scheme == "file") ? { |
350 "foo.x": null | 353 "foo.x": null |
351 } : { | 354 } : { |
352 "iroot": "%http/packages/", | 355 "iroot": "%http/packages/", |
353 "foo/": "%http/packages/foo/", | 356 "foo/": "%http/packages/foo/", |
354 "foo/bar": "%http/packages/foo/bar", | 357 "foo/bar": "%http/packages/foo/bar", |
355 "foo.x": null, | 358 "foo.x": null, |
| 359 "bar/bar": "%http/packages/bar/bar", |
356 }); | 360 }); |
357 } | 361 } |
358 | 362 |
359 { | 363 { |
360 // No parameters, no .packages files, | 364 // No parameters, no .packages files, |
361 // packages/ dir exists and is detected. | 365 // packages/ dir exists and is detected. |
362 var files = {"packages": fooPackage}; | 366 var files = {"packages": fooPackage}; |
363 addScheme("implicit packages dir","%$scheme/", | 367 addScheme("implicit packages dir","%$scheme/", |
364 files: files, | 368 files: files, |
365 expect: { | 369 expect: { |
366 "iroot": "%$scheme/packages/", | 370 "iroot": "%$scheme/packages/", |
367 "foo/": "%$scheme/packages/foo/", | 371 "foo/": "%$scheme/packages/foo/", |
368 "foo/bar": "%$scheme/packages/foo/bar", | 372 "foo/bar": "%$scheme/packages/foo/bar", |
| 373 "bar/bar": "%$scheme/packages/bar/bar", |
369 }); | 374 }); |
370 } | 375 } |
371 | 376 |
372 { | 377 { |
373 // No parameters, no .packages files in current dir, but one in parent, | 378 // No parameters, no .packages files in current dir, but one in parent, |
374 // packages/ dir exists and is used. | 379 // packages/ dir exists and is used. |
375 // | 380 // |
376 // Should not detect the .packages file in parent directory. | 381 // Should not detect the .packages file in parent directory. |
377 // That file is empty, so if it is used, the system cannot resolve "foo". | 382 // That file is empty, so if it is used, the system cannot resolve "foo". |
378 var files = {"sub": {"packages": fooPackage}, | 383 var files = {"sub": {"packages": fooPackage}, |
379 ".packages": ""}; | 384 ".packages": ""}; |
380 addScheme("implicit packages dir overrides parent .packages", | 385 addScheme("implicit packages dir overrides parent .packages", |
381 "%$scheme/sub/", | 386 "%$scheme/sub/", |
382 files: files, | 387 files: files, |
383 expect: { | 388 expect: { |
384 "iroot": "%$scheme/sub/packages/", | 389 "iroot": "%$scheme/sub/packages/", |
385 "foo/": "%$scheme/sub/packages/foo/", | 390 "foo/": "%$scheme/sub/packages/foo/", |
386 "foo/bar": "%$scheme/sub/packages/foo/bar", | 391 "foo/bar": "%$scheme/sub/packages/foo/bar", |
387 // "foo.x": "qux", // Blocked by issue http://dartbug.com/26482 | 392 // "foo.x": "qux", // Blocked by issue http://dartbug.com/26482 |
| 393 "bar/bar": "%$scheme/sub/packages/bar/bar", |
388 }); | 394 }); |
389 } | 395 } |
390 | 396 |
391 { | 397 { |
392 // No parameters, a .packages file next to entry is found and used. | 398 // No parameters, a .packages file next to entry is found and used. |
393 // A packages/ directory is ignored. | 399 // A packages/ directory is ignored. |
394 var files = {".packages": "foo:pkgs/foo/", | 400 var files = {".packages": "foo:pkgs/foo/", |
395 "packages": {}, | 401 "packages": {}, |
396 "pkgs": fooPackage}; | 402 "pkgs": fooPackage}; |
397 addScheme("implicit .packages file", "%$scheme/", | 403 addScheme("implicit .packages file", "%$scheme/", |
(...skipping 16 matching lines...) Expand all Loading... |
414 files: files, | 420 files: files, |
415 expect: (scheme == "file") ? { | 421 expect: (scheme == "file") ? { |
416 "iconf": "%file/.packages", | 422 "iconf": "%file/.packages", |
417 "foo/": "%file/pkgs/foo/", | 423 "foo/": "%file/pkgs/foo/", |
418 "foo/bar": "%file/pkgs/foo/bar", | 424 "foo/bar": "%file/pkgs/foo/bar", |
419 } : { | 425 } : { |
420 "iroot": "%http/sub/packages/", | 426 "iroot": "%http/sub/packages/", |
421 "foo/": "%http/sub/packages/foo/", | 427 "foo/": "%http/sub/packages/foo/", |
422 "foo/bar": "%http/sub/packages/foo/bar", | 428 "foo/bar": "%http/sub/packages/foo/bar", |
423 "foo.x": null, | 429 "foo.x": null, |
| 430 "bar/bar": "%http/sub/packages/bar/bar", |
424 }); | 431 }); |
425 } | 432 } |
426 | 433 |
427 { | 434 { |
428 // Specified package root that doesn't exist. | 435 // Specified package root that doesn't exist. |
429 // Ignores existing .packages file and packages/ dir. | 436 // Ignores existing .packages file and packages/ dir. |
430 addScheme("explicit root not there", | 437 addScheme("explicit root not there", |
431 "%$scheme/", | 438 "%$scheme/", |
432 files: {"packages": fooPackage, | 439 files: {"packages": fooPackage, |
433 ".packages": "foo:%$scheme/packages/"}, | 440 ".packages": "foo:%$scheme/packages/"}, |
434 root: "%$scheme/notthere/", | 441 root: "%$scheme/notthere/", |
435 expect: { | 442 expect: { |
436 "proot": "%$scheme/notthere/", | 443 "proot": "%$scheme/notthere/", |
437 "iroot": "%$scheme/notthere/", | 444 "iroot": "%$scheme/notthere/", |
438 "foo/": "%$scheme/notthere/foo/", | 445 "foo/": "%$scheme/notthere/foo/", |
439 "foo/bar": "%$scheme/notthere/foo/bar", | 446 "foo/bar": "%$scheme/notthere/foo/bar", |
440 "foo.x": null, | 447 "foo.x": null, |
| 448 "bar/bar": "%$scheme/notthere/bar/bar", |
441 }); | 449 }); |
442 } | 450 } |
443 | 451 |
444 { | 452 { |
445 // Specified package config that doesn't exist. | 453 // Specified package config that doesn't exist. |
446 // Ignores existing .packages file and packages/ dir. | 454 // Ignores existing .packages file and packages/ dir. |
447 addScheme("explicit config not there", | 455 addScheme("explicit config not there", |
448 "%$scheme/", | 456 "%$scheme/", |
449 files: {".packages": "foo:packages/foo/", | 457 files: {".packages": "foo:packages/foo/", |
450 "packages": fooPackage}, | 458 "packages": fooPackage}, |
(...skipping 14 matching lines...) Expand all Loading... |
465 "packages": {}, | 473 "packages": {}, |
466 "pkgs": fooPackage}; | 474 "pkgs": fooPackage}; |
467 addScheme("explicit package root, no slash", "%$scheme/", | 475 addScheme("explicit package root, no slash", "%$scheme/", |
468 files: files, | 476 files: files, |
469 root: "%$scheme/pkgs", | 477 root: "%$scheme/pkgs", |
470 expect: { | 478 expect: { |
471 "proot": "%$scheme/pkgs/", | 479 "proot": "%$scheme/pkgs/", |
472 "iroot": "%$scheme/pkgs/", | 480 "iroot": "%$scheme/pkgs/", |
473 "foo/": "%$scheme/pkgs/foo/", | 481 "foo/": "%$scheme/pkgs/foo/", |
474 "foo/bar": "%$scheme/pkgs/foo/bar", | 482 "foo/bar": "%$scheme/pkgs/foo/bar", |
| 483 "bar/bar": "%$scheme/pkgs/bar/bar", |
475 }); | 484 }); |
476 } | 485 } |
477 | 486 |
478 { | 487 { |
479 // Specified package root with trailing slash. | 488 // Specified package root with trailing slash. |
480 var files = {".packages": "foo:packages/foo/", | 489 var files = {".packages": "foo:packages/foo/", |
481 "packages": {}, | 490 "packages": {}, |
482 "pkgs": fooPackage}; | 491 "pkgs": fooPackage}; |
483 addScheme("explicit package root, slash", "%$scheme/", | 492 addScheme("explicit package root, slash", "%$scheme/", |
484 files: files, | 493 files: files, |
485 root: "%$scheme/pkgs", | 494 root: "%$scheme/pkgs", |
486 expect: { | 495 expect: { |
487 "proot": "%$scheme/pkgs/", | 496 "proot": "%$scheme/pkgs/", |
488 "iroot": "%$scheme/pkgs/", | 497 "iroot": "%$scheme/pkgs/", |
489 "foo/": "%$scheme/pkgs/foo/", | 498 "foo/": "%$scheme/pkgs/foo/", |
490 "foo/bar": "%$scheme/pkgs/foo/bar", | 499 "foo/bar": "%$scheme/pkgs/foo/bar", |
| 500 "bar/bar": "%$scheme/pkgs/bar/bar", |
491 }); | 501 }); |
492 } | 502 } |
493 | 503 |
494 { | 504 { |
495 // Specified package config. | 505 // Specified package config. |
496 var files = {".packages": "foo:packages/foo/", | 506 var files = {".packages": "foo:packages/foo/", |
497 "packages": {}, | 507 "packages": {}, |
498 ".pkgs": "foo:pkgs/foo/", | 508 ".pkgs": "foo:pkgs/foo/", |
499 "pkgs": fooPackage}; | 509 "pkgs": fooPackage}; |
500 addScheme("explicit package config file", "%$scheme/", | 510 addScheme("explicit package config file", "%$scheme/", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 (entryScheme == "file" ? files : https)["main"] = testMain; | 550 (entryScheme == "file" ? files : https)["main"] = testMain; |
541 (pkgScheme == "file" ? files : https)["pkgs"] = fooPackage; | 551 (pkgScheme == "file" ? files : https)["pkgs"] = fooPackage; |
542 add("$pkgScheme pkg/$entryScheme main", "%$entryScheme/", | 552 add("$pkgScheme pkg/$entryScheme main", "%$entryScheme/", |
543 file: files, http: https, | 553 file: files, http: https, |
544 root: "%$pkgScheme/pkgs/", | 554 root: "%$pkgScheme/pkgs/", |
545 expect: { | 555 expect: { |
546 "proot": "%$pkgScheme/pkgs/", | 556 "proot": "%$pkgScheme/pkgs/", |
547 "iroot": "%$pkgScheme/pkgs/", | 557 "iroot": "%$pkgScheme/pkgs/", |
548 "foo/": "%$pkgScheme/pkgs/foo/", | 558 "foo/": "%$pkgScheme/pkgs/foo/", |
549 "foo/bar": "%$pkgScheme/pkgs/foo/bar", | 559 "foo/bar": "%$pkgScheme/pkgs/foo/bar", |
| 560 "bar/bar": "%$pkgScheme/pkgs/bar/bar", |
550 "foo.x": "qux", | 561 "foo.x": "qux", |
551 }); | 562 }); |
552 } | 563 } |
553 // Package config. The configuration file may also be on either source. | 564 // Package config. The configuration file may also be on either source. |
554 for (var configScheme in const ["file", "http"]) { | 565 for (var configScheme in const ["file", "http"]) { |
555 // Don't do the boring stuff! | 566 // Don't do the boring stuff! |
556 if (entryScheme == configScheme && entryScheme == pkgScheme) continue; | 567 if (entryScheme == configScheme && entryScheme == pkgScheme) continue; |
557 // Package config, packages and entry point not all on same scheme. | 568 // Package config, packages and entry point not all on same scheme. |
558 var files = {}; | 569 var files = {}; |
559 var https = {}; | 570 var https = {}; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 String platformRoot = await Platform.packageRoot; | 654 String platformRoot = await Platform.packageRoot; |
644 String platformConfig = await Platform.packageConfig; | 655 String platformConfig = await Platform.packageConfig; |
645 Directory cwd = Directory.current; | 656 Directory cwd = Directory.current; |
646 Uri script = Platform.script; | 657 Uri script = Platform.script; |
647 Uri isolateRoot = await Isolate.packageRoot; | 658 Uri isolateRoot = await Isolate.packageRoot; |
648 Uri isolateConfig = await Isolate.packageConfig; | 659 Uri isolateConfig = await Isolate.packageConfig; |
649 Uri base = Uri.base; | 660 Uri base = Uri.base; |
650 Uri res1 = await Isolate.resolvePackageUri(Uri.parse("package:foo")); | 661 Uri res1 = await Isolate.resolvePackageUri(Uri.parse("package:foo")); |
651 Uri res2 = await Isolate.resolvePackageUri(Uri.parse("package:foo/")); | 662 Uri res2 = await Isolate.resolvePackageUri(Uri.parse("package:foo/")); |
652 Uri res3 = await Isolate.resolvePackageUri(Uri.parse("package:foo/bar")); | 663 Uri res3 = await Isolate.resolvePackageUri(Uri.parse("package:foo/bar")); |
| 664 Uri res4 = await Isolate.resolvePackageUri(Uri.parse("package:bar/bar")); |
| 665 Uri res5 = await Isolate.resolvePackageUri(Uri.parse("relative/path")); |
| 666 Uri res6 = await Isolate.resolvePackageUri( |
| 667 Uri.parse("http://example.org/file")); |
653 String fooX = await foo | 668 String fooX = await foo |
654 .loadLibrary() | 669 .loadLibrary() |
655 .timeout(const Duration(seconds: 1)) | 670 .timeout(const Duration(seconds: 1)) |
656 .then((_) => foo.x, onError: (_) => null); | 671 .then((_) => foo.x, onError: (_) => null); |
657 print(JSON.encode({ | 672 print(JSON.encode({ |
658 "cwd": cwd.path, | 673 "cwd": cwd.path, |
659 "base": base?.toString(), | 674 "base": base?.toString(), |
660 "script": script?.toString(), | 675 "script": script?.toString(), |
661 "proot": platformRoot, | 676 "proot": platformRoot, |
662 "pconf": platformConfig, | 677 "pconf": platformConfig, |
663 "iroot" : isolateRoot?.toString(), | 678 "iroot" : isolateRoot?.toString(), |
664 "iconf" : isolateConfig?.toString(), | 679 "iconf" : isolateConfig?.toString(), |
665 "foo": res1?.toString(), | 680 "foo": res1?.toString(), |
666 "foo/": res2?.toString(), | 681 "foo/": res2?.toString(), |
667 "foo/bar": res3?.toString(), | 682 "foo/bar": res3?.toString(), |
668 "foo.x": fooX?.toString(), | 683 "foo.x": fooX?.toString(), |
| 684 "bar/bar": res4?.toString(), |
| 685 "relative": res5?.toString(), |
| 686 "nonpkg": res6?.toString(), |
669 })); | 687 })); |
670 } | 688 } |
671 """; | 689 """; |
672 | 690 |
673 /// Script that spawns a new Isolate using Isolate.spawnUri. | 691 /// Script that spawns a new Isolate using Isolate.spawnUri. |
674 /// | 692 /// |
675 /// Takes URI of target isolate, package config, package root and | 693 /// Takes URI of target isolate, package config, package root and |
676 /// automatic package resolution-flag parameters as command line arguments. | 694 /// automatic package resolution-flag parameters as command line arguments. |
677 /// Any further arguments are forwarded to the spawned isolate. | 695 /// Any further arguments are forwarded to the spawned isolate. |
678 const String spawnUriMain = """ | 696 const String spawnUriMain = """ |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 void insertFileAt(Map file, Map http, | 984 void insertFileAt(Map file, Map http, |
967 String path, String name, String content) { | 985 String path, String name, String content) { |
968 var parts = path.split('/').toList(); | 986 var parts = path.split('/').toList(); |
969 var dir = (parts[0] == "%file") ? file : http; | 987 var dir = (parts[0] == "%file") ? file : http; |
970 for (var i = 1; i < parts.length - 1; i++) { | 988 for (var i = 1; i < parts.length - 1; i++) { |
971 var entry = parts[i]; | 989 var entry = parts[i]; |
972 dir = dir[entry] ?? (dir[entry] = {}); | 990 dir = dir[entry] ?? (dir[entry] = {}); |
973 } | 991 } |
974 dir[name] = content; | 992 dir[name] = content; |
975 } | 993 } |
OLD | NEW |