Remove catalog.resolveConstraints

Also remove the subclass of LocalCatalog used for the isopacket building
catalog... it can just use LocalCatalog and set a flag (which is only
checked in one place).
This commit is contained in:
David Glasser
2014-11-13 00:14:08 -08:00
parent e313b8e3d8
commit e921b20caa
6 changed files with 9 additions and 163 deletions

View File

@@ -1,60 +0,0 @@
var _ = require('underscore');
var util = require('util');
var fs = require('fs');
var buildmessage = require('./buildmessage.js');
var LocalCatalog = require('./catalog-local.js').LocalCatalog;
var tropohouse = require('./tropohouse.js');
// BootstrapCatalogCheckout represents a catalog of the packages at bootstrap
// when we are running in checkout mode.
// This catalog is typically never used directly by the user.
// An instance of this catalog is created in catalog.js
var BootstrapCatalogCheckout = function () {
var self = this;
LocalCatalog.call(this);
self.isopacketBuildingCatalog = true;
};
util.inherits(BootstrapCatalogCheckout, LocalCatalog);
_.extend(BootstrapCatalogCheckout.prototype, {
resolveConstraints: function (constraints, resolverOpts, opts) {
var self = this;
opts = opts || {};
self._requireInitialized();
buildmessage.assertInCapture();
// Building isopackets should always ignore the project: it's essentially
// loading part of the tool, which shouldn't be affected by your app's
// dependencies.
if (!opts.ignoreProjectDeps)
throw Error("whoa, if for isopackets, why not ignoring project?");
// OK, we're building part of an isopacket.
var ret = {};
_.each(constraints, function (constraint) {
if (_.has(constraint, 'version')) {
if (constraint.version !== null) {
throw Error("isopacket specifying version? " + JSON.stringify(constraint));
}
delete constraint.version;
}
// Constraints for isopackets should just be packages with no version
// constraint and one local version (since they should all be in core).
if (!_.has(constraint, 'name') ||
constraint.constraints.length > 1 ||
constraint.constraints[0].type !== 'any-reasonable') {
throw Error("Surprising constraint: " + JSON.stringify(constraint));
}
if (!_.has(self.packages, constraint.name)) {
throw Error("Trying to resolve unknown package: " + constraint.name);
}
ret[constraint.name] =
self.packages[constraint.name].versionRecord.version;
});
return ret;
}
});
exports.BootstrapCatalogCheckout = BootstrapCatalogCheckout;

View File

