OLD | NEW |
1 library pub.entrypoint; | 1 library pub.entrypoint; |
2 import 'dart:async'; | 2 import 'dart:async'; |
3 import 'package:path/path.dart' as path; | 3 import 'package:path/path.dart' as path; |
4 import 'package:barback/barback.dart'; | 4 import 'package:barback/barback.dart'; |
5 import 'barback/asset_environment.dart'; | 5 import 'barback/asset_environment.dart'; |
6 import 'io.dart'; | 6 import 'io.dart'; |
7 import 'lock_file.dart'; | 7 import 'lock_file.dart'; |
8 import 'log.dart' as log; | 8 import 'log.dart' as log; |
9 import 'package.dart'; | 9 import 'package.dart'; |
10 import 'package_graph.dart'; | 10 import 'package_graph.dart'; |
(...skipping 22 matching lines...) Expand all Loading... |
33 _lockFile = new LockFile.empty(); | 33 _lockFile = new LockFile.empty(); |
34 } else { | 34 } else { |
35 _lockFile = new LockFile.load(lockFilePath, cache.sources); | 35 _lockFile = new LockFile.load(lockFilePath, cache.sources); |
36 } | 36 } |
37 return _lockFile; | 37 return _lockFile; |
38 } | 38 } |
39 String get pubspecPath => path.join(root.dir, 'pubspec.yaml'); | 39 String get pubspecPath => path.join(root.dir, 'pubspec.yaml'); |
40 String get lockFilePath => path.join(root.dir, 'pubspec.lock'); | 40 String get lockFilePath => path.join(root.dir, 'pubspec.lock'); |
41 Future acquireDependencies(SolveType type, {List<String> useLatest, | 41 Future acquireDependencies(SolveType type, {List<String> useLatest, |
42 bool dryRun: false}) { | 42 bool dryRun: false}) { |
43 return syncFuture(() { | 43 final completer0 = new Completer(); |
44 return resolveVersions( | 44 scheduleMicrotask(() { |
45 type, | 45 try { |
46 cache.sources, | 46 resolveVersions( |
47 root, | 47 type, |
48 lockFile: lockFile, | 48 cache.sources, |
49 useLatest: useLatest); | 49 root, |
50 }).then((result) { | 50 lockFile: lockFile, |
51 if (!result.succeeded) throw result.error; | 51 useLatest: useLatest).then((x0) { |
52 result.showReport(type); | 52 try { |
53 if (dryRun) { | 53 var result = x0; |
54 result.summarizeChanges(type, dryRun: dryRun); | 54 join0() { |
55 return null; | 55 result.showReport(type); |
| 56 join1() { |
| 57 join2() { |
| 58 Future.wait(result.packages.map(_get)).then((x1) { |
| 59 try { |
| 60 var ids = x1; |
| 61 _saveLockFile(ids); |
| 62 join3() { |
| 63 _linkOrDeleteSecondaryPackageDirs(); |
| 64 result.summarizeChanges(type, dryRun: dryRun); |
| 65 loadPackageGraph(result).then((x2) { |
| 66 try { |
| 67 var packageGraph = x2; |
| 68 packageGraph.loadTransformerCache().clearIfOutdated( |
| 69 result.changedPackages); |
| 70 completer0.complete( |
| 71 precompileDependencies(changed: result.changedPa
ckages).then(((_) { |
| 72 return precompileExecutables( |
| 73 changed: result.changedPackages); |
| 74 })).catchError(((error, stackTrace) { |
| 75 log.exception(error, stackTrace); |
| 76 }))); |
| 77 } catch (e2) { |
| 78 completer0.completeError(e2); |
| 79 } |
| 80 }, onError: (e3) { |
| 81 completer0.completeError(e3); |
| 82 }); |
| 83 } |
| 84 if (_packageSymlinks) { |
| 85 _linkSelf(); |
| 86 join3(); |
| 87 } else { |
| 88 join3(); |
| 89 } |
| 90 } catch (e1) { |
| 91 completer0.completeError(e1); |
| 92 } |
| 93 }, onError: (e4) { |
| 94 completer0.completeError(e4); |
| 95 }); |
| 96 } |
| 97 if (_packageSymlinks) { |
| 98 cleanDir(packagesDir); |
| 99 join2(); |
| 100 } else { |
| 101 deleteEntry(packagesDir); |
| 102 join2(); |
| 103 } |
| 104 } |
| 105 if (dryRun) { |
| 106 result.summarizeChanges(type, dryRun: dryRun); |
| 107 completer0.complete(null); |
| 108 } else { |
| 109 join1(); |
| 110 } |
| 111 } |
| 112 if (!result.succeeded) { |
| 113 completer0.completeError(result.error); |
| 114 } else { |
| 115 join0(); |
| 116 } |
| 117 } catch (e0) { |
| 118 completer0.completeError(e0); |
| 119 } |
| 120 }, onError: (e5) { |
| 121 completer0.completeError(e5); |
| 122 }); |
| 123 } catch (e6) { |
| 124 completer0.completeError(e6); |
56 } | 125 } |
57 if (_packageSymlinks) { | 126 }); |
58 cleanDir(packagesDir); | 127 return completer0.future; |
59 } else { | 128 } |
60 deleteEntry(packagesDir); | 129 Future precompileDependencies({Iterable<String> changed}) { |
| 130 final completer0 = new Completer(); |
| 131 scheduleMicrotask(() { |
| 132 try { |
| 133 join0() { |
| 134 loadPackageGraph().then((x0) { |
| 135 try { |
| 136 var graph = x0; |
| 137 var depsDir = path.join('.pub', 'deps', 'debug'); |
| 138 var dependenciesToPrecompile = |
| 139 graph.packages.values.where(((package) { |
| 140 if (package.pubspec.transformers.isEmpty) return false; |
| 141 if (graph.isPackageMutable(package.name)) return false; |
| 142 if (!dirExists(path.join(depsDir, package.name))) return true; |
| 143 if (changed == null) return true; |
| 144 return overlaps( |
| 145 graph.transitiveDependencies( |
| 146 package.name).map((package) => package.name).toSet(), |
| 147 changed); |
| 148 })).map(((package) => package.name)).toSet(); |
| 149 log.fine( |
| 150 "dependencies to precompile: ${dependenciesToPrecompile}"); |
| 151 log.fine("changed: ${changed}"); |
| 152 join1() { |
| 153 log.progress("Precompiling dependencies", (() { |
| 154 final completer0 = new Completer(); |
| 155 scheduleMicrotask(() { |
| 156 try { |
| 157 var packagesToLoad = unionAll( |
| 158 dependenciesToPrecompile.map( |
| 159 graph.transitiveDependencies)).map(((package) => p
ackage.name)).toSet(); |
| 160 AssetEnvironment.create( |
| 161 this, |
| 162 BarbackMode.DEBUG, |
| 163 packages: packagesToLoad, |
| 164 useDart2JS: false).then((x0) { |
| 165 try { |
| 166 var environment = x0; |
| 167 environment.barback.errors.listen(((_) {})); |
| 168 var it0 = dependenciesToPrecompile.iterator; |
| 169 break0(x4) { |
| 170 environment.barback.getAllAssets().then((x1) { |
| 171 try { |
| 172 var assets = x1; |
| 173 waitAndPrintErrors(assets.map(((asset) { |
| 174 final completer0 = new Completer(); |
| 175 scheduleMicrotask(() { |
| 176 try { |
| 177 join0() { |
| 178 var destPath = |
| 179 path.join(depsDir, asset.id.package,
path.fromUri(asset.id.path)); |
| 180 ensureDir(path.dirname(destPath)); |
| 181 createFileFromStream( |
| 182 asset.read(), |
| 183 destPath).then((x0) { |
| 184 try { |
| 185 x0; |
| 186 completer0.complete(null); |
| 187 } catch (e0) { |
| 188 completer0.completeError(e0); |
| 189 } |
| 190 }, onError: (e1) { |
| 191 completer0.completeError(e1); |
| 192 }); |
| 193 } |
| 194 if (!dependenciesToPrecompile.contains( |
| 195 asset.id.package)) { |
| 196 completer0.complete(null); |
| 197 } else { |
| 198 join0(); |
| 199 } |
| 200 } catch (e2) { |
| 201 completer0.completeError(e2); |
| 202 } |
| 203 }); |
| 204 return completer0.future; |
| 205 }))).then((x2) { |
| 206 try { |
| 207 x2; |
| 208 log.message( |
| 209 "Precompiled " + |
| 210 toSentence(ordered(dependenciesToPre
compile).map(log.bold)) + |
| 211 "."); |
| 212 completer0.complete(null); |
| 213 } catch (e2) { |
| 214 completer0.completeError(e2); |
| 215 } |
| 216 }, onError: (e3) { |
| 217 completer0.completeError(e3); |
| 218 }); |
| 219 } catch (e1) { |
| 220 completer0.completeError(e1); |
| 221 } |
| 222 }, onError: (e4) { |
| 223 completer0.completeError(e4); |
| 224 }); |
| 225 } |
| 226 continue0(x5) { |
| 227 if (it0.moveNext()) { |
| 228 Future.wait([]).then((x3) { |
| 229 var package = it0.current; |
| 230 cleanDir(path.join(depsDir, package)); |
| 231 continue0(null); |
| 232 }); |
| 233 } else { |
| 234 break0(null); |
| 235 } |
| 236 } |
| 237 continue0(null); |
| 238 } catch (e0) { |
| 239 completer0.completeError(e0); |
| 240 } |
| 241 }, onError: (e5) { |
| 242 completer0.completeError(e5); |
| 243 }); |
| 244 } catch (e6) { |
| 245 completer0.completeError(e6); |
| 246 } |
| 247 }); |
| 248 return completer0.future; |
| 249 })).catchError(((error) { |
| 250 for (var package in dependenciesToPrecompile) { |
| 251 deleteEntry(path.join(depsDir, package)); |
| 252 } |
| 253 throw error; |
| 254 })).then((x1) { |
| 255 try { |
| 256 x1; |
| 257 completer0.complete(null); |
| 258 } catch (e1) { |
| 259 completer0.completeError(e1); |
| 260 } |
| 261 }, onError: (e2) { |
| 262 completer0.completeError(e2); |
| 263 }); |
| 264 } |
| 265 if (dependenciesToPrecompile.isEmpty) { |
| 266 completer0.complete(null); |
| 267 } else { |
| 268 join1(); |
| 269 } |
| 270 } catch (e0) { |
| 271 completer0.completeError(e0); |
| 272 } |
| 273 }, onError: (e3) { |
| 274 completer0.completeError(e3); |
| 275 }); |
| 276 } |
| 277 if (changed != null) { |
| 278 changed = changed.toSet(); |
| 279 join0(); |
| 280 } else { |
| 281 join0(); |
| 282 } |
| 283 } catch (e4) { |
| 284 completer0.completeError(e4); |
61 } | 285 } |
62 return Future.wait(result.packages.map(_get)).then((ids) { | |
63 _saveLockFile(ids); | |
64 if (_packageSymlinks) _linkSelf(); | |
65 _linkOrDeleteSecondaryPackageDirs(); | |
66 result.summarizeChanges(type, dryRun: dryRun); | |
67 return loadPackageGraph(result); | |
68 }).then((packageGraph) { | |
69 packageGraph.loadTransformerCache().clearIfOutdated( | |
70 result.changedPackages); | |
71 return precompileExecutables( | |
72 changed: result.changedPackages).catchError((error, stackTrace) { | |
73 log.exception(error, stackTrace); | |
74 }); | |
75 }); | |
76 }); | 286 }); |
| 287 return completer0.future; |
77 } | 288 } |
78 Future precompileExecutables({Iterable<String> changed}) { | 289 Future precompileExecutables({Iterable<String> changed}) { |
79 if (changed != null) changed = changed.toSet(); | 290 if (changed != null) changed = changed.toSet(); |
80 var binDir = path.join('.pub', 'bin'); | 291 var binDir = path.join('.pub', 'bin'); |
81 var sdkVersionPath = path.join(binDir, 'sdk-version'); | 292 var sdkVersionPath = path.join(binDir, 'sdk-version'); |
82 var sdkMatches = | 293 var sdkMatches = |
83 fileExists(sdkVersionPath) && | 294 fileExists(sdkVersionPath) && |
84 readTextFile(sdkVersionPath) == "${sdk.version}\n"; | 295 readTextFile(sdkVersionPath) == "${sdk.version}\n"; |
85 if (!sdkMatches) changed = null; | 296 if (!sdkMatches) changed = null; |
86 return loadPackageGraph().then((graph) { | 297 return loadPackageGraph().then((graph) { |
(...skipping 30 matching lines...) Expand all Loading... |
117 })); | 328 })); |
118 }); | 329 }); |
119 }); | 330 }); |
120 }); | 331 }); |
121 } | 332 } |
122 List<AssetId> _executablesForPackage(PackageGraph graph, String packageName, | 333 List<AssetId> _executablesForPackage(PackageGraph graph, String packageName, |
123 Set<String> changed) { | 334 Set<String> changed) { |
124 var package = graph.packages[packageName]; | 335 var package = graph.packages[packageName]; |
125 var binDir = path.join(package.dir, 'bin'); | 336 var binDir = path.join(package.dir, 'bin'); |
126 if (!dirExists(binDir)) return []; | 337 if (!dirExists(binDir)) return []; |
127 var deps = graph.transitiveDependencies(packageName); | 338 if (graph.isPackageMutable(packageName)) return []; |
128 var hasUncachedDependency = deps.any((package) { | |
129 var source = cache.sources[graph.lockFile.packages[package.name].source]; | |
130 return source is! CachedSource; | |
131 }); | |
132 if (hasUncachedDependency) return []; | |
133 var executables = package.executableIds; | 339 var executables = package.executableIds; |
134 if (changed == null) return executables; | 340 if (changed == null) return executables; |
135 if (deps.any((package) => changed.contains(package.name))) { | 341 if (graph.transitiveDependencies( |
| 342 packageName).any((package) => changed.contains(package.name))) { |
136 return executables; | 343 return executables; |
137 } | 344 } |
138 var executablesExist = executables.every( | 345 var executablesExist = executables.every( |
139 (executable) => | 346 (executable) => |
140 fileExists( | 347 fileExists( |
141 path.join( | 348 path.join( |
142 '.pub', | 349 '.pub', |
143 'bin', | 350 'bin', |
144 packageName, | 351 packageName, |
145 "${path.url.basename(executable.path)}.snapshot"))); | 352 "${path.url.basename(executable.path)}.snapshot"))); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 fileAndSubfiles.addAll(_listDirWithoutPackages(file)); | 481 fileAndSubfiles.addAll(_listDirWithoutPackages(file)); |
275 return fileAndSubfiles; | 482 return fileAndSubfiles; |
276 })); | 483 })); |
277 } | 484 } |
278 void _linkOrDeleteSecondaryPackageDir(String dir) { | 485 void _linkOrDeleteSecondaryPackageDir(String dir) { |
279 var symlink = path.join(dir, 'packages'); | 486 var symlink = path.join(dir, 'packages'); |
280 if (entryExists(symlink)) deleteEntry(symlink); | 487 if (entryExists(symlink)) deleteEntry(symlink); |
281 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 488 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
282 } | 489 } |
283 } | 490 } |
OLD | NEW |