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 #22774 from yurenju/app-makefile-2
Browse files Browse the repository at this point in the history
Bug 1029385 - Rewrite app-makefile rule in javascript
  • Loading branch information
yurenju committed Aug 19, 2014
2 parents bf52411 + 4a20760 commit 1c96181
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 74 deletions.
44 changes: 7 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -485,25 +485,6 @@ endef

export BUILD_CONFIG

define app-makefile-template
.PHONY: $(1)
$(1): $(XULRUNNER_BASE_DIRECTORY) pre-app | $(STAGE_DIR)
@if [[ ("$(2)" =~ "${BUILD_APP_NAME}") || ("${BUILD_APP_NAME}" == "*") ]]; then \
if [ -r "$(2)$(SEP)Makefile" ]; then \
echo "execute Makefile for $(1) app" ; \
STAGE_APP_DIR="../../build_stage/$(1)" make -C "$(2)" ; \
else \
echo "copy $(1) to build_stage/" ; \
cp -LR "$(2)" $(STAGE_DIR) && \
if [ -r "$(2)$(SEP)build$(SEP)build.js" ]; then \
echo "execute $(1)/build/build.js"; \
export APP_DIR=$(2); \
$(call run-js-command,app/build); \
fi; \
fi; \
fi;
endef

include build/common.mk

# Generate profile/
Expand All @@ -515,29 +496,18 @@ endif
$(STAGE_DIR):
mkdir -p $@

ifeq (${BUILD_APP_NAME},*)
APP_RULES := $(foreach appdir,$(GAIA_APPDIRS),$(notdir $(appdir)))
else
APP_RULES := ${BUILD_APP_NAME}
endif
$(foreach appdir,$(GAIA_APPDIRS), \
$(eval $(call app-makefile-template,$(notdir $(appdir)),$(appdir))) \
)


# FIXME: we use |STAGE_APP_DIR="../../build_stage/$$APP"| here because we got
# some problem on Windows if use absolute path.
.PHONY: app-makefiles
app-makefiles: $(APP_RULES)

LANG=POSIX # Avoiding sort order differences between OSes

.PHONY: pre-app
pre-app: $(XULRUNNER_BASE_DIRECTORY) $(STAGE_DIR)
@$(call run-js-command,pre-app)

.PHONY: app
app: $(XULRUNNER_BASE_DIRECTORY) pre-app | $(STAGE_DIR)
@$(call run-js-command,app)

.PHONY: post-app
post-app: app-makefiles pre-app $(XULRUNNER_BASE_DIRECTORY)
post-app: app pre-app $(XULRUNNER_BASE_DIRECTORY)
@$(call run-js-command,post-app)

# Keep old targets just for people/scripts still using it
Expand Down Expand Up @@ -576,7 +546,7 @@ endif
endif

# Create webapps
offline: app-makefiles post-app
offline: app post-app

# Create an empty reference workload
.PHONY: reference-workload-empty
Expand Down Expand Up @@ -752,7 +722,7 @@ test-perf:
./bin/gaia-perf-marionette

.PHONY: tests
tests: app-makefiles offline
tests: app offline
echo "Checking if the mozilla build has tests enabled..."
test -d $(MOZ_TESTS) || (echo "Please ensure you don't have |ac_add_options --disable-tests| in your mozconfig." && exit 1)
echo "Checking the injected Gaia..."
Expand Down
1 change: 1 addition & 0 deletions apps/browser/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ BrowserAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new BrowserAppBuilder()).execute(options);
};
1 change: 0 additions & 1 deletion apps/calendar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.PHONY: $(STAGE_APP_DIR)

$(STAGE_APP_DIR):
cp -r "$(CURDIR)" "$(STAGE_DIR)"
@$(call run-js-command,app/build)

.PHONY: web_assets
Expand Down
1 change: 1 addition & 0 deletions apps/calendar/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var utils = require('utils');