@@ -214,106 +214,6 @@ _.extend(LayeredCatalog.prototype, {
return self.getVersion(name, latest);
},
resolveConstraints: function (constraints, resolverOpts, opts) {
var self = this;
opts = opts || {};
// OK, since we are the complete catalog, isopackets must be fully
// initialized, so it's safe to load a resolver if we didn't
// already. (Putting this off until the first call to resolveConstraints
// also helps with performance: no need to build this package and load the
// large mori module unless we actually need it.)
self.resolver = self.resolver || self._buildResolver();
// Looks like we are not going to be able to avoid calling the constraint
// solver, so let's process the input (constraints) into the correct
// arguments to the constraint solver.
//
// -deps: list of package names that we depend on
// -constr: constraints of the proper form from parseConstraint in utils.js
//
// Weak dependencies are constraints (they constrain the result), but not
// dependencies.
var deps = [];
var constr = [];
_.each(constraints, function (constraint) {
constraint = _.clone(constraint);
if (!constraint.weak) {
deps.push(constraint.name);
}
delete constraint.weak;
constr.push(constraint);
});
// If we are called with 'ignore projectDeps', then we don't even look to
// see what the project thinks and recalculate everything. Similarly, if the
// project root path has not been initialized, we are probably running
// outside of a project, and have nothing to look at for guidance.
if (!opts.ignoreProjectDeps && project.project &&
project.project.viableDepSource) {
// Anything in the project's dependencies was calculated based on a
// previous constraint solver run, and needs to be taken as absolute truth
// for now: we can't use any packages that are of different versions from
// what we've already decided from the project!
_.each(project.project.getVersions(), function (version, name) {
constr.push(utils.parseConstraint(name + "@=" + version));
});
}
// Local packages can only be loaded from the version we have the source
// for: that's a weak exact constraint.
_.each(self.packageSources, function (packageSource, name) {
constr.push(utils.parseConstraint(name + "@=" + packageSource.version));
});
var ret = buildmessage.enterJob({
title: "Selecting package versions" },
function () {
// Then, call the constraint solver, to get the valid transitive
// subset of those versions to record for our solution. (We don't just
// return the original version lock because we want to record the
// correct transitive dependencies)
return self.resolver.resolve(deps, constr, resolverOpts);
});
if (ret["usedRCs"]) {
var expPackages = [];
_.each(ret.answer, function(version, package) {
if (self.isLocalPackage(package))
return;
if (version.split('-').length > 1) {
if (!(resolverOpts.previousSolution &&
resolverOpts.previousSolution[package] === version)) {
var oldConstraints = _.where(constr, { name: package } );
var printMe = true;
_.each(oldConstraints, function (oC) {
_.each(oC.constraints, function (specOC) {
if (specOC.version === version) {
printMe = false;
}
});
});
if (printMe) {
expPackages.push({
name: " " + package + "@" + version,
description: self.getVersion(package, version).description
});
};
}}
});
if (!_.isEmpty(expPackages)) {
// XXX: Couldn't figure out how to word this better for better tenses.
//
// XXX: this shouldn't be here. This is library code... it
// shouldn't be printing.
// https://github.com/meteor/meteor/wiki/Meteor-Style-Guide#only-user-interface-code-should-engage-with-the-user
Console.info(
"\nIn order to resolve constraints, we had to use the following\n"+
"experimental package versions:");
utils.printPackageList(expPackages);
}
}
return ret.answer;
},
// Refresh the catalogs referenced by this catalog.
// options:
// - watchSet: if provided, any files read in reloading packages will be added

View File

@@ -1774,6 +1774,7 @@ var maybeUpdateRelease = function (options) {
});
try {
var messages = buildmessage.capture(function () {
// XXX #3006 no longer exists
solutionPackageVersions = catalog.complete.resolveConstraints(
constraints,
{ previousSolution: previousVersions },
@@ -1949,6 +1950,7 @@ main.registerCommand({
// any constraints that we didn't have before.
var newVersions;
var messages = buildmessage.capture(function () {
// XXX #3006 no longer exists
newVersions = catalog.complete.resolveConstraints(allPackages, {
previousSolution: versions,
upgrade: upgradePackages
@@ -2199,6 +2201,7 @@ main.registerCommand({
versions = project.getVersions();
// Call the constraint solver.
// XXX #3006 no longer exists
newVersions = catalog.complete.resolveConstraints(
allPackages,
{ previousSolution: versions },

View File

@@ -215,8 +215,9 @@ var newIsopacketBuildingCatalog = function () {
// XXX #3006 once a lot more refactors are done, this should be able to just
// be a LocalCatalog. There's no reason that resolveConstraints should be
// called here!
var catalogBootstrapCheckout = require('./catalog-bootstrap-checkout.js');
var isopacketCatalog = new catalogBootstrapCheckout.BootstrapCatalogCheckout;
var catalogLocal = require('./catalog-local.js');
var isopacketCatalog = new catalogLocal.LocalCatalog;
isopacketCatalog.isopacketBuildingCatalog = true;
var messages = buildmessage.capture(
{ title: "Scanning local core packages" },
function () {

View File

@@ -171,7 +171,8 @@ _.extend(exports.ProjectContext.prototype, {
if (!solution)
return; // error is already in buildmessage
// XXX #3006 Check solution.usedRCs and maybe print something about it
// XXX #3006 Check solution.usedRCs and maybe print something about it. This
// code used to exist in catalog.js.
self.packageMap = new packageMapModule.PackageMap(solution.answer, cat);
},

View File

@@ -224,6 +224,7 @@ _.extend(Project.prototype, {
// solution. It is useful to set ignoreProjectDeps, but not nessessary,
// since self.viableDepSource is false.
try {
// XXX #3006 no longer exists
var newVersions = catalog.complete.resolveConstraints(
self.combinedConstraints,
{ previousSolution: self.dependencies },