@@ -71,10 +71,6 @@ class Entrypoint {
71
71
/// the network.
72
72
final SystemCache cache;
73
73
74
- /// Whether to create and symlink a "packages" directory containing links to
75
- /// the installed packages.
76
- final bool _packageSymlinks;
77
-
78
74
/// Whether this entrypoint is in memory only, as opposed to representing a
79
75
/// real directory on disk.
80
76
final bool _inMemory;
@@ -119,7 +115,7 @@ class Entrypoint {
119
115
PackageGraph _packageGraph;
120
116
121
117
/// The path to the entrypoint's "packages" directory.
122
- String get packagesDir => root.path ('packages' );
118
+ String get packagesPath => root.path ('packages' );
123
119
124
120
/// The path to the entrypoint's ".packages" file.
125
121
String get packagesFile => root.path ('.packages' );
@@ -141,29 +137,21 @@ class Entrypoint {
141
137
String get _snapshotPath => root.path ('.pub' , 'bin' );
142
138
143
139
/// Loads the entrypoint from a package at [rootDir] .
144
- ///
145
- /// If [packageSymlinks] is `true` , this will create a "packages" directory
146
- /// with symlinks to the installed packages. This directory will be symlinked
147
- /// into any directory that might contain an entrypoint.
148
- Entrypoint (String rootDir, SystemCache cache, {bool packageSymlinks: true ,
149
- this .isGlobal: false })
140
+ Entrypoint (String rootDir, SystemCache cache, {this .isGlobal: false })
150
141
: root = new Package .load (null , rootDir, cache.sources),
151
142
cache = cache,
152
- _packageSymlinks = packageSymlinks,
153
143
_inMemory = false ;
154
144
155
145
/// Creates an entrypoint given package and lockfile objects.
156
146
Entrypoint .inMemory (this .root, this ._lockFile, this .cache,
157
147
{this .isGlobal: false })
158
- : _packageSymlinks = false ,
159
- _inMemory = true ;
148
+ : _inMemory = true ;
160
149
161
150
/// Creates an entrypoint given a package and a [solveResult] , from which the
162
151
/// package graph and lockfile will be computed.
163
152
Entrypoint .fromSolveResult (this .root, this .cache, SolveResult solveResult,
164
153
{this .isGlobal: false })
165
- : _packageSymlinks = false ,
166
- _inMemory = true {
154
+ : _inMemory = true {
167
155
_packageGraph = new PackageGraph .fromSolveResult (this , solveResult);
168
156
_lockFile = _packageGraph.lockFile;
169
157
}
@@ -186,9 +174,14 @@ class Entrypoint {
186
174
/// If [precompile] is `true` (the default), this snapshots dependencies'
187
175
/// executables and runs transformers on transformed dependencies.
188
176
///
177
+ /// If [packagesDir] is `true` , this will create "packages" directory with
178
+ /// symlinks to the installed packages. This directory will be symlinked into
179
+ /// any directory that might contain an entrypoint.
180
+ ///
189
181
/// Updates [lockFile] and [packageRoot] accordingly.
190
182
Future acquireDependencies (SolveType type, {List <String > useLatest,
191
- bool dryRun: false , bool precompile: true }) async {
183
+ bool dryRun: false , bool precompile: true , bool packagesDir: false })
184
+ async {
192
185
var result = await resolveVersions (type, cache, root,
193
186
lockFile: lockFile, useLatest: useLatest);
194
187
if (! result.succeeded) throw result.error;
@@ -201,17 +194,18 @@ class Entrypoint {
201
194
}
202
195
203
196
// Install the packages and maybe link them into the entrypoint.
204
- if (_packageSymlinks ) {
205
- cleanDir (packagesDir );
197
+ if (packagesDir ) {
198
+ cleanDir (packagesPath );
206
199
} else {
207
- deleteEntry (packagesDir );
200
+ deleteEntry (packagesPath );
208
201
}
209
202
210
- await Future .wait (result.packages.map (_get));
203
+ await Future .wait (result.packages
204
+ .map ((id) => _get (id, packagesDir: packagesDir)));
211
205
_saveLockFile (result);
212
206
213
- if (_packageSymlinks ) _linkSelf ();
214
- _linkOrDeleteSecondaryPackageDirs ();
207
+ if (packagesDir ) _linkSelf ();
208
+ _linkOrDeleteSecondaryPackageDirs (packagesDir : packagesDir );
215
209
216
210
result.summarizeChanges (type, dryRun: dryRun);
217
211
@@ -449,18 +443,18 @@ class Entrypoint {
449
443
/// This automatically downloads the package to the system-wide cache as well
450
444
/// if it requires network access to retrieve (specifically, if the package's
451
445
/// source is a [CachedSource] ).
452
- Future _get (PackageId id) async {
446
+ Future _get (PackageId id, { bool packagesDir : false } ) async {
453
447
if (id.isRoot) return ;
454
448
455
449
var source = cache.source (id.source);
456
- if (! _packageSymlinks ) {
450
+ if (! packagesDir ) {
457
451
if (source is CachedSource ) await source.downloadToSystemCache (id);
458
452
return ;
459
453
}
460
454
461
- var packageDir = p.join (packagesDir , id.name);
462
- if (entryExists (packageDir )) deleteEntry (packageDir );
463
- await source.get (id, packageDir );
455
+ var packagePath = p.join (packagesPath , id.name);
456
+ if (entryExists (packagePath )) deleteEntry (packagePath );
457
+ await source.get (id, packagePath );
464
458
}
465
459
466
460
/// Throws a [DataError] if the `.packages` file doesn't exist or if it's
@@ -654,42 +648,47 @@ class Entrypoint {
654
648
/// Creates a self-referential symlink in the `packages` directory that allows
655
649
/// a package to import its own files using `package:` .
656
650
void _linkSelf () {
657
- var linkPath = p.join (packagesDir , root.name);
651
+ var linkPath = p.join (packagesPath , root.name);
658
652
// Create the symlink if it doesn't exist.
659
653
if (entryExists (linkPath)) return ;
660
- ensureDir (packagesDir );
654
+ ensureDir (packagesPath );
661
655
createPackageSymlink (root.name, root.dir, linkPath,
662
656
isSelfLink: true , relative: true );
663
657
}
664
658
665
- /// If [packageSymlinks ] is true, add "packages" directories to the whitelist
666
- /// of directories that may contain Dart entrypoints.
659
+ /// If [packagesDir ] is true, add "packages" directories to the whitelist of
660
+ /// directories that may contain Dart entrypoints.
667
661
///
668
662
/// Otherwise, delete any "packages" directories in the whitelist of
669
663
/// directories that may contain Dart entrypoints.
670
- void _linkOrDeleteSecondaryPackageDirs () {
664
+ void _linkOrDeleteSecondaryPackageDirs ({ bool packagesDir : false } ) {
671
665
// Only the main "bin" directory gets a "packages" directory, not its
672
666
// subdirectories.
673
667
var binDir = root.path ('bin' );
674
- if (dirExists (binDir)) _linkOrDeleteSecondaryPackageDir (binDir);
668
+ if (dirExists (binDir)) {
669
+ _linkOrDeleteSecondaryPackageDir (binDir, packagesDir: packagesDir);
670
+ }
675
671
676
672
// The others get "packages" directories in subdirectories too.
677
673
for (var dir in ['benchmark' , 'example' , 'test' , 'tool' , 'web' ]) {
678
- _linkOrDeleteSecondaryPackageDirsRecursively (root.path (dir));
674
+ _linkOrDeleteSecondaryPackageDirsRecursively (root.path (dir),
675
+ packagesDir: packagesDir);
679
676
}
680
677
}
681
678
682
- /// If [packageSymlinks ] is true, creates a symlink to the "packages"
683
- /// directory in [dir] and all its subdirectories.
679
+ /// If [packagesDir ] is true, creates a symlink to the "packages" directory in
680
+ /// [dir] and all its subdirectories.
684
681
///
685
682
/// Otherwise, deletes any "packages" directories in [dir] and all its
686
683
/// subdirectories.
687
- void _linkOrDeleteSecondaryPackageDirsRecursively (String dir) {
684
+ void _linkOrDeleteSecondaryPackageDirsRecursively (String dir,
685
+ {bool packagesDir: false }) {
688
686
if (! dirExists (dir)) return ;
689
- _linkOrDeleteSecondaryPackageDir (dir);
690
- _listDirWithoutPackages (dir)
691
- .where (dirExists)
692
- .forEach (_linkOrDeleteSecondaryPackageDir);
687
+ _linkOrDeleteSecondaryPackageDir (dir, packagesDir: packagesDir);
688
+ for (var subdir in _listDirWithoutPackages (dir)) {
689
+ if (! dirExists (subdir)) continue ;
690
+ _linkOrDeleteSecondaryPackageDir (subdir, packagesDir: packagesDir);
691
+ }
693
692
}
694
693
695
694
// TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed.
@@ -705,13 +704,13 @@ class Entrypoint {
705
704
});
706
705
}
707
706
708
- /// If [packageSymlinks ] is true, creates a symlink to the "packages"
709
- /// directory in [dir] .
707
+ /// If [packagesDir ] is true, creates a symlink to the "packages" directory in
708
+ /// [dir] .
710
709
///
711
710
/// Otherwise, deletes a "packages" directories in [dir] if one exists.
712
- void _linkOrDeleteSecondaryPackageDir (String dir) {
711
+ void _linkOrDeleteSecondaryPackageDir (String dir, { bool packagesDir : false } ) {
713
712
var symlink = p.join (dir, 'packages' );
714
713
if (entryExists (symlink)) deleteEntry (symlink);
715
- if (_packageSymlinks ) createSymlink (packagesDir , symlink, relative: true );
714
+ if (packagesDir ) createSymlink (packagesPath , symlink, relative: true );
716
715
}
717
716
}
0 commit comments