pdf.js/make.js

1024 lines
29 KiB
JavaScript
Raw Normal View History

2012-08-31 20:51:25 +09:00
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* jshint node:true */
/* globals cat, cd, cp, echo, env, exec, exit, find, ls, mkdir, mv, process, rm, sed, target, test */
2012-08-31 20:51:25 +09:00
'use strict';
2012-03-04 04:01:31 +09:00
require('./external/shelljs/make');
var builder = require('./external/builder/builder.js');
var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
2012-03-04 04:01:31 +09:00
var ROOT_DIR = __dirname + '/', // absolute path to project's root
2012-03-04 04:01:31 +09:00
BUILD_DIR = 'build/',
BUILD_TARGET = BUILD_DIR + 'pdf.js',
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
2012-03-04 04:01:31 +09:00
EXTENSION_SRC_DIR = 'extensions/',
LOCALE_SRC_DIR = 'l10n/',
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
2012-08-02 03:29:13 +09:00
GENERIC_DIR = BUILD_DIR + 'generic/',
2012-03-04 04:01:31 +09:00
REPO = 'git@github.com:mozilla/pdf.js.git',
PYTHON_BIN = 'python2.7',
MOZCENTRAL_PREF_PREFIX = 'pdfjs',
FIREFOX_PREF_PREFIX = 'extensions.uriloader@pdf.js',
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
FIREFOX_STREAM_CONVERTER_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb1';
2012-03-04 04:01:31 +09:00
2012-08-02 03:29:13 +09:00
var DEFINES = {
PRODUCTION: true,
// The main build targets:
GENERIC: false,
FIREFOX: false,
MOZCENTRAL: false,
B2G: false,
CHROME: false
};
2012-03-04 04:01:31 +09:00
//
// make all
//
target.all = function() {
2012-03-04 04:01:31 +09:00
// Don't do anything by default
echo('Please specify a target. Available targets:');
for (var t in target)
2012-03-04 04:01:31 +09:00
if (t !== 'all') echo(' ' + t);
};
2012-03-04 04:01:31 +09:00
///////////////////////////////////////////////////////////////////////////////////////////
//
// Production stuff
//
2012-08-02 03:29:13 +09:00
// Files that need to be included in every build.
2012-08-02 04:05:03 +09:00
var COMMON_WEB_FILES =
2012-08-02 03:29:13 +09:00
['web/viewer.css',
'web/images',
'web/debugger.js'],
COMMON_WEB_FILES_PREPROCESS =
['web/viewer.js',
'web/viewer.html'];
//
// make generic
// Builds the generic production viewer that should be compatible with most
// modern HTML5 browsers.
//
target.generic = function() {
target.bundle();
target.locale();
cd(ROOT_DIR);
echo();
echo('### Creating generic viewer');
rm('-rf', GENERIC_DIR);
mkdir('-p', GENERIC_DIR);
mkdir('-p', GENERIC_DIR + BUILD_DIR);
mkdir('-p', GENERIC_DIR + '/web');
var defines = builder.merge(DEFINES, {GENERIC: true});
2012-08-02 03:29:13 +09:00
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
['web/compatibility.js', GENERIC_DIR + '/web'],
['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
['web/locale', GENERIC_DIR + '/web']
2012-08-02 03:29:13 +09:00
],
preprocess: [
[BUILD_TARGET, GENERIC_DIR + BUILD_TARGET],
[COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
]
};
builder.build(setup);
2012-08-02 03:29:13 +09:00
};
2012-03-04 04:01:31 +09:00
//
// make web
2012-08-23 03:34:34 +09:00
// Generates the website for the project, by checking out the gh-pages branch
// underneath the build directory, and then moving the various viewer files
// into place.
2012-03-04 04:01:31 +09:00
//
target.web = function() {
2012-08-02 03:29:13 +09:00
target.generic();
2012-03-04 04:01:31 +09:00
target.extension();
2012-03-04 04:01:31 +09:00
echo();
echo('### Creating web site');
if (test('-d', GH_PAGES_DIR))
rm('-rf', GH_PAGES_DIR);
mkdir('-p', GH_PAGES_DIR + '/web');
mkdir('-p', GH_PAGES_DIR + '/web/images');
mkdir('-p', GH_PAGES_DIR + BUILD_DIR);
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox');
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome');
2012-08-02 03:29:13 +09:00
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
2012-08-02 03:29:13 +09:00
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chrome/');
2012-08-02 03:29:13 +09:00
cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
2012-12-03 06:47:41 +09:00
cp('-R', 'test/features', GH_PAGES_DIR);
2012-08-02 03:29:13 +09:00
2012-03-04 04:01:31 +09:00
cd(GH_PAGES_DIR);
exec('git init');
exec('git remote add origin ' + REPO);
2012-03-04 04:01:31 +09:00
exec('git add -A');
exec('git commit -am "gh-pages site created via make.js script"');
exec('git branch -m gh-pages');
2012-03-04 04:01:31 +09:00
echo();
2012-08-23 03:34:34 +09:00
echo('Website built in ' + GH_PAGES_DIR);
};
2012-03-04 04:01:31 +09:00
//
// make locale
// Creates localized resources for the viewer and extension.
//
target.locale = function() {
var METADATA_OUTPUT = 'extensions/firefox/metadata.inc';
var CHROME_MANIFEST_OUTPUT = 'extensions/firefox/chrome.manifest.inc';
var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale';
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
cd(ROOT_DIR);
echo();
echo('### Building localization files');
rm('-rf', EXTENSION_LOCALE_OUTPUT);
mkdir('-p', EXTENSION_LOCALE_OUTPUT);
rm('-rf', VIEWER_LOCALE_OUTPUT);
mkdir('-p', VIEWER_LOCALE_OUTPUT);
var subfolders = ls(LOCALE_SRC_DIR);
subfolders.sort();
var metadataContent = '';
var chromeManifestContent = '';
var viewerOutput = '';
for (var i = 0; i < subfolders.length; i++) {
var locale = subfolders[i];
var path = LOCALE_SRC_DIR + locale;
if (!test('-d', path))
continue;
if (!/^[a-z][a-z](-[A-Z][A-Z])?$/.test(locale)) {
echo('Skipping invalid locale: ' + locale);
continue;
}
mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale);
mkdir('-p', VIEWER_LOCALE_OUTPUT + '/' + locale);
2012-08-23 03:34:34 +09:00
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
locale + '/\n';
if (test('-f', path + '/viewer.properties')) {
viewerOutput += '[' + locale + ']\n' +
'@import url(' + locale + '/viewer.properties)\n\n';
cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
cp(path + '/viewer.properties', VIEWER_LOCALE_OUTPUT + '/' + locale);
}
2012-05-16 02:33:01 +09:00
if (test('-f', path + '/chrome.properties')) {
cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
}
if (test('-f', path + '/metadata.inc')) {
var metadata = cat(path + '/metadata.inc');
metadataContent += metadata;
}
}
viewerOutput.to(VIEWER_LOCALE_OUTPUT + 'locale.properties');
metadataContent.to(METADATA_OUTPUT);
chromeManifestContent.to(CHROME_MANIFEST_OUTPUT);
};
2012-03-04 04:01:31 +09:00
//
// make bundle
// Bundles all source files into one wrapper 'pdf.js' file, in the given order.
//
target.bundle = function() {
2013-01-05 02:01:31 +09:00
target.buildnumber();
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
echo();
echo('### Bundling files into ' + BUILD_TARGET);
2012-03-04 04:01:31 +09:00
// File order matters
var SRC_FILES =
2012-03-04 04:01:31 +09:00
['core.js',
'util.js',
'api.js',
2012-03-04 04:01:31 +09:00
'canvas.js',
'obj.js',
'function.js',
'charsets.js',
'cidmaps.js',
'colorspace.js',
'crypto.js',
'evaluator.js',
'fonts.js',
'glyphlist.js',
'image.js',
'metrics.js',
'parser.js',
'pattern.js',
'stream.js',
'worker.js',
'jpx.js',
'jbig2.js',
2012-03-25 03:59:51 +09:00
'bidi.js',
2012-03-27 06:53:51 +09:00
'metadata.js'];
2012-03-04 04:01:31 +09:00
2012-09-05 02:22:32 +09:00
var EXT_SRC_FILES = [
'../external/jpgjs/jpg.js'];
if (!test('-d', BUILD_DIR))
2012-03-04 04:01:31 +09:00
mkdir(BUILD_DIR);
cd('src');
var bundle = cat(SRC_FILES),
2013-01-05 02:01:31 +09:00
bundleVersion = EXTENSION_VERSION,
bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', '');
2012-03-04 04:01:31 +09:00
crlfchecker.checkIfCrlfIsPresent(SRC_FILES);
2012-09-05 02:22:32 +09:00
// Strip out all the vim/license headers.
var reg = /\n\/\* -\*- Mode(.|\n)*?Mozilla Foundation(.|\n)*?'use strict';/g;
bundle = bundle.replace(reg, '');
// Append external files last since we don't want to modify them.
bundle += cat(EXT_SRC_FILES);
2012-08-02 03:29:13 +09:00
// This just preprocesses the empty pdf.js file, we don't actually want to
// preprocess everything yet since other build targets use this file.
builder.preprocess('pdf.js', ROOT_DIR + BUILD_TARGET,
2013-01-05 02:01:31 +09:00
{BUNDLE: bundle,
BUNDLE_VERSION: bundleVersion,
BUNDLE_BUILD: bundleBuild});
};
2012-03-04 04:01:31 +09:00
///////////////////////////////////////////////////////////////////////////////////////////
//
// Extension stuff
//
2012-12-12 02:30:45 +09:00
var EXTENSION_BASE_VERSION = '9583cb710808f6c9746c4723de0c0a816bc006e1',
EXTENSION_VERSION_PREFIX = '0.7.',
2012-03-14 10:31:53 +09:00
EXTENSION_BUILD_NUMBER,
EXTENSION_VERSION;
2012-03-04 04:01:31 +09:00
//
// make extension
//
target.extension = function() {
cd(ROOT_DIR);
echo();
echo('### Building extensions');
target.locale();
2012-03-04 04:01:31 +09:00
target.firefox();
target.chrome();
};
2012-03-04 04:01:31 +09:00
target.buildnumber = function() {
cd(ROOT_DIR);
echo();
echo('### Getting extension build number');
2012-09-01 07:48:21 +09:00
var lines = exec('git log --format=oneline ' +
EXTENSION_BASE_VERSION + '..', {silent: true}).output;
2012-03-04 04:01:31 +09:00
// Build number is the number of commits since base version
2012-09-01 07:48:21 +09:00
EXTENSION_BUILD_NUMBER = lines ? lines.match(/\n/g).length : 0;
echo('Extension build number: ' + EXTENSION_BUILD_NUMBER);
2012-03-14 10:31:53 +09:00
EXTENSION_VERSION = EXTENSION_VERSION_PREFIX + EXTENSION_BUILD_NUMBER;
};
2012-03-04 04:01:31 +09:00
//
// make firefox
//
target.firefox = function() {
cd(ROOT_DIR);
echo();
echo('### Building Firefox extension');
var defines = builder.merge(DEFINES, {FIREFOX: true});
2012-03-04 04:01:31 +09:00
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/',
2012-08-02 03:29:13 +09:00
FIREFOX_EXTENSION_DIR = 'extensions/firefox/',
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
2012-03-04 04:01:31 +09:00
FIREFOX_EXTENSION_FILES_TO_COPY =
['*.js',
'*.rdf',
2012-05-09 00:23:55 +09:00
'*.svg',
2012-03-21 07:25:02 +09:00
'*.png',
'*.manifest',
2012-03-14 10:31:53 +09:00
'components',
'locale',
2012-05-09 00:23:55 +09:00
'../../LICENSE'],
2012-03-04 04:01:31 +09:00
FIREFOX_EXTENSION_FILES =
2012-03-14 10:31:53 +09:00
['bootstrap.js',
2012-03-04 04:01:31 +09:00
'install.rdf',
'chrome.manifest',
2012-03-21 07:25:02 +09:00
'icon.png',
'icon64.png',
2012-03-04 04:01:31 +09:00
'components',
2012-03-14 10:31:53 +09:00
'content',
'locale',
2012-05-09 00:23:55 +09:00
'LICENSE'],
2012-03-04 04:01:31 +09:00
FIREFOX_EXTENSION_NAME = 'pdf.js.xpi',
FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi';
target.locale();
2012-08-02 03:29:13 +09:00
target.bundle();
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
// Clear out everything in the firefox extension build directory
rm('-rf', FIREFOX_BUILD_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web');
2012-08-23 03:34:34 +09:00
cp(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm',
FIREFOX_BUILD_CONTENT_DIR + 'PdfJs.jsm');
2012-08-20 03:07:31 +09:00
// Copy extension files
2012-09-02 19:05:05 +09:00
cd(FIREFOX_EXTENSION_DIR);
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR);
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
2012-08-02 03:29:13 +09:00
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR + '/web'],
2012-09-02 19:05:05 +09:00
[FIREFOX_EXTENSION_DIR + 'tools/l10n.js',
FIREFOX_BUILD_CONTENT_DIR + '/web']
2012-08-02 03:29:13 +09:00
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET]
2012-08-02 03:29:13 +09:00
]
};
builder.build(setup);
2012-03-04 04:01:31 +09:00
2012-03-15 06:50:49 +09:00
// Remove '.DS_Store' and other hidden files
find(FIREFOX_BUILD_DIR).forEach(function(file) {
2012-03-15 06:50:49 +09:00
if (file.match(/^\./))
rm('-f', file);
});
2012-03-04 04:01:31 +09:00
// Update the build version number
2012-08-23 03:34:34 +09:00
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
FIREFOX_BUILD_DIR + '/install.rdf');
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
FIREFOX_BUILD_DIR + '/update.rdf');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID,
FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'false',
FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
// Update localized metadata
var localizedMetadata = cat(EXTENSION_SRC_DIR + '/firefox/metadata.inc');
2012-08-23 03:34:34 +09:00
sed('-i', /.*PDFJS_LOCALIZED_METADATA.*\n/, localizedMetadata,
FIREFOX_BUILD_DIR + '/install.rdf');
var chromeManifest = cat(EXTENSION_SRC_DIR + '/firefox/chrome.manifest.inc');
2012-08-23 03:34:34 +09:00
sed('-i', /.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifest,
FIREFOX_BUILD_DIR + '/chrome.manifest');
2012-03-04 04:01:31 +09:00
// Create the xpi
cd(FIREFOX_BUILD_DIR);
2012-08-23 03:34:34 +09:00
exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
2012-03-04 04:01:31 +09:00
echo('extension created: ' + FIREFOX_EXTENSION_NAME);
cd(ROOT_DIR);
// Build the amo extension too (remove the updateUrl)
cd(FIREFOX_BUILD_DIR);
sed('-i', /.*updateURL.*\n/, '', 'install.rdf');
2012-08-23 03:34:34 +09:00
exec('zip -r ' + FIREFOX_AMO_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
2012-03-04 04:01:31 +09:00
echo('AMO extension created: ' + FIREFOX_AMO_EXTENSION_NAME);
cd(ROOT_DIR);
2012-05-09 00:23:55 +09:00
};
//
// make mozcentral
//
target.mozcentral = function() {
cd(ROOT_DIR);
echo();
echo('### Building mozilla-central extension');
var defines = builder.merge(DEFINES, {MOZCENTRAL: true});
2012-05-09 00:23:55 +09:00
var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/',
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/',
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + 'content/',
MOZCENTRAL_L10N_DIR = MOZCENTRAL_DIR + 'browser/locales/en-US/pdfviewer/',
MOZCENTRAL_TEST_DIR = MOZCENTRAL_EXTENSION_DIR + 'test/',
2012-05-09 00:23:55 +09:00
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
FIREFOX_EXTENSION_FILES_TO_COPY =
['*.svg',
2012-05-09 00:23:55 +09:00
'*.png',
'*.manifest',
2012-05-09 00:23:55 +09:00
'README.mozilla',
'components',
'../../LICENSE'],
DEFAULT_LOCALE_FILES =
[LOCALE_SRC_DIR + 'en-US/viewer.properties',
LOCALE_SRC_DIR + 'en-US/chrome.properties'],
2012-05-09 00:23:55 +09:00
FIREFOX_MC_EXTENSION_FILES =
['chrome.manifest',
2012-05-09 00:23:55 +09:00
'components',
'content',
'LICENSE'];
2012-08-02 03:29:13 +09:00
target.bundle();
2012-05-09 00:23:55 +09:00
cd(ROOT_DIR);
// Clear out everything in the firefox extension build directory
rm('-rf', MOZCENTRAL_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR);
mkdir('-p', MOZCENTRAL_L10N_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR + BUILD_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web');
2012-08-23 03:34:34 +09:00
cp(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', MOZCENTRAL_CONTENT_DIR);
2012-05-09 00:23:55 +09:00
// Copy extension files
cd('extensions/firefox');
2012-08-23 03:34:34 +09:00
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY,
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR);
mv('-f', ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome-mozcentral.manifest',
2012-08-23 03:34:34 +09:00
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest');
2012-05-09 00:23:55 +09:00
cd(ROOT_DIR);
2012-08-02 03:29:13 +09:00
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, MOZCENTRAL_CONTENT_DIR + '/web'],
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
[BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET]
2012-08-02 03:29:13 +09:00
]
};
builder.build(setup);
2012-05-09 00:23:55 +09:00
// Remove '.DS_Store' and other hidden files
find(MOZCENTRAL_DIR).forEach(function(file) {
if (file.match(/^\./))
rm('-f', file);
});
// Copy default localization files
cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR);
// Update the build version number
2012-08-23 03:34:34 +09:00
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
MOZCENTRAL_EXTENSION_DIR + 'README.mozilla');
2012-03-14 10:31:53 +09:00
2012-08-23 03:34:34 +09:00
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID,
MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'true',
MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
2012-03-15 06:50:49 +09:00
// List all files for mozilla-central
cd(MOZCENTRAL_EXTENSION_DIR);
2012-03-15 06:50:49 +09:00
var extensionFiles = '';
2012-08-23 03:34:34 +09:00
find(FIREFOX_MC_EXTENSION_FILES).forEach(function(file) {
2012-03-15 06:50:49 +09:00
if (test('-f', file))
2012-08-23 03:34:34 +09:00
extensionFiles += file + '\n';
});
2012-03-15 06:50:49 +09:00
extensionFiles.to('extension-files');
cd(ROOT_DIR);
// Copy test files
mkdir('-p', MOZCENTRAL_TEST_DIR);
cp('-Rf', 'test/mozcentral/*', MOZCENTRAL_TEST_DIR);
};
2012-03-04 04:01:31 +09:00
2012-07-28 07:19:43 +09:00
target.b2g = function() {
2012-11-30 10:01:51 +09:00
target.locale();
2013-01-05 02:01:31 +09:00
2012-07-28 07:19:43 +09:00
echo();
echo('### Building B2G (Firefox OS App)');
var B2G_BUILD_DIR = BUILD_DIR + '/b2g/',
B2G_BUILD_CONTENT_DIR = B2G_BUILD_DIR + '/content/';
var defines = builder.merge(DEFINES, { B2G: true });
2012-08-02 03:29:13 +09:00
target.bundle();
2012-08-02 03:29:13 +09:00
// Clear out everything in the b2g build directory
2012-07-28 07:19:43 +09:00
cd(ROOT_DIR);
rm('-Rf', B2G_BUILD_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR + '/web');
2012-08-02 03:29:13 +09:00
var setup = {
defines: defines,
copy: [
2012-11-30 10:01:51 +09:00
['extensions/b2g/images', B2G_BUILD_CONTENT_DIR + '/web'],
['extensions/b2g/viewer.html', B2G_BUILD_CONTENT_DIR + '/web'],
['extensions/b2g/viewer.css', B2G_BUILD_CONTENT_DIR + '/web'],
['web/locale', B2G_BUILD_CONTENT_DIR + '/web'],
2012-08-02 03:29:13 +09:00
['external/webL10n/l10n.js', B2G_BUILD_CONTENT_DIR + '/web']
],
preprocess: [
2012-11-30 10:01:51 +09:00
['web/viewer.js', B2G_BUILD_CONTENT_DIR + '/web'],
2012-08-02 03:29:13 +09:00
[BUILD_TARGET, B2G_BUILD_CONTENT_DIR + BUILD_TARGET]
]
2012-07-28 07:19:43 +09:00
};
builder.build(setup);
2012-07-28 07:19:43 +09:00
};
2012-03-04 04:01:31 +09:00
//
// make chrome
//
target.chrome = function() {
cd(ROOT_DIR);
echo();
echo('### Building Chrome extension');
var defines = builder.merge(DEFINES, {CHROME: true});
2012-03-04 04:01:31 +09:00
var CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
2012-08-02 03:29:13 +09:00
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + '/content/';
2012-03-04 04:01:31 +09:00
2012-08-02 03:29:13 +09:00
target.bundle();
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
// Clear out everything in the chrome extension build directory
rm('-Rf', CHROME_BUILD_DIR);
mkdir('-p', CHROME_BUILD_CONTENT_DIR);
mkdir('-p', CHROME_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', CHROME_BUILD_CONTENT_DIR + '/web');
2012-03-04 04:01:31 +09:00
2012-08-02 03:29:13 +09:00
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'],
[['extensions/chrome/*.json',
'extensions/chrome/*.html',
'extensions/chrome/*.js'],
2012-08-23 03:34:34 +09:00
CHROME_BUILD_DIR],
2012-08-02 03:29:13 +09:00
[BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET],
['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'],
['web/locale', CHROME_BUILD_CONTENT_DIR + '/web']
2012-08-02 03:29:13 +09:00
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web']
2012-08-02 03:29:13 +09:00
]
};
builder.build(setup);
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
CHROME_BUILD_DIR + '/manifest.json');
// Bundle the files to a Chrome extension file .crx if path to key is set
var pem = env['PDFJS_CHROME_KEY'];
if (!pem) {
return;
}
echo();
echo('### Bundling .crx extension into ' + CHROME_BUILD_DIR);
if (!test('-f', pem)) {
echo('Incorrect PDFJS_CHROME_KEY path');
exit(1);
}
var browserManifest = env['PDF_BROWSERS'] ||
'test/resources/browser_manifests/browser_manifest.json';
if (!test('-f', browserManifest)) {
echo('Browser manifest file ' + browserManifest + ' does not exist.');
echo('Try copying one of the examples in test/resources/browser_manifests');
exit(1);
}
var manifest;
try {
manifest = JSON.parse(cat(browserManifest));
} catch (e) {
echo('Malformed browser manifest file');
echo(e.message);
exit(1);
}
var executable;
manifest.forEach(function(browser) {
if (browser.name === 'chrome') {
executable = browser.path;
}
});
// If there was no chrome entry in the browser manifest, exit
2012-08-28 04:23:42 +09:00
if (!executable) {
echo('There was no \'chrome\' entry in the browser manifest');
exit(1);
}
// If we're on a Darwin (Mac) OS, then let's check for an .app path
if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) {
2012-08-28 01:09:33 +09:00
executable = executable + '/Contents/MacOS/Google Chrome';
}
// If the chrome executable doesn't exist
2012-08-28 04:23:42 +09:00
if (!test('-f', executable)) {
echo('Incorrect executable path to chrome');
exit(1);
}
// Let chrome pack the extension for us
exec('"' + executable + '"' +
' --no-message-box' +
' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
' "--pack-extension-key=' + pem + '"');
// Rename to pdf.js.crx
mv(BUILD_DIR + 'chrome.crx', CHROME_BUILD_DIR + 'pdf.js.crx');
};
2012-03-04 04:01:31 +09:00
///////////////////////////////////////////////////////////////////////////////////////////
//
// Test stuff
//
//
// make test
//
target.test = function() {
2012-04-20 04:32:24 +09:00
target.unittest({}, function() {
target.browsertest();
});
};
2012-03-04 04:01:31 +09:00
2012-03-29 06:06:41 +09:00
//
// make bottest
// (Special tests for the Github bot)
//
target.bottest = function() {
2012-04-20 04:54:53 +09:00
target.unittest({}, function() {
2012-11-02 08:10:47 +09:00
target.fonttest({}, function() {
target.browsertest({noreftest: true});
});
2012-04-20 04:32:24 +09:00
});
};
2012-03-04 04:01:31 +09:00
//
// make browsertest
//
2012-03-29 06:06:41 +09:00
target.browsertest = function(options) {
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
echo();
echo('### Running browser tests');
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
2012-08-23 03:34:34 +09:00
PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
2012-03-04 04:01:31 +09:00
if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
2012-08-23 03:34:34 +09:00
echo('Copy one of the examples in test/resources/browser_manifests/');
2012-03-04 04:01:31 +09:00
exit(1);
}
2012-03-30 04:04:12 +09:00
var reftest = (options && options.noreftest) ? '' : '--reftest';
2012-03-29 06:06:41 +09:00
2012-03-04 04:01:31 +09:00
cd('test');
2012-08-23 03:34:34 +09:00
exec(PYTHON_BIN + ' -u test.py ' + reftest + ' --browserManifestFile=' +
PDF_BROWSERS + ' --manifestFile=' + PDF_TEST, {async: true});
};
2012-03-04 04:01:31 +09:00
//
// make unittest
//
2012-04-20 04:32:24 +09:00
target.unittest = function(options, callback) {
2012-03-04 04:01:31 +09:00
cd(ROOT_DIR);
echo();
echo('### Running unit tests');
2012-08-23 03:34:34 +09:00
var PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
2012-04-20 04:32:24 +09:00
if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
2012-08-23 03:34:34 +09:00
echo('Copy one of the examples in test/resources/browser_manifests/');
2012-04-20 04:32:24 +09:00
exit(1);
}
callback = callback || function() {};
cd('test');
2012-08-23 03:34:34 +09:00
exec(PYTHON_BIN + ' -u test.py --unitTest --browserManifestFile=' +
PDF_BROWSERS, {async: true}, callback);
};
2012-03-04 04:01:31 +09:00
2012-11-02 08:10:47 +09:00
//
// make fonttest
//
target.fonttest = function(options, callback) {
cd(ROOT_DIR);
echo();
echo('### Running font tests');
var PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
echo('Copy one of the examples in test/resources/browser_manifests/');
exit(1);
}
callback = callback || function() {};
cd('test');
exec(PYTHON_BIN + ' -u test.py --fontTest --browserManifestFile=' +
PDF_BROWSERS, {async: true}, callback);
};
2012-03-30 04:04:12 +09:00
//
// make botmakeref
//
target.botmakeref = function() {
cd(ROOT_DIR);
echo();
echo('### Creating reference images');
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
2012-08-23 03:34:34 +09:00
PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
2012-03-30 04:04:12 +09:00
if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
2012-08-23 03:34:34 +09:00
echo('Copy one of the examples in test/resources/browser_manifests/');
2012-03-30 04:04:12 +09:00
exit(1);
}
cd('test');
2012-08-23 03:34:34 +09:00
exec(PYTHON_BIN + ' -u test.py --masterMode --noPrompts ' +
'--browserManifestFile=' + PDF_BROWSERS, {async: true});
};
////////////////////////////////////////////////////////////////////////////////
//
// Baseline operation
//
target.baseline = function() {
cd(ROOT_DIR);
echo();
echo('### Creating baseline environment');
var baselineCommit = env['BASELINE'];
if (!baselineCommit) {
echo('Baseline commit is not provided. Please specify BASELINE variable');
exit(1);
}
if (!test('-d', BUILD_DIR))
mkdir(BUILD_DIR);
var BASELINE_DIR = BUILD_DIR + 'baseline';
if (test('-d', BASELINE_DIR)) {
cd(BASELINE_DIR);
exec('git fetch origin');
} else {
cd(BUILD_DIR);
exec('git clone .. baseline');
cd(ROOT_DIR + BASELINE_DIR);
}
exec('git checkout ' + baselineCommit);
};
target.mozcentralbaseline = function() {
target.baseline();
cd(ROOT_DIR);
echo();
echo('### Creating mozcentral baseline environment');
var BASELINE_DIR = BUILD_DIR + 'baseline';
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
if (test('-d', MOZCENTRAL_BASELINE_DIR))
rm('-rf', MOZCENTRAL_BASELINE_DIR);
cd(BASELINE_DIR);
if (test('-d', 'build'))
rm('-rf', 'build');
exec('node make mozcentral');
cd(ROOT_DIR);
mkdir(MOZCENTRAL_BASELINE_DIR);
cp('-Rf', BASELINE_DIR + '/build/mozcentral/*', MOZCENTRAL_BASELINE_DIR);
// fixing baseline
if (test('-f', MOZCENTRAL_BASELINE_DIR +
'/browser/extensions/pdfjs/PdfStreamConverter.js')) {
rm(MOZCENTRAL_BASELINE_DIR +
'/browser/extensions/pdfjs/PdfStreamConverter.js');
}
cd(MOZCENTRAL_BASELINE_DIR);
exec('git init');
exec('git add .');
exec('git commit -m "mozcentral baseline"');
};
target.mozcentraldiff = function() {
target.mozcentral();
cd(ROOT_DIR);
echo();
echo('### Creating mozcentral diff');
var MOZCENTRAL_DIFF = BUILD_DIR + 'mozcentral.diff';
if (test('-f', MOZCENTRAL_DIFF))
rm(MOZCENTRAL_DIFF);
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
if (!test('-d', MOZCENTRAL_BASELINE_DIR)) {
echo('mozcentral baseline was not found');
echo('Please build one using "node make mozcentralbaseline"');
exit(1);
}
cd(MOZCENTRAL_BASELINE_DIR);
exec('git reset --hard');
cd(ROOT_DIR); rm('-rf', MOZCENTRAL_BASELINE_DIR + '/*'); // trying to be safe
cd(MOZCENTRAL_BASELINE_DIR);
cp('-Rf', '../mozcentral/*', '.');
exec('git add -A');
exec('git diff --binary --cached --unified=8', {silent: true}).output.
to('../mozcentral.diff');
echo('Result diff can be found at ' + MOZCENTRAL_DIFF);
};
target.mozcentralcheck = function() {
cd(ROOT_DIR);
echo();
echo('### Checking mozcentral changes');
var mcPath = env['MC_PATH'];
if (!mcPath) {
echo('mozilla-central path is not provided.');
echo('Please specify MC_PATH variable');
exit(1);
}
if ((mcPath[0] != '/' && mcPath[0] != '~' && mcPath[1] != ':') ||
!test('-d', mcPath)) {
echo('mozilla-central path is not in absolute form or does not exist.');
exit(1);
}
var MOZCENTRAL_DIFF = BUILD_DIR + 'mozcentral_changes.diff';
if (test('-f', MOZCENTRAL_DIFF)) {
rm(MOZCENTRAL_DIFF);
}
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
if (!test('-d', MOZCENTRAL_BASELINE_DIR)) {
echo('mozcentral baseline was not found');
echo('Please build one using "node make mozcentralbaseline"');
exit(1);
}
cd(MOZCENTRAL_BASELINE_DIR);
exec('git reset --hard');
cd(ROOT_DIR); rm('-rf', MOZCENTRAL_BASELINE_DIR + '/*'); // trying to be safe
cd(MOZCENTRAL_BASELINE_DIR);
mkdir('browser');
cd('browser');
mkdir('-p', 'extensions/pdfjs');
cp('-Rf', mcPath + '/browser/extensions/pdfjs/*', 'extensions/pdfjs');
mkdir('-p', 'locales/en-US/pdfviewer');
cp('-Rf', mcPath + '/browser/locales/en-US/pdfviewer/*',
'locales/en-US/pdfviewer');
// Remove '.DS_Store' and other hidden files
find('.').forEach(function(file) {
if (file.match(/^\.\w|~$/)) {
rm('-f', file);
}
});
cd('..');
exec('git add -A');
var diff = exec('git diff --binary --cached --unified=8',
{silent: true}).output;
if (diff) {
echo('There were changes found at mozilla-central.');
diff.to('../mozcentral_changes.diff');
echo('Result diff can be found at ' + MOZCENTRAL_DIFF);
exit(1);
}
echo('Success: there are no changes at mozilla-central');
};
2012-03-04 04:01:31 +09:00
///////////////////////////////////////////////////////////////////////////////////////////
//
// Other
//
//
// make server
//
target.server = function() {
cd(ROOT_DIR);
echo();
echo('### Starting local server');
cd('test');
exec(PYTHON_BIN + ' -u test.py --port=8888 --noDownload', {async: true});
};
2012-03-04 04:01:31 +09:00
//
// make lint
//
target.lint = function() {
cd(ROOT_DIR);
echo();
echo('### Linting JS files (this can take a while!)');
var LINT_FILES = ['make.js',
'external/builder/*.js',
'external/crlfchecker/*.js',
'src/*.js',
'web/*.js',
'test/*.js',
'test/unit/*.js',
'extensions/firefox/*.js',
'extensions/firefox/components/*.js',
'extensions/chrome/*.js'];
exec('gjslint --nojsdoc ' + LINT_FILES.join(' '));
2012-03-04 04:01:31 +09:00
crlfchecker.checkIfCrlfIsPresent(LINT_FILES);
};
2012-03-04 04:01:31 +09:00
2013-02-01 08:29:37 +09:00
//
// make jshint
//
target.jshint = function() {
cd(ROOT_DIR);
echo();
echo('### Linting JS files (this can take a while!)');
var LINT_FILES = ['make.js',
2013-02-01 08:29:37 +09:00
//'external/builder/*.js',
//'external/crlfchecker/*.js',
'src/',
//'web/*.js',
//'test/*.js',
//'test/unit/*.js',
//'extensions/firefox/*.js',
//'extensions/firefox/components/*.js',
//'extensions/chrome/*.js'
];
exec('jshint --reporter test/reporter.js ' + LINT_FILES.join(' '));
};
2012-03-04 04:01:31 +09:00
//
// make clean
//
target.clean = function() {
cd(ROOT_DIR);
echo();
echo('### Cleaning up project builds');
rm('-rf', BUILD_DIR);
};
2012-08-28 04:17:29 +09:00
//
// make makefile
//
target.makefile = function() {
var makefileContent = 'help:\n\tnode make\n\n';
2012-10-06 01:10:27 +09:00
var targetsNames = [];
2012-08-28 04:17:29 +09:00
for (var i in target) {
makefileContent += i + ':\n\tnode make ' + i + '\n\n';
2012-10-06 01:10:27 +09:00
targetsNames.push(i);
2012-08-28 04:17:29 +09:00
}
2012-10-06 01:10:27 +09:00
makefileContent += '.PHONY: ' + targetsNames.join(' ') + '\n';
2012-08-28 04:17:29 +09:00
makefileContent.to('Makefile');
};