Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17183 from cctuan/983564
Browse files Browse the repository at this point in the history
Bug 983564 - [Gaia] [Build] reduce |make| time
  • Loading branch information
cctuan committed Mar 18, 2014
2 parents eea8e37 + 51c57bd commit a04f630
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/communications/build/build.js
Expand Up @@ -23,7 +23,7 @@ CommAppBuilder.prototype.setOptions = function(options) {

this.webapp = utils.getWebapp(this.appDir.path, options.GAIA_DOMAIN,
options.GAIA_SCHEME, options.GAIA_PORT);
this.gaia = utils.getGaia(options);
this.gaia = utils.gaia.getInstance(options);

var content = JSON.parse(utils.getFileContent(utils.getFile(this.appDir.path,
'build', 'communications_services.json')));
Expand Down
2 changes: 1 addition & 1 deletion apps/homescreen/build/build.js
Expand Up @@ -81,7 +81,7 @@ HomescreenAppBuilder.prototype.bestMatchingIcon =
HomescreenAppBuilder.prototype.getCollectionManifest =
function(directory, appName) {
var config = this.options;
let gaia = utils.getGaia(config);
let gaia = utils.gaia.getInstance(config);

// Locate the directory of a given app.
// If the directory (Gaia.distributionDir)/(directory)/(appName) exists,
Expand Down
2 changes: 1 addition & 1 deletion apps/homescreen/build/homescreen-svoperapps.js
Expand Up @@ -51,7 +51,7 @@ function getSystemApps(config, grid) {
var hiddenRoles = ['system', 'input', 'homescreen'];
var systemApps = [];

utils.getGaia(config).webapps.forEach(function(webapp) {
utils.gaia.getInstance(config).webapps.forEach(function(webapp) {
if (!webapp.manifest.role ||
hiddenRoles.indexOf(webapp.manifest.role) === -1) {
// Check if the application has an entrypoint, it means that there are
Expand Down
2 changes: 1 addition & 1 deletion apps/wallpaper/build/build.js
Expand Up @@ -20,7 +20,7 @@ WallPaperAppBuilder.prototype.setOptions = function(options) {
this.WALLPAPER_PATH.split('/'));
this.wallpaperDir = utils.getFile.apply(utils, wallpaperDirPath);

this.gaia = utils.getGaia(options);
this.gaia = utils.gaia.getInstance(options);
};

// XXX This inherits the behavior of what's done before in bug 838110
Expand Down
2 changes: 1 addition & 1 deletion build/copy-build-stage-manifest.js
Expand Up @@ -3,7 +3,7 @@ const utils = require('./utils');
function execute(options) {
const WEBAPP_FILENAME = 'manifest.webapp';
const STAGE_FOLDER = utils.getEnv('STAGE_FOLDER');
var gaia = utils.getGaia(options);
var gaia = utils.gaia.getInstance(options);
var webappsBaseDir = utils.getFile(options.PROFILE_DIR);
webappsBaseDir.append('webapps');
gaia.webapps.forEach(function(app) {
Expand Down
2 changes: 1 addition & 1 deletion build/csslint.js
Expand Up @@ -30,7 +30,7 @@ function execute(config) {
Services.scriptloader.loadSubScript(url, scope);
CSSLint = scope.CSSLint;

let gaia = utils.getGaia(config);
let gaia = utils.gaia.getInstance(config);

let errorsCount = 0;
let warningsCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion build/optimize-clean.js
Expand Up @@ -6,7 +6,7 @@ function debug(str) {
}

function execute(options) {
var gaia = utils.getGaia(options);
var gaia = utils.gaia.getInstance(options);
config = options;
debug('Begin');

Expand Down
2 changes: 1 addition & 1 deletion build/preferences.js
Expand Up @@ -9,7 +9,7 @@ var PreferencesBuilder = function() {
PreferencesBuilder.prototype.setConfig = function(config) {
this.config = config;
this.prefs = {};
this.gaia = utils.getGaia(this.config);
this.gaia = utils.gaia.getInstance(this.config);
};

PreferencesBuilder.prototype.execute = function(config) {
Expand Down
6 changes: 4 additions & 2 deletions build/test/unit/preference.test.js
Expand Up @@ -15,8 +15,10 @@ suite('preferences.js', function() {
'../../preferences', {
'./utils': mockUtils
});
mockUtils.getGaia = function(config) {
return config;
mockUtils.gaia = {
getInstance: function(config) {
return config;
}
};
mockUtils.getFile = function(src, path) {
return src + path;
Expand Down
50 changes: 28 additions & 22 deletions build/utils-xpc.js
Expand Up @@ -286,28 +286,34 @@ function registerProfileDirectory(profileDir) {
.registerProvider(directoryProvider);
}

function getGaia(options) {
var gaia = {
engine: options.GAIA_ENGINE,
sharedFolder: getFile(options.GAIA_DIR, 'shared'),
webapps: makeWebappsObject(options.GAIA_APPDIRS.split(' '),
options.GAIA_DOMAIN, options.GAIA_SCHEME, options.GAIA_PORT),
aggregatePrefix: 'gaia_build_',
distributionDir: options.GAIA_DISTRIBUTION_DIR
};

if (options.LOCALE_BASEDIR) {
// Bug 952901: remove getLocaleBasedir() if bug 952900 fixed.
var localeBasedir = getLocaleBasedir(options.LOCALE_BASEDIR);
gaia.l10nManager = new multilocale.L10nManager(
options.GAIA_DIR,
gaia.sharedFolder.path,
options.LOCALES_FILE,
localeBasedir);
var gaia = {
config: {},
getInstance: function(config) {
if (JSON.stringify(this.config) !== JSON.stringify(config) ||
!this.instance) {
this.config = config;
this.instance = {
engine: this.config.GAIA_ENGINE,
sharedFolder: getFile(this.config.GAIA_DIR, 'shared'),
webapps: makeWebappsObject(this.config.GAIA_APPDIRS.split(' '),
this.config.GAIA_DOMAIN, this.config.GAIA_SCHEME,
this.config.GAIA_PORT),
aggregatePrefix: 'gaia_build_',
distributionDir: this.config.GAIA_DISTRIBUTION_DIR
};
}
if (this.config.LOCALE_BASEDIR) {
// Bug 952901: remove getLocaleBasedir() if bug 952900 fixed.
var localeBasedir = getLocaleBasedir(this.config.LOCALE_BASEDIR);
this.instance.l10nManager = new multilocale.L10nManager(
this.config.GAIA_DIR,
this.instance.sharedFolder.path,
this.config.LOCALES_FILE,
localeBasedir);
}
return this.instance;
}

return gaia;
}
};

// FIXME (Bug 952901): because TBPL use path style like C:/path1/path2 for
// LOCALE_BASEDIR but we expect C:\path1\path2, so we need convert it if this
Expand Down Expand Up @@ -744,7 +750,6 @@ exports.getFileAsDataURI = getFileAsDataURI;
exports.makeWebappsObject = makeWebappsObject;
exports.getDistributionFileContent = getDistributionFileContent;
exports.resolve = resolve;
exports.getGaia = getGaia;
exports.getBuildConfig = getBuildConfig;
exports.getAppsByList = getAppsByList;
exports.getApp = getApp;
Expand Down Expand Up @@ -775,3 +780,4 @@ exports.isExternalApp = isExternalApp;
exports.getDocument = getDocument;
exports.getWebapp = getWebapp;
exports.Services = Services;
exports.gaia = gaia;
2 changes: 1 addition & 1 deletion build/utils.js
Expand Up @@ -85,7 +85,7 @@ exports.gaiaOriginURL = gaiaOriginURL;
exports.gaiaManifestURL = gaiaManifestURL;
exports.getDistributionFileContent = utils.getDistributionFileContent;
exports.resolve = utils.resolve;
exports.getGaia = utils.getGaia;
exports.gaia = utils.gaia;
exports.getBuildConfig = utils.getBuildConfig;
exports.getAppsByList = utils.getAppsByList;
exports.getApp = utils.getApp;
Expand Down
4 changes: 2 additions & 2 deletions build/webapp-manifests.js
Expand Up @@ -109,7 +109,7 @@ function fillAppManifest(webapp) {
// Copy webapp's manifest to the profile
let webappTargetDir = webappsTargetDir.clone();
webappTargetDir.append(webappTargetDirName);
let gaia = utils.getGaia(config);
let gaia = utils.gaia.getInstance(config);

if (gaia.l10nManager) {
let manifest = gaia.l10nManager.localizeManifest(webapp);
Expand Down Expand Up @@ -314,7 +314,7 @@ function execute(options) {
cleanProfile(webappsTargetDir);
}

utils.getGaia(config).webapps.forEach(function(webapp) {
utils.gaia.getInstance(config).webapps.forEach(function(webapp) {
if (utils.isExternalApp(webapp)) {
fillExternalAppManifest(webapp);
} else {
Expand Down
6 changes: 3 additions & 3 deletions build/webapp-optimize.js
Expand Up @@ -75,7 +75,7 @@ const RE_INI = /locales[\/\\].+\.ini$/;
function optimize_getFileContent(webapp, htmlFile, relativePath) {
let paths = relativePath.split(/[\/\\]/);
let file;
let gaia = utils.getGaia(config);
let gaia = utils.gaia.getInstance(config);

// get starting directory: webapp root, HTML file or /shared/
if (/^\//.test(relativePath)) {
Expand Down Expand Up @@ -246,7 +246,7 @@ function optimize_aggregateJsResources(doc, webapp, htmlFile) {
if (!conf.content)
return;

var gaia = utils.getGaia(config);
var gaia = utils.gaia.getInstance(config);
// prefix the file we are about to write content to.
let scriptBaseName = gaia.aggregatePrefix + conf.prefix + baseName + '.js';

Expand Down Expand Up @@ -663,7 +663,7 @@ function execute(options) {
l10nLocales.push(config.GAIA_DEFAULT_LOCALE);
}

utils.getGaia(config).webapps.forEach(function(webapp) {
utils.gaia.getInstance(config).webapps.forEach(function(webapp) {
// if BUILD_APP_NAME isn't `*`, we only accept one webapp
if (config.BUILD_APP_NAME != '*' &&
webapp.sourceDirectoryName != config.BUILD_APP_NAME)
Expand Down
6 changes: 3 additions & 3 deletions build/webapp-zip.js
Expand Up @@ -207,7 +207,7 @@ function copyBuildingBlock(zip, blockName, dirName, webapp) {
let dirPath = '/shared/' + dirName + '/';

// Compute the nsIFile for this shared style
let styleFolder = utils.getGaia(config).sharedFolder.clone();
let styleFolder = utils.gaia.getInstance(config).sharedFolder.clone();
styleFolder.append(dirName);
let cssFile = styleFolder.clone();
if (!styleFolder.exists()) {
Expand Down Expand Up @@ -239,7 +239,7 @@ function copyBuildingBlock(zip, blockName, dirName, webapp) {

function customizeFiles(zip, src, dest, webapp) {
// Add customize file to the zip
var distDir = utils.getGaia(config).distributionDir;
var distDir = utils.gaia.getInstance(config).distributionDir;
let files = utils.ls(utils.getFile(distDir, src));
files.forEach(function(file) {
let filename = dest + file.leafName;
Expand All @@ -253,7 +253,7 @@ function customizeFiles(zip, src, dest, webapp) {

function execute(options) {
config = options;
var gaia = utils.getGaia(config);
var gaia = utils.gaia.getInstance(config);
var localesFile = utils.resolve(config.LOCALES_FILE,
config.GAIA_DIR);
if (!localesFile.exists()) {
Expand Down

0 comments on commit a04f630

Please sign in to comment.