This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15835 from comoyo/build-keyboard
Bug 964216 - Use build_stage to build keyboard app. r=janjongboom
- Loading branch information
Showing
154 changed files
with
260 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +0,0 @@ | ||
/js/imes | ||
/js/imes/\!latin | ||
/js/imes/latin/dictionaries/*.dict | ||
/js/layouts/*.js | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
The keyboard app uses large dictionary files for autocorrection. If we | ||
include all the dictionaries we have, our builds become too large. So | ||
the keyboard is configured at build time to include only the layouts | ||
and dictionaries we need for a particular build. | ||
the keyboard is configured at build time to include only the IMEs, | ||
layouts, and dictionaries we need for a particular build. | ||
|
||
Dictionaries live in gaia/keyboard/dictionaries and layouts are | ||
defined in gaia/keyboard/layouts. Files are copied into this app, but | ||
are not checked into github in this app. | ||
Dictionaries files currently only apply for the latin IME and live in | ||
js/imes/latin/dictionaries, along with the source files (in XML) in | ||
Android format. There is a Makefile present to convert the source files | ||
into Firefox OS dictionaries. | ||
|
||
At build time we only package the IMEs and dictionaries required by the | ||
specified keyboard layouts. | ||
|
||
We also configure the manifest.webapp file at build time, to add entry | ||
points for each layout. | ||
|
||
Configuration is done with the GAIA_KEYBOARD_LAYOUTS environment | ||
variable, and there is a default value defined in the Makefile. | ||
|
||
The actual configuration code is in build/keyboard-config.js. The | ||
functions defined by that file are used by build/application-data.js | ||
and build/webapp-manifests.js | ||
|
||
The build happens in gaia/build_stage. | ||
The actual configuration code is in build/keyboard-config.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
ifndef GAIA_BUILD_DIR | ||
GAIA_BUILD_DIR=$(PWD)/build | ||
endif | ||
|
||
BUILD_DIR=$(PWD)/build_stage/keyboard | ||
|
||
.PHONY: all clean | ||
all: clean | ||
@echo Building keyboard app to build_stage... | ||
@mkdir -p $(BUILD_DIR) | ||
@$(XULRUNNERSDK) $(XPCSHELLSDK) \ | ||
-e "const GAIA_BUILD_DIR='$(GAIA_BUILD_DIR)'" \ | ||
-e "const APP_BUILD_DIR='$(GAIA_BUILD_DIR)../apps/keyboard/build/'" \ | ||
-f ../../build/xpcshell-commonjs.js \ | ||
-e "try { require('app/build').execute($$BUILD_CONFIG); quit(0);} \ | ||
catch(e) { \ | ||
dump('Exception: ' + e + '\n' + e.stack + '\n'); \ | ||
throw(e); \ | ||
}" | ||
|
||
clean: | ||
@rm -rf $(BUILD_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
'use strict'; | ||
|
||
/* global require, exports */ | ||
|
||
var utils = require('utils'); | ||
var keyboardConfig = require('./keyboard-config'); | ||
|
||
var KeyboardAppBuilder = function() { | ||
}; | ||
KeyboardAppBuilder.prototype.APP_DIR = 'apps/keyboard'; | ||
KeyboardAppBuilder.prototype.DIST_DIR = 'build_stage/keyboard'; | ||
|
||
// set options | ||
KeyboardAppBuilder.prototype.setOptions = function(options) { | ||
this.allLayouts = options.GAIA_KEYBOARD_LAYOUTS.split(','); | ||
|
||
var distDirPath = [options.GAIA_DIR].concat(this.DIST_DIR.split('/')); | ||
this.distDir = utils.getFile.apply(utils, distDirPath); | ||
|
||
var appDirPath = [options.GAIA_DIR].concat(this.APP_DIR.split('/')); | ||
this.appDir = utils.getFile.apply(utils, appDirPath); | ||
}; | ||
|
||
KeyboardAppBuilder.prototype.getLayoutsForVersion = function(version) { | ||
var layouts = []; | ||
switch (version) { | ||
case 'one': | ||
this.allLayouts.forEach(function(layoutName) { | ||
var file = utils.getFile( | ||
this.appDir.path, 'js', 'layouts', layoutName + '.js'); | ||
if (file.exists()) { | ||
layouts.push(layoutName); | ||
} | ||
}.bind(this)); | ||
|
||
break; | ||
|
||
case 'two': | ||
// TBD | ||
|
||
break; | ||
} | ||
|
||
return layouts; | ||
}; | ||
|
||
KeyboardAppBuilder.prototype.throwForNoneExistLayouts = function() { | ||
this.allLayouts.forEach(function(layoutName) { | ||
if (this.versionOneLayouts.indexOf(layoutName) === -1 && | ||
this.versionTwoLayouts.indexOf(layoutName) === -1) { | ||
throw new Error('Keyboard layout ' + layoutName + '.js specified by ' + | ||
'GAIA_KEYBOARD_LAYOUTS not found.'); | ||
} | ||
}.bind(this)); | ||
}; | ||
|
||
// Copy static files to build_stage. | ||
KeyboardAppBuilder.prototype.copyStaticFiles = function() { | ||
// Files to blindly copy to build_stage regardless of versions | ||
var filenames = ['resources']; | ||
var dirs = []; | ||
|
||
if (this.versionOneLayouts.length) { | ||
dirs = dirs.concat('js', 'js/imes', 'js/imes/latin'); | ||
// Unfortunately we have to explicitly list many files here | ||
// because the whitelist most not include optional layout | ||
// specific files. | ||
filenames = filenames.concat('index.html', 'locales', | ||
'settings.html', 'style', | ||
'js/keyboard.js', 'js/layout.js', | ||
'js/render.js', 'js/settings', | ||
'js/imes/latin/latin.js', | ||
'js/imes/latin/predictions.js', | ||
'js/imes/latin/worker.js'); | ||
} | ||
if (this.versionTwoLayouts.length) { | ||
/* TBD, maybe | ||
filenames = filenames.concat('index2.html', 'style2', 'js2'); | ||
and move more shared files out of the two `if` blocks. | ||
*/ | ||
} | ||
|
||
dirs.forEach(function(dirName) { | ||
var dir = utils.getFile.apply(utils, | ||
[this.appDir.path].concat(dirName.split('/'))); | ||
utils.ensureFolderExists(dir); | ||
}.bind(this)); | ||
|
||
filenames.forEach(function(filename) { | ||
var filenameArr = filename.split('/'); | ||
|
||
var file = utils.getFile.apply(utils, | ||
[this.appDir.path].concat(filenameArr)); | ||
var distSubDir = utils.getFile.apply(utils, | ||
[this.distDir.path].concat(filenameArr.slice(0, filenameArr.length - 1))); | ||
file.copyTo(distSubDir, file.leafName); | ||
}.bind(this)); | ||
}; | ||
|
||
KeyboardAppBuilder.prototype.copyLayouts = function() { | ||
// XXX we probably need better separation between this | ||
// and keyboard-config.js | ||
|
||
// For v1 keyboard | ||
keyboardConfig.copyLayoutsAndResources( | ||
this.appDir, this.distDir, this.versionOneLayouts); | ||
|
||
// TBD: v2 | ||
}; | ||
|
||
KeyboardAppBuilder.prototype.generateManifest = function() { | ||
// XXX we probably need better separation between this | ||
// and keyboard-config.js | ||
|
||
var manifest = | ||
utils.getJSON(utils.getFile(this.appDir.path, 'manifest.webapp')); | ||
|
||
// For v1 keyboard | ||
manifest = keyboardConfig.addEntryPointsToManifest( | ||
this.appDir, this.distDir, this.versionOneLayouts, manifest); | ||
|
||
// TBD: v2 | ||
|
||
// Write content to build_stage | ||
utils.writeContent(utils.getFile(this.distDir.path, 'manifest.webapp'), | ||
JSON.stringify(manifest)); | ||
}; | ||
|
||
KeyboardAppBuilder.prototype.execute = function(options) { | ||
this.setOptions(options); | ||
|
||
// Check against allLayouts. Most of the code should be gone with v1 keyboard. | ||
this.versionOneLayouts = this.getLayoutsForVersion('one'); | ||
this.versionTwoLayouts = this.getLayoutsForVersion('two'); | ||
this.throwForNoneExistLayouts(); | ||
|
||
this.copyStaticFiles(); | ||
this.copyLayouts(); | ||
this.generateManifest(); | ||
}; | ||
|
||
exports.execute = function(options) { | ||
// We cannot export prototype functions out :( | ||
// so we run execute() this way. | ||
(new KeyboardAppBuilder()).execute(options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dir": "../../build_stage/keyboard" | ||
} |
Oops, something went wrong.