From eda80acb86fcbf06a95d56404c1e0da22af9da83 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sun, 25 Oct 2015 14:23:33 -0400 Subject: [PATCH] Make sure PackageSourceBatch objects know their .sourceRoot. --- tools/isobuild/bundler.js | 14 ++++++++++++-- tools/isobuild/compiler-plugin.js | 14 +++++++++++++- tools/isobuild/isopack-cache.js | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index 61adb4388a..62fc4ea556 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -420,6 +420,9 @@ class Target { packageMap, isopackCache, + // Path to the root source directory for this Target. + sourceRoot, + // the architecture to build arch, // projectContextModule.CordovaPluginsFile object @@ -436,6 +439,8 @@ class Target { this.packageMap = packageMap; this.isopackCache = isopackCache; + this.sourceRoot = sourceRoot; + // Something like "web.browser" or "os" or "os.osx.x86_64" this.arch = arch; @@ -711,6 +716,7 @@ class Target { const processor = new compilerPluginModule.CompilerPluginProcessor({ unibuilds: this.unibuilds, arch: this.arch, + sourceRoot: this.sourceRoot, isopackCache: this.isopackCache, linkerCacheDir: (this.bundlerCacheDir && files.pathJoin(this.bundlerCacheDir, 'linker')) @@ -2174,12 +2180,16 @@ exports.bundle = function ({ var messages = buildmessage.capture({ title: "building the application" }, function () { + var packageSource = new PackageSource; + packageSource.initFromAppDir(projectContext, exports.ignoreFiles); + var makeClientTarget = Profile( "bundler.bundle..makeClientTarget", function (app, webArch, options) { var client = new ClientTarget({ bundlerCacheDir, packageMap: projectContext.packageMap, isopackCache: projectContext.isopackCache, + sourceRoot: packageSource.sourceRoot, arch: webArch, cordovaPluginsFile: (webArch === 'web.cordova' ? projectContext.cordovaPluginsFile : null), @@ -2202,6 +2212,7 @@ exports.bundle = function ({ bundlerCacheDir, packageMap: projectContext.packageMap, isopackCache: projectContext.isopackCache, + sourceRoot: packageSource.sourceRoot, arch: serverArch, releaseName: releaseName, buildMode: buildOptions.buildMode, @@ -2223,8 +2234,6 @@ exports.bundle = function ({ // Create a Isopack object that represents the app // XXX should this be part of prepareProjectForBuild and get cached? // at the very least, would speed up deploy after build. - var packageSource = new PackageSource; - packageSource.initFromAppDir(projectContext, exports.ignoreFiles); var app = compiler.compile(packageSource, { packageMap: projectContext.packageMap, isopackCache: projectContext.isopackCache, @@ -2468,6 +2477,7 @@ exports.buildJsImage = Profile("bundler.buildJsImage", function (options) { var target = new JsImageTarget({ packageMap: options.packageMap, isopackCache: options.isopackCache, + sourceRoot: packageSource.sourceRoot, // This function does not yet support cross-compilation (neither does // initFromOptions). That's OK for now since we're only trying to support // cross-bundling, not cross-package-building, and this function is only diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index e4f82e0c22..8793b6a764 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -68,6 +68,7 @@ export class CompilerPluginProcessor { constructor({ unibuilds, arch, + sourceRoot, isopackCache, linkerCacheDir, }) { @@ -75,6 +76,7 @@ export class CompilerPluginProcessor { self.unibuilds = unibuilds; self.arch = arch; + self.sourceRoot = sourceRoot; self.isopackCache = isopackCache; self.linkerCacheDir = linkerCacheDir; @@ -91,7 +93,13 @@ export class CompilerPluginProcessor { var sourceProcessorsWithSlots = {}; var sourceBatches = _.map(self.unibuilds, function (unibuild) { + const { pkg: { name }, arch } = unibuild; + const sourceRoot = name + ? self.isopackCache.getSourceRoot(name, arch) + : self.sourceRoot; + return new PackageSourceBatch(unibuild, self, { + sourceRoot, linkerCacheDir: self.linkerCacheDir }); }); @@ -456,12 +464,16 @@ class ResourceSlot { } class PackageSourceBatch { - constructor(unibuild, processor, {linkerCacheDir}) { + constructor(unibuild, processor, { + sourceRoot, + linkerCacheDir, + }) { const self = this; buildmessage.assertInJob(); self.unibuild = unibuild; self.processor = processor; + self.sourceRoot = sourceRoot; self.linkerCacheDir = linkerCacheDir; var sourceProcessorSet = self._getSourceProcessorSet(); self.resourceSlots = []; diff --git a/tools/isobuild/isopack-cache.js b/tools/isobuild/isopack-cache.js index 4b7207b1c6..20ae44ec51 100644 --- a/tools/isobuild/isopack-cache.js +++ b/tools/isobuild/isopack-cache.js @@ -118,6 +118,27 @@ _.extend(exports.IsopackCache.prototype, { }); }, + getSourceRoot(name, arch) { + const packageInfo = this._packageMap.getInfo(name); + + if (packageInfo) { + if (packageInfo.kind === "local") { + return packageInfo.packageSource.sourceRoot; + } + + if (packageInfo.kind === "versioned") { + const isopackPath = this._tropohouse.packagePath( + name, + packageInfo.version + ); + + return files.realpath(files.pathJoin(isopackPath, arch)); + } + } + + return null; + }, + _ensurePackageLoaded: function (name, onStack) { var self = this; buildmessage.assertInCapture();