Make sure PackageSourceBatch objects know their .sourceRoot.

This commit is contained in:
Ben Newman
2015-10-25 14:23:33 -04:00
parent eac6fa9c09
commit eda80acb86
3 changed files with 46 additions and 3 deletions

View File

@@ -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

View File

@@ -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 = [];

View File

@@ -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();