Skip to content

Commit

Permalink
Factor out common code for building isopackets
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Dec 3, 2014
1 parent ff7863d commit 14cdfa0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
22 changes: 4 additions & 18 deletions tools/isopack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,21 +1058,7 @@ _.extend(Isopack.prototype, {

// Build all of the isopackets now, so that no build step is required when
// you're actually running meteor from a release in order to load packages.
// XXX This code is pretty similar to isopackets.ensureIsopacketsLoadable
// and could be consolidated.
var isopacketCatalog = isopackets.newIsopacketBuildingCatalog();
var versions = {};
_.each(isopacketCatalog.getAllPackageNames(), function (packageName) {
versions[packageName] =
isopacketCatalog.getLatestVersion(packageName).version;
});
var packageMap = new packageMapModule.PackageMap(
versions, isopacketCatalog);
// Make an isopack cache that doesn't save isopacks to disk and has no
// access to versioned packages.
var isopackCache = new isopackCacheModule.IsopackCache({
packageMap: packageMap
});
var isopacketBuildContext = isopackets.makeIsopacketBuildContext();

var messages = buildmessage.capture(function () {
// We rebuild them in the order listed in ISOPACKETS. This is not strictly
Expand All @@ -1083,14 +1069,14 @@ _.extend(Isopack.prototype, {
buildmessage.enterJob({
title: "Compiling " + isopacketName + " packages for the tool"
}, function () {
isopackCache.buildLocalPackages(packages);
isopacketBuildContext.isopackCache.buildLocalPackages(packages);
if (buildmessage.jobHasMessages())
return;

var image = bundler.buildJsImage({
name: "isopacket-" + isopacketName,
packageMap: packageMap,
isopackCache: isopackCache,
packageMap: isopacketBuildContext.packageMap,
isopackCache: isopacketBuildContext.isopackCache,
use: packages
}).image;
if (buildmessage.jobHasMessages())
Expand Down
46 changes: 24 additions & 22 deletions tools/isopackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ var ensureIsopacketsLoadable = function () {
return;
}

// We make these objects lazily later.
var isopacketCatalog = null;
var isopackCache = null;
var packageMap = null;
// We make this object lazily later.
var isopacketBuildContext = null;

var failedPackageBuild = false;
// Look at each isopacket. Check to see if it's on disk and up to date. If
Expand Down Expand Up @@ -153,35 +151,23 @@ var ensureIsopacketsLoadable = function () {

// We're going to need to build! Make a catalog and loader if we haven't
// yet.
if (! isopacketCatalog) {
isopacketCatalog = newIsopacketBuildingCatalog();
var versions = {};
_.each(isopacketCatalog.getAllPackageNames(), function (packageName) {
versions[packageName] =
isopacketCatalog.getLatestVersion(packageName).version;
});
packageMap = new packageMapModule.PackageMap(
versions, isopacketCatalog);
// Make an isopack cache that doesn't save isopacks to disk and has no
// access to versioned packages.
isopackCache = new isopackCacheModule.IsopackCache({
packageMap: packageMap
});
if (! isopacketBuildContext) {
isopacketBuildContext = makeIsopacketBuildContext();
}

buildmessage.enterJob({
title: "Bundling " + isopacketName + " packages for the tool"
}, function () {
// Build the packages into the in-memory IsopackCache.
isopackCache.buildLocalPackages(packages);
isopacketBuildContext.isopackCache.buildLocalPackages(packages);
if (buildmessage.jobHasMessages())
return;

// Now bundle them into a program.
var built = bundler.buildJsImage({
name: "isopacket-" + isopacketName,
packageMap: packageMap,
isopackCache: isopackCache,
packageMap: isopacketBuildContext.packageMap,
isopackCache: isopacketBuildContext.isopackCache,
use: packages
});
if (buildmessage.jobHasMessages())
Expand Down Expand Up @@ -239,6 +225,22 @@ var newIsopacketBuildingCatalog = function () {
return isopacketCatalog;
};

var makeIsopacketBuildContext = function () {
var context = {};
var catalog = newIsopacketBuildingCatalog();
var versions = {};
_.each(catalog.getAllPackageNames(), function (packageName) {
versions[packageName] = catalog.getLatestVersion(packageName).version;
});
context.packageMap = new packageMapModule.PackageMap(versions, catalog);
// Make an isopack cache that doesn't save isopacks to disk and has no
// access to versioned packages.
context.isopackCache = new isopackCacheModule.IsopackCache({
packageMap: context.packageMap
});
return context;
};

// Loads a built isopacket from disk. Always loads (the cache is in 'load', not
// this function). Does not run a build process; it must already be built.
var loadIsopacketFromDisk = function (isopacketName) {
Expand Down Expand Up @@ -283,5 +285,5 @@ _.extend(exports, {
load: load,
ensureIsopacketsLoadable: ensureIsopacketsLoadable,
ISOPACKETS: ISOPACKETS,
newIsopacketBuildingCatalog: newIsopacketBuildingCatalog
makeIsopacketBuildContext: makeIsopacketBuildContext
});

0 comments on commit 14cdfa0

Please sign in to comment.