function execute(config) {
utils.copyToStage(config);
var distDir = config.GAIA_DISTRIBUTION_DIR;

// Calendar Config
Expand Down
32 changes: 0 additions & 32 deletions apps/camera/Makefile

This file was deleted.

4 changes: 3 additions & 1 deletion apps/camera/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function optimize(options) {
var r = require('r-wrapper').get(options.GAIA_DIR);
var configFile = utils.getFile(options.APP_DIR, 'build',
'require_config.jslike');
r.optimize([configFile.path]);
var optimizeOption = 'optimize=' + (options.GAIA_OPTIMIZE === '1' ?
'uglify2' : 'none');
r.optimize([configFile.path, optimizeOption]);
}

function copyUserConfig(options) {
Expand Down
1 change: 1 addition & 0 deletions apps/collection/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ CollectionAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new CollectionAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/communications/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ CommAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new CommAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/findmydevice/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var utils = require('utils');

function execute(config) {
utils.copyToStage(config);
var init = utils.getFile(config.STAGE_APP_DIR, 'js', 'config.js');
var content = {
'api_url': 'https://find.firefox.com',
Expand Down
1 change: 1 addition & 0 deletions apps/ftu/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ FtuAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new FtuAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/gallery/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ GalleryAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new GalleryAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/homescreen/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,6 @@ HomescreenAppBuilder.prototype.customizeSettings = function(origin, custom) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new HomescreenAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/music/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var utils = require('utils');

exports.execute = function(options) {
utils.copyToStage(options);
var sharedPath = utils.gaia.getInstance(options).sharedFolder.path;
var paths = [
[sharedPath, 'js', 'blobview.js'],
Expand Down
1 change: 1 addition & 0 deletions apps/operatorvariant/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ OperatorAppBuilder.prototype.getSingleVariantResources = function(svConfFile) {
};

OperatorAppBuilder.prototype.execute = function(options) {
utils.copyToStage(options);
this.setOptions(options);
this.generateCustomizeResources(options);
};
Expand Down
1 change: 1 addition & 0 deletions apps/system/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SystemAppBuilder.prototype.initConfigJsons = function() {
};

SystemAppBuilder.prototype.execute = function(options) {
utils.copyToStage(options);
this.setOptions(options);
this.initConfigJsons();
if (this.distDirPath) {
Expand Down
1 change: 1 addition & 0 deletions apps/verticalhome/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ VerticalHomeAppBuilder.prototype.execute = function(options) {
};

exports.execute = function(options) {
utils.copyToStage(options);
(new VerticalHomeAppBuilder()).execute(options);
};
1 change: 1 addition & 0 deletions apps/wallpaper/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ WallPaperAppBuilder.prototype.copyWallpapers = function() {
};

WallPaperAppBuilder.prototype.execute = function(options) {
utils.copyToStage(options);
this.setOptions(options);

this.copyWallpapers();
Expand Down
1 change: 1 addition & 0 deletions apps/wappush/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var utils = require('utils');

function execute(config) {
utils.copyToStage(config);
var distDir = config.GAIA_DISTRIBUTION_DIR;

var file = utils.getFile(config.STAGE_APP_DIR, 'js', 'whitelist.json');
Expand Down
36 changes: 36 additions & 0 deletions build/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

/* global exports, require */

var utils = require('utils');

exports.execute = function(options) {
var appRegExp;
try {
appRegExp = utils.getAppNameRegex(options.BUILD_APP_NAME);
} catch (e) {
utils.log('utils', 'Using an invalid regular expression for APP ' +
'environment variable, APP=' + options.BUILD_APP_NAME);
throw e;
}

options.GAIA_APPDIRS.split(' ').forEach(function(appDir) {
let appDirFile = utils.getFile(appDir);

if (appRegExp.test(appDirFile.leafName)) {
let appOptions = utils.cloneJSON(options);
let stageAppDir = utils.getFile(options.STAGE_DIR, appDirFile.leafName);

appOptions.APP_DIR = appDirFile.path;
appOptions.STAGE_APP_DIR = stageAppDir.path;

let buildFile = utils.getFile(appDir, 'build', 'build.js');
if (buildFile.exists()) {
utils.log('app', 'building ' + appDirFile.leafName + ' app...');
require(appDirFile.leafName + '/build').execute(appOptions);
} else {
utils.copyToStage(appOptions);
}
}
});
};
73 changes: 73 additions & 0 deletions build/test/unit/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

var assert = require('chai').assert;
var proxyquire = require('proxyquire');
var mockUtils = require('./mock_utils.js');

suite('app.js', function() {
var app;
var files = [];
var copied = false;
var existed = false;
var stageDir = '/path/to/build_stage';
var applist = ['app1', 'app2', 'app3'];
var options = {
GAIA_APPDIRS: '/path/to/app1 /path/to/app2 /path/to/app3',
STAGE_DIR: stageDir
};

setup(function() {
var stubs = {
'utils': mockUtils
};
app = proxyquire.noCallThru().load('../../app', stubs);

mockUtils.getFile = function() {
var path = Array.prototype.slice.call(arguments, 0).join('/');
var file = {
path: path,
leafName: path.split('/').pop(),
exists: function() { return existed; }
};
files.push(file);
return file;
};

mockUtils.copyToStage = function(options) {
copied = true;
};
});

test('BUILD_APP_NAME = *', function() {
options.BUILD_APP_NAME = '*';
app.execute(options);

applist.forEach(function(appName, i) {
var baseIdx = i * applist.length;
assert.equal(files[baseIdx].path, '/path/to/' + appName,
'1st file which access in app.js should be app absolute dir');
assert.equal(files[baseIdx + 1].path, stageDir + '/' + appName,
'2nd file which access in app.js should be app dir in build_stage');
assert.equal(files[baseIdx + 2].path,
'/path/to/' + appName + '/build/build.js',
'3rd file which access in app.js should be build script in app dir');
});
});

test('BUILD_APP_NAME = app1', function() {
var appName = 'app1';
options.BUILD_APP_NAME = appName;
app.execute(options);
assert.equal(files[0].path, '/path/to/' + appName,
'1st file which access in app.js should be app absolute dir');
assert.equal(files[1].path, stageDir + '/' + appName,
'2nd file which access in app.js should be app dir in build_stage');
assert.equal(files[2].path,
'/path/to/' + appName + '/build/build.js',
'3rd file which access in app.js should be build script in app dir');
});

teardown(function() {
files = [];
});
});
8 changes: 8 additions & 0 deletions build/test/unit/mock_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ exports.isSubjectToDeviceType = function(path) {
return /locales[\/\\]?[a-zA-Z]*[\/\\]?device_type$/.test(path);
};

exports.cloneJSON = function(obj) {
return JSON.parse(JSON.stringify(obj));
};

exports.existsInAppDirs = function(appDirs, appName) {
var apps = appDirs.split(' ');
var exists = apps.some(function (appPath) {
Expand All @@ -86,6 +90,10 @@ exports.existsInAppDirs = function(appDirs, appName) {
return exists;
};

exports.getAppNameRegex = function(buildAppName) {
return buildAppName === '*' ? /.+/ : new RegExp(buildAppName);
};

exports.scriptLoader = {
load: function load() {}
};
6 changes: 6 additions & 0 deletions build/utils-xpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ function copyDirTo(path, toParent, name, override) {
});
}

function copyToStage(options) {
var appDir = getFile(options.APP_DIR);
copyDirTo(appDir, options.STAGE_DIR, appDir.leafName);
}

/**
* Create standard XMLHttpRequest object.
* Note: this function is a wrapper function for node.js
Expand Down Expand Up @@ -1220,6 +1225,7 @@ exports.mkdirs = mkdirs;
exports.joinPath = joinPath;
exports.copyFileTo = copyFileTo;
exports.copyDirTo = copyDirTo;
exports.copyToStage = copyToStage;
exports.createXMLHttpRequest = createXMLHttpRequest;
exports.downloadJSON = downloadJSON;
exports.readJSONFromPath = readJSONFromPath;
Expand Down
Loading

0 comments on commit 1c96181

Please sign in to comment.