Commit f5f98044 authored by jrw's avatar jrw Committed by Commit bot

Added support for enabling GCD, or not, at build time.

GCD support is off by default.

BUG=470744

Review URL: https://codereview.chromium.org/1007153003

Cr-Commit-Position: refs/heads/master@{#322430}
parent 70964960
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
# Set this to enable cast mode on the android client. # Set this to enable cast mode on the android client.
'enable_cast%': 0, 'enable_cast%': 0,
# Set this to use GCD instead of the remoting directory service.
'remoting_use_gcd%': 0,
'variables': { 'variables': {
'conditions': [ 'conditions': [
......
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
'<@(extra_files)', '<@(extra_files)',
'--locales_listfile', '--locales_listfile',
'<(dr_webapp_locales_listfile)', '<(dr_webapp_locales_listfile)',
'--use_gcd',
'<(remoting_use_gcd)',
], ],
}, },
], ],
......
...@@ -14,6 +14,7 @@ a zip archive for all of the above is produced. ...@@ -14,6 +14,7 @@ a zip archive for all of the above is produced.
# Python 2.5 compatibility # Python 2.5 compatibility
from __future__ import with_statement from __future__ import with_statement
import argparse
import io import io
import os import os
import platform import platform
...@@ -62,6 +63,36 @@ def replaceString(destination, placeholder, value): ...@@ -62,6 +63,36 @@ def replaceString(destination, placeholder, value):
"'" + placeholder + "'", "'" + value + "'") "'" + placeholder + "'", "'" + value + "'")
def replaceBool(destination, placeholder, value):
# Look for a "!!" in the source code so the expession we're
# replacing looks like a boolean to the compiler. A single "!"
# would satisfy the compiler but might confused human readers.
findAndReplace(os.path.join(destination, 'plugin_settings.js'),
"!!'" + placeholder + "'", 'true' if value else 'false')
def parseBool(boolStr):
"""Tries to parse a string as a boolean value.
Returns a bool on success; raises ValueError on failure.
"""
lower = boolStr.tolower()
if lower in ['0', 'false']: return False
if lower in ['1', 'true']: return True
raise ValueError('not a boolean string {!r}'.format(boolStr))
def getenvBool(name, defaultValue):
"""Gets an environment value as a boolean."""
rawValue = os.environ.get(name)
if rawValue is None:
return defaultValue
try:
return parseBool(rawValue)
except ValueError:
raise Exception('Value of ${} must be boolean!'.format(name))
def processJinjaTemplate(input_file, include_paths, output_file, context): def processJinjaTemplate(input_file, include_paths, output_file, context):
jinja2_path = os.path.normpath( jinja2_path = os.path.normpath(
os.path.join(os.path.abspath(__file__), os.path.join(os.path.abspath(__file__),
...@@ -76,9 +107,9 @@ def processJinjaTemplate(input_file, include_paths, output_file, context): ...@@ -76,9 +107,9 @@ def processJinjaTemplate(input_file, include_paths, output_file, context):
io.open(output_file, 'w', encoding='utf-8').write(rendered) io.open(output_file, 'w', encoding='utf-8').write(rendered)
def buildWebApp(buildtype, version, destination, zip_path, def buildWebApp(buildtype, version, destination, zip_path,
manifest_template, webapp_type, app_id, app_name, manifest_template, webapp_type, appid, app_name,
app_description, app_capabilities, files, locales, jinja_paths, app_description, app_capabilities, files, locales_listfile,
service_environment): jinja_paths, service_environment, use_gcd):
"""Does the main work of building the webapp directory and zipfile. """Does the main work of building the webapp directory and zipfile.
Args: Args:
...@@ -89,7 +120,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -89,7 +120,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
contents of |destination|. contents of |destination|.
manifest_template: jinja2 template file for manifest. manifest_template: jinja2 template file for manifest.
webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting").
app_id: A string with the Remoting Application Id (only used for app appid: A string with the Remoting Application Id (only used for app
remoting webapps). If supplied, it defaults to using the remoting webapps). If supplied, it defaults to using the
test API server. test API server.
app_name: A string with the name of the application. app_name: A string with the name of the application.
...@@ -98,13 +129,24 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -98,13 +129,24 @@ def buildWebApp(buildtype, version, destination, zip_path,
enabled for this application. enabled for this application.
files: An array of strings listing the paths for resources to include files: An array of strings listing the paths for resources to include
in this webapp. in this webapp.
locales: An array of strings listing locales, which are copied, along locales_listfile: The name of a file containing a list of locales, one per
with their directory structure from the _locales directory down. line, which are copied, along with their directory structure, from
the _locales directory down.
jinja_paths: An array of paths to search for {%include} directives in jinja_paths: An array of paths to search for {%include} directives in
addition to the directory containing the manifest template. addition to the directory containing the manifest template.
service_environment: Used to point the webApp to one of the service_environment: Used to point the webApp to one of the
dev/test/staging/prod environments dev/test/staging/prod environments
use_gcd: True if GCD support should be enabled.
""" """
# Load the locales files from the locales_listfile.
if not locales_listfile:
raise Exception('You must specify a locales_listfile')
locales = []
with open(locales_listfile) as input:
for s in input:
locales.append(s.rstrip())
# Ensure a fresh directory. # Ensure a fresh directory.
try: try:
shutil.rmtree(destination) shutil.rmtree(destination)
...@@ -190,8 +232,8 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -190,8 +232,8 @@ def buildWebApp(buildtype, version, destination, zip_path,
+ buildtype + ': ' + service_environment) + buildtype + ': ' + service_environment)
if 'out/Release' not in destination and 'out\Release' not in destination: if 'out/Release' not in destination and 'out\Release' not in destination:
raise Exception('Prod builds must be placed in the out/Release folder') raise Exception('Prod builds must be placed in the out/Release folder')
if app_id != None: if appid != None:
raise Exception('Cannot pass in an app_id for ' raise Exception('Cannot pass in an appid for '
+ buildtype + ' builds: ' + service_environment) + buildtype + ' builds: ' + service_environment)
if appRemotingApiHost != None: if appRemotingApiHost != None:
raise Exception('Cannot set APP_REMOTING_API_HOST env var for ' raise Exception('Cannot set APP_REMOTING_API_HOST env var for '
...@@ -202,7 +244,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -202,7 +244,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
# If an Application ID was set (either from service_environment variable or # If an Application ID was set (either from service_environment variable or
# from a command line argument), hardcode it, otherwise get it at runtime. # from a command line argument), hardcode it, otherwise get it at runtime.
effectiveAppId = appRemotingApplicationId or app_id effectiveAppId = appRemotingApplicationId or appid
if effectiveAppId: if effectiveAppId:
appRemotingApplicationId = "'" + effectiveAppId + "'" appRemotingApplicationId = "'" + effectiveAppId + "'"
else: else:
...@@ -236,6 +278,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -236,6 +278,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
else: else:
appRemotingApiBaseUrl = '' appRemotingApiBaseUrl = ''
replaceBool(destination, 'USE_GCD', use_gcd)
replaceString(destination, 'OAUTH2_BASE_URL', oauth2BaseUrl) replaceString(destination, 'OAUTH2_BASE_URL', oauth2BaseUrl)
replaceString(destination, 'OAUTH2_API_BASE_URL', oauth2ApiBaseUrl) replaceString(destination, 'OAUTH2_API_BASE_URL', oauth2ApiBaseUrl)
replaceString(destination, 'DIRECTORY_API_BASE_URL', directoryApiBaseUrl) replaceString(destination, 'DIRECTORY_API_BASE_URL', directoryApiBaseUrl)
...@@ -284,10 +327,9 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -284,10 +327,9 @@ def buildWebApp(buildtype, version, destination, zip_path,
"'OAUTH2_REDIRECT_URL'", oauth2RedirectUrlJs) "'OAUTH2_REDIRECT_URL'", oauth2RedirectUrlJs)
# Configure xmpp server and directory bot settings in the plugin. # Configure xmpp server and directory bot settings in the plugin.
findAndReplace(os.path.join(destination, 'plugin_settings.js'), replaceBool(
"Boolean('XMPP_SERVER_USE_TLS')", destination, 'XMPP_SERVER_USE_TLS',
os.environ.get('XMPP_SERVER_USE_TLS', 'true')) getenvBool('XMPP_SERVER_USE_TLS', True))
xmppServer = os.environ.get('XMPP_SERVER', xmppServer = os.environ.get('XMPP_SERVER',
'talk.google.com:443') 'talk.google.com:443')
replaceString(destination, 'XMPP_SERVER', xmppServer) replaceString(destination, 'XMPP_SERVER', xmppServer)
...@@ -339,6 +381,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -339,6 +381,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
'APP_NAME': app_name, 'APP_NAME': app_name,
'APP_DESCRIPTION': app_description, 'APP_DESCRIPTION': app_description,
'OAUTH_GDRIVE_SCOPE': '', 'OAUTH_GDRIVE_SCOPE': '',
'USE_GCD': use_gcd,
'XMPP_SERVER': xmppServer, 'XMPP_SERVER': xmppServer,
} }
if 'GOOGLE_DRIVE' in app_capabilities: if 'GOOGLE_DRIVE' in app_capabilities:
...@@ -356,72 +399,28 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -356,72 +399,28 @@ def buildWebApp(buildtype, version, destination, zip_path,
def main(): def main():
if len(sys.argv) < 6: parser = argparse.ArgumentParser()
print ('Usage: build-webapp.py ' parser.add_argument('buildtype')
'<build-type> <version> <dst> <zip-path> <manifest_template> ' parser.add_argument('version')
'<webapp_type> <other files...> ' parser.add_argument('destination')
'--app_name <name> ' parser.add_argument('zip_path')
'--app_description <description> ' parser.add_argument('manifest_template')
'--app_capabilities <capabilities...> ' parser.add_argument('webapp_type')
'[--appid <appid>] ' parser.add_argument('files', nargs='*', metavar='file', default=[])
'[--locales_listfile <locales-listfile-name>] ' parser.add_argument('--app_name', metavar='NAME')
'[--jinja_paths <paths...>] ' parser.add_argument('--app_description', metavar='TEXT')
'[--service_environment <service_environment>]') parser.add_argument('--app_capabilities',
return 1 nargs='*', default=[], metavar='CAPABILITY')
parser.add_argument('--appid')
arg_type = '' parser.add_argument('--locales_listfile', default='', metavar='PATH')
files = [] parser.add_argument('--jinja_paths', nargs='*', default=[], metavar='PATH')
locales_listfile = '' parser.add_argument('--service_environment', default='', metavar='ENV')
jinja_paths = [] parser.add_argument('--use_gcd', choices=['0', '1'], default='0')
app_id = None
app_name = None args = parser.parse_args()
app_description = None args.use_gcd = (args.use_gcd != '0')
app_capabilities = set([]) args.app_capabilities = set(args.app_capabilities)
service_environment = '' return buildWebApp(**vars(args))
for arg in sys.argv[7:]:
if arg in ['--locales_listfile',
'--jinja_paths',
'--appid',
'--app_name',
'--app_description',
'--app_capabilities',
'--service_environment']:
arg_type = arg
elif arg_type == '--locales_listfile':
locales_listfile = arg
arg_type = ''
elif arg_type == '--jinja_paths':
jinja_paths.append(arg)
elif arg_type == '--appid':
app_id = arg
arg_type = ''
elif arg_type == '--app_name':
app_name = arg
arg_type = ''
elif arg_type == '--app_description':
app_description = arg
arg_type = ''
elif arg_type == '--app_capabilities':
app_capabilities.add(arg)
elif arg_type == '--service_environment':
service_environment = arg
arg_type = ''
else:
files.append(arg)
# Load the locales files from the locales_listfile.
if not locales_listfile:
raise Exception('You must specify a locales_listfile')
locales = []
with open(locales_listfile) as input:
for s in input:
locales.append(s.rstrip())
return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4],
sys.argv[5], sys.argv[6], app_id, app_name,
app_description, app_capabilities, files, locales,
jinja_paths, service_environment)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -41,7 +41,7 @@ remoting.Settings.prototype.TALK_GADGET_URL = 'TALK_GADGET_URL'; ...@@ -41,7 +41,7 @@ remoting.Settings.prototype.TALK_GADGET_URL = 'TALK_GADGET_URL';
*/ */
remoting.Settings.prototype.OAUTH2_REDIRECT_URL = function() { remoting.Settings.prototype.OAUTH2_REDIRECT_URL = function() {
return 'OAUTH2_REDIRECT_URL'; return 'OAUTH2_REDIRECT_URL';
} };
/** @type {string} Base URL for the App Remoting API. */ /** @type {string} Base URL for the App Remoting API. */
remoting.Settings.prototype.APP_REMOTING_API_BASE_URL = remoting.Settings.prototype.APP_REMOTING_API_BASE_URL =
...@@ -67,7 +67,7 @@ remoting.Settings.prototype.DIRECTORY_BOT_JID = 'DIRECTORY_BOT_JID'; ...@@ -67,7 +67,7 @@ remoting.Settings.prototype.DIRECTORY_BOT_JID = 'DIRECTORY_BOT_JID';
remoting.Settings.prototype.XMPP_SERVER = 'XMPP_SERVER'; remoting.Settings.prototype.XMPP_SERVER = 'XMPP_SERVER';
/** @type {boolean} Whether to use TLS on connections to the XMPP server. */ /** @type {boolean} Whether to use TLS on connections to the XMPP server. */
remoting.Settings.prototype.XMPP_SERVER_USE_TLS = remoting.Settings.prototype.XMPP_SERVER_USE_TLS =
Boolean('XMPP_SERVER_USE_TLS'); !!'XMPP_SERVER_USE_TLS';
// Third party authentication settings. // Third party authentication settings.
/** @type {string} The third party auth redirect URI. */ /** @type {string} The third party auth redirect URI. */
...@@ -76,3 +76,6 @@ remoting.Settings.prototype.THIRD_PARTY_AUTH_REDIRECT_URI = ...@@ -76,3 +76,6 @@ remoting.Settings.prototype.THIRD_PARTY_AUTH_REDIRECT_URI =
// 'native', 'nacl' or 'pnacl'. // 'native', 'nacl' or 'pnacl'.
remoting.Settings.prototype.CLIENT_PLUGIN_TYPE = 'CLIENT_PLUGIN_TYPE'; remoting.Settings.prototype.CLIENT_PLUGIN_TYPE = 'CLIENT_PLUGIN_TYPE';
/** @const {boolean} If true, use GCD instead of Chromoting registry. */
remoting.Settings.prototype.USE_GCD = !!'USE_GCD';
...@@ -53,7 +53,12 @@ ...@@ -53,7 +53,12 @@
"oauth2": { "oauth2": {
"client_id": "{{ REMOTING_IDENTITY_API_CLIENT_ID }}", "client_id": "{{ REMOTING_IDENTITY_API_CLIENT_ID }}",
"scopes": [ "scopes": [
"https://www.googleapis.com/auth/chromoting https://www.googleapis.com/auth/googletalk https://www.googleapis.com/auth/userinfo#email" {% if USE_GCD %}
"https://www.googleapis.com/auth/clouddevices",
{% endif %}
"https://www.googleapis.com/auth/chromoting",
"https://www.googleapis.com/auth/googletalk",
"https://www.googleapis.com/auth/userinfo#email"
] ]
}, },
"sandbox": { "sandbox": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment