Commit 03380671 authored by garykac's avatar garykac Committed by Commit bot

[Chromoting] Update build-webapp.py to support app_remoting webapps.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#300197}
parent 4436048a
...@@ -61,36 +61,47 @@ def replaceString(destination, placeholder, value): ...@@ -61,36 +61,47 @@ def replaceString(destination, placeholder, value):
"'" + placeholder + "'", "'" + value + "'") "'" + placeholder + "'", "'" + value + "'")
def processJinjaTemplate(input_file, 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__),
'../../../third_party/jinja2')) '../../../third_party/jinja2'))
sys.path.append(os.path.split(jinja2_path)[0]) sys.path.append(os.path.split(jinja2_path)[0])
import jinja2 import jinja2
(template_path, template_name) = os.path.split(input_file) (template_path, template_name) = os.path.split(input_file)
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path)) include_paths = [template_path] + include_paths
env = jinja2.Environment(loader=jinja2.FileSystemLoader(include_paths))
template = env.get_template(template_name) template = env.get_template(template_name)
rendered = template.render(context) rendered = template.render(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, files, locales): manifest_template, webapp_type, app_id, app_name,
app_description, files, locales, jinja_paths,
service_environment):
"""Does the main work of building the webapp directory and zipfile. """Does the main work of building the webapp directory and zipfile.
Args: Args:
buildtype: the type of build ("Official" or "Dev"). buildtype: the type of build ("Official", "Release" or "Dev").
destination: A string with path to directory where the webapp will be destination: A string with path to directory where the webapp will be
written. written.
zipfile: A string with path to the zipfile to create containing the zipfile: A string with path to the zipfile to create containing the
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" or "v2_pnacl"). webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting").
app_id: A string with the Remoting Application Id (only used for app
remoting webapps). If supplied, it defaults to using the
test API server.
app_name: A string with the name of the application.
app_description: A string with the description of the 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: An array of strings listing locales, which are copied, along
with their directory structure from the _locales directory down. with their directory structure from the _locales directory down.
jinja_paths: An array of paths to search for {%include} directives in
addition to the directory containing the manifest template.
service_environment: Used to point the webApp to one of the
dev/test/staging/prod environments
""" """
# Ensure a fresh directory. # Ensure a fresh directory.
try: try:
...@@ -102,6 +113,9 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -102,6 +113,9 @@ def buildWebApp(buildtype, version, destination, zip_path,
pass pass
os.mkdir(destination, 0775) os.mkdir(destination, 0775)
if buildtype != "Official" and buildtype != "Release" and buildtype != "Dev":
raise Exception("Unknown buildtype: " + buildtype);
# Use symlinks on linux and mac for faster compile/edit cycle. # Use symlinks on linux and mac for faster compile/edit cycle.
# #
# On Windows Vista platform.system() can return 'Microsoft' with some # On Windows Vista platform.system() can return 'Microsoft' with some
...@@ -150,6 +164,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -150,6 +164,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
raise Exception("Unknown extension: " + current_locale); raise Exception("Unknown extension: " + current_locale);
# Set client plugin type. # Set client plugin type.
# TODO(wez): Use 'native' in app_remoting until b/17441659 is resolved.
client_plugin = 'pnacl' if webapp_type == 'v2_pnacl' else 'native' client_plugin = 'pnacl' if webapp_type == 'v2_pnacl' else 'native'
findAndReplace(os.path.join(destination, 'plugin_settings.js'), findAndReplace(os.path.join(destination, 'plugin_settings.js'),
"'CLIENT_PLUGIN_TYPE'", "'" + client_plugin + "'") "'CLIENT_PLUGIN_TYPE'", "'" + client_plugin + "'")
...@@ -161,12 +176,80 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -161,12 +176,80 @@ def buildWebApp(buildtype, version, destination, zip_path,
'OAUTH2_API_HOST', 'https://www.googleapis.com') 'OAUTH2_API_HOST', 'https://www.googleapis.com')
directoryApiHost = os.environ.get( directoryApiHost = os.environ.get(
'DIRECTORY_API_HOST', 'https://www.googleapis.com') 'DIRECTORY_API_HOST', 'https://www.googleapis.com')
if webapp_type == 'app_remoting':
appRemotingApiHost = os.environ.get(
'APP_REMOTING_API_HOST', None)
appRemotingApplicationId = os.environ.get(
'APP_REMOTING_APPLICATION_ID', None)
# Release/Official builds are special because they are what we will upload
# to the web store. The checks below will validate that prod builds are
# being generated correctly (no overrides) and with the correct buildtype.
# They also verify that folks are not accidentally building dev/test/staging
# apps for release (no impersonation) instead of dev.
if service_environment == "prod" and buildtype == "Dev":
raise Exception("Prod environment cannot be built for 'dev' builds");
if buildtype != "Dev":
if service_environment != "prod":
raise Exception("Invalid service_environment targeted for "
+ buildtype + ": " + service_environment);
if "out/Release" not in destination:
raise Exception("Prod builds must be placed in the out/Release folder");
if app_id != None:
raise Exception("Cannot pass in an app_id for "
+ buildtype + " builds: " + service_environment);
if appRemotingApiHost != None:
raise Exception("Cannot set APP_REMOTING_API_HOST env var for "
+ buildtype + " builds");
if appRemotingApplicationId != None:
raise Exception("Cannot set APP_REMOTING_APPLICATION_ID env var for "
+ buildtype + " builds");
# If an Application ID was set (either from service_environment variable or
# from a command line argument), hardcode it, otherwise get it at runtime.
effectiveAppId = appRemotingApplicationId or app_id
if effectiveAppId:
appRemotingApplicationId = "'" + effectiveAppId + "'"
else:
appRemotingApplicationId = "chrome.i18n.getMessage('@@extension_id')"
findAndReplace(os.path.join(destination, 'plugin_settings.js'),
"'APP_REMOTING_APPLICATION_ID'", appRemotingApplicationId)
oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2' oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2'
oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2' oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2'
directoryApiBaseUrl = directoryApiHost + '/chromoting/v1' directoryApiBaseUrl = directoryApiHost + '/chromoting/v1'
if webapp_type == 'app_remoting':
# Set the apiary endpoint and then set the endpoint version
if not appRemotingApiHost:
if service_environment == "prod":
appRemotingApiHost = 'https://www.googleapis.com'
else:
appRemotingApiHost = 'https://www-googleapis-test.sandbox.google.com'
if service_environment == "dev":
appRemotingServicePath = '/appremoting/v1beta1_dev'
elif service_environment == "test":
appRemotingServicePath = '/appremoting/v1beta1'
elif service_environment == "staging":
appRemotingServicePath = '/appremoting/v1beta1_staging'
elif service_environment == "prod":
appRemotingServicePath = '/appremoting/v1beta1'
else:
raise Exception("Unknown service environment: " + service_environment);
appRemotingApiBaseUrl = appRemotingApiHost + appRemotingServicePath
else:
appRemotingApiBaseUrl = ''
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)
if webapp_type == 'app_remoting':
replaceString(destination, 'APP_REMOTING_API_BASE_URL',
appRemotingApiBaseUrl)
# Substitute hosts in the manifest's CSP list. # Substitute hosts in the manifest's CSP list.
# Ensure we list the API host only once if it's the same for multiple APIs. # Ensure we list the API host only once if it's the same for multiple APIs.
googleApiHosts = ' '.join(set([oauth2ApiHost, directoryApiHost])) googleApiHosts = ' '.join(set([oauth2ApiHost, directoryApiHost]))
...@@ -194,7 +277,7 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -194,7 +277,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
oauth2RedirectPath = '/talkgadget/oauth/chrome-remote-desktop' oauth2RedirectPath = '/talkgadget/oauth/chrome-remote-desktop'
oauth2RedirectBaseUrlJs = oauth2RedirectHostJs + oauth2RedirectPath oauth2RedirectBaseUrlJs = oauth2RedirectHostJs + oauth2RedirectPath
oauth2RedirectBaseUrlJson = oauth2RedirectHostJson + oauth2RedirectPath oauth2RedirectBaseUrlJson = oauth2RedirectHostJson + oauth2RedirectPath
if buildtype == 'Official': if buildtype != 'Dev':
oauth2RedirectUrlJs = ("'" + oauth2RedirectBaseUrlJs + oauth2RedirectUrlJs = ("'" + oauth2RedirectBaseUrlJs +
"/rel/' + chrome.i18n.getMessage('@@extension_id')") "/rel/' + chrome.i18n.getMessage('@@extension_id')")
oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/rel/*' oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/rel/*'
...@@ -230,30 +313,35 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -230,30 +313,35 @@ def buildWebApp(buildtype, version, destination, zip_path,
replaceString(destination, "API_CLIENT_ID", apiClientId) replaceString(destination, "API_CLIENT_ID", apiClientId)
replaceString(destination, "API_CLIENT_SECRET", apiClientSecret) replaceString(destination, "API_CLIENT_SECRET", apiClientSecret)
# Use a consistent extension id for unofficial builds. # Use a consistent extension id for dev builds.
if buildtype != 'Official': if buildtype == 'Dev':
manifestKey = '"key": "remotingdevbuild",' manifestKey = '"key": "remotingdevbuild",'
else: else:
manifestKey = '' manifestKey = ''
# Generate manifest. # Generate manifest.
context = { if manifest_template:
'webapp_type': webapp_type, context = {
'FULL_APP_VERSION': version, 'webapp_type': webapp_type,
'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey, 'FULL_APP_VERSION': version,
'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson, 'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey,
'TALK_GADGET_HOST': talkGadgetHostJson, 'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson,
'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson, 'TALK_GADGET_HOST': talkGadgetHostJson,
'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2, 'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson,
'OAUTH2_BASE_URL': oauth2BaseUrl, 'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2,
'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl, 'OAUTH2_BASE_URL': oauth2BaseUrl,
'DIRECTORY_API_BASE_URL': directoryApiBaseUrl, 'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl,
'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost, 'DIRECTORY_API_BASE_URL': directoryApiBaseUrl,
'GOOGLE_API_HOSTS': googleApiHosts, 'APP_REMOTING_API_BASE_URL': appRemotingApiBaseUrl,
} 'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost,
processJinjaTemplate(manifest_template, 'GOOGLE_API_HOSTS': googleApiHosts,
os.path.join(destination, 'manifest.json'), 'APP_NAME': app_name,
context) 'APP_DESCRIPTION': app_description,
}
processJinjaTemplate(manifest_template,
jinja_paths,
os.path.join(destination, 'manifest.json'),
context)
# Make the zipfile. # Make the zipfile.
createZip(zip_path, destination) createZip(zip_path, destination)
...@@ -266,22 +354,54 @@ def main(): ...@@ -266,22 +354,54 @@ def main():
print ('Usage: build-webapp.py ' print ('Usage: build-webapp.py '
'<build-type> <version> <dst> <zip-path> <manifest_template> ' '<build-type> <version> <dst> <zip-path> <manifest_template> '
'<webapp_type> <other files...> ' '<webapp_type> <other files...> '
'[--locales <locales...>]') '--app_name <name> '
'--app_description <description> '
'[--appid <appid>] '
'[--locales <locales...>] '
'[--jinja_paths <paths...>] '
'[--service_environment <service_environment>]')
return 1 return 1
arg_type = '' arg_type = ''
files = [] files = []
locales = [] locales = []
jinja_paths = []
app_id = None
app_name = None
app_description = None
service_environment = ''
for arg in sys.argv[7:]: for arg in sys.argv[7:]:
if arg in ['--locales']: if arg in ['--locales',
'--jinja_paths',
'--appid',
'--app_name',
'--app_description',
'--service_environment']:
arg_type = arg arg_type = arg
elif arg_type == '--locales': elif arg_type == '--locales':
locales.append(arg) locales.append(arg)
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 == '--service_environment':
service_environment = arg
arg_type = ''
else: else:
files.append(arg) files.append(arg)
return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4],
sys.argv[5], sys.argv[6], files, locales) sys.argv[5], sys.argv[6], app_id, app_name,
app_description, files, locales, jinja_paths,
service_environment)
if __name__ == '__main__': if __name__ == '__main__':
......
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