def main(argv): parser = optparse.OptionParser() parser.add_option('-v', '--version', action='store_true', dest='version', default=False, help='The version of this python tool.') parser.add_option('--verbose', action="store_true", dest='verbose', default=False, help='Print debug messages.') info = ( 'The packaging mode of the web application. The value \'shared\' ' 'means that the runtime is shared across multiple application ' 'instances and that the runtime needs to be distributed separately. ' 'The value \'embedded\' means that the runtime is embedded into the ' 'application itself and distributed along with it.' 'Set the default mode as \'embedded\'. For example: --mode=embedded') parser.add_option('--mode', choices=('embedded', 'shared'), default='embedded', help=info) info = ( 'The target architecture of the embedded runtime. Supported values: ' '%s. If not specified, APKs for all available architectures will be ' 'generated.' % ', '.join(AllArchitectures())) parser.add_option('--arch', choices=AllArchitectures(), help=info) group = optparse.OptionGroup( parser, 'Application Source Options', 'This packaging tool supports 3 kinds of web application source: ' '1) XPK package; 2) manifest.json; 3) various command line options, ' 'for example, \'--app-url\' for website, \'--app-root\' and ' '\'--app-local-path\' for local web application.') info = ( 'The path of the XPK package. For example, --xpk=/path/to/xpk/file') group.add_option('--xpk', help=info) info = ( 'The manifest file with the detail description of the application. ' 'For example, --manifest=/path/to/your/manifest/file') group.add_option('--manifest', help=info) info = ('The url of application. ' 'This flag allows to package website as apk. For example, ' '--app-url=http://www.intel.com') group.add_option('--app-url', help=info) info = ('The root path of the web app. ' 'This flag allows to package local web app as apk. For example, ' '--app-root=/root/path/of/the/web/app') group.add_option('--app-root', help=info) info = ( 'The relative path of entry file based on the value from ' '\'app_root\'. This flag should work with \'--app-root\' together. ' 'For example, --app-local-path=/relative/path/of/entry/file') group.add_option('--app-local-path', help=info) parser.add_option_group(group) # Mandatory options group group = optparse.OptionGroup( parser, 'Mandatory arguments', 'They are used for describing the APK information through ' 'command line options.') info = ('The apk name. For example, --name="Your Application Name"') group.add_option('--name', help=info) info = ('The package name. For example, ' '--package=com.example.YourPackage') group.add_option('--package', help=info) parser.add_option_group(group) # Optional options group (alphabetical) group = optparse.OptionGroup( parser, 'Optional arguments', 'They are used for various settings for applications through ' 'command line options.') info = ('The version name of the application. ' 'For example, --app-version=1.0.0') group.add_option('--app-version', help=info) info = ('The version code of the application. ' 'For example, --app-versionCode=24') group.add_option('--app-versionCode', type='int', help=info) info = ('The version code base of the application. Version code will ' 'be made by adding a prefix based on architecture to the version ' 'code base. For example, --app-versionCodeBase=24') group.add_option('--app-versionCodeBase', type='int', help=info) info = ('The description of the application. For example, ' '--description=YourApplicationDescription') group.add_option('--description', help=info) group.add_option('--enable-remote-debugging', action='store_true', dest='enable_remote_debugging', default=False, help='Enable remote debugging.') group.add_option('--use-animatable-view', action='store_true', dest='use_animatable_view', default=False, help='Enable using animatable view (TextureView).') info = ('The list of external extension paths splitted by OS separators. ' 'The separators are \':\' , \';\' and \':\' on Linux, Windows and ' 'Mac OS respectively. For example, ' '--extensions=/path/to/extension1:/path/to/extension2.') group.add_option('--extensions', help=info) group.add_option('-f', '--fullscreen', action='store_true', dest='fullscreen', default=False, help='Make application fullscreen.') group.add_option('--keep-screen-on', action='store_true', default=False, help='Support keeping screen on') info = ('The path of application icon. ' 'Such as: --icon=/path/to/your/customized/icon') group.add_option('--icon', help=info) info = ('The orientation of the web app\'s display on the device. ' 'For example, --orientation=landscape. The default value is ' '\'unspecified\'. The permitted values are from Android: ' 'http://developer.android.com/guide/topics/manifest/' 'activity-element.html#screen') group.add_option('--orientation', help=info) info = ( 'The list of permissions to be used by web application. For example, ' '--permissions=geolocation:webgl') group.add_option('--permissions', help=info) info = ( 'Create an Android project directory with Crosswalk at this location.' ' (See project-only option below)') group.add_option('--project-dir', help=info) info = ('Must be used with project-dir option. Create an Android project ' 'directory with Crosswalk but do not build the APK package') group.add_option('--project-only', action='store_true', default=False, dest='project_only', help=info) info = ('Packaging tool will move the output APKs to the target directory') group.add_option('--target-dir', default=os.getcwd(), help=info) info = ( 'Use command lines.' 'Crosswalk is powered by Chromium and supports Chromium command line.' 'For example, ' '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'') group.add_option('--xwalk-command-line', default='', help=info) parser.add_option_group(group) # Keystore options group group = optparse.OptionGroup( parser, 'Keystore Options', 'The keystore is a signature from web developer, it\'s used when ' 'developer wants to distribute the applications.') info = ('The path to the developer keystore. For example, ' '--keystore-path=/path/to/your/developer/keystore') group.add_option('--keystore-path', help=info) info = ('The alias name of keystore. For example, --keystore-alias=name') group.add_option('--keystore-alias', help=info) info = ('The passcode of keystore. For example, --keystore-passcode=code') group.add_option('--keystore-passcode', help=info) info = ('Passcode for alias\'s private key in the keystore, ' 'For example, --keystore-alias-passcode=alias-code') group.add_option('--keystore-alias-passcode', help=info) info = ('Minify and obfuscate javascript and css.' '--compressor: compress javascript and css.' '--compressor=js: compress javascript.' '--compressor=css: compress css.') group.add_option('--compressor', dest='compressor', action='callback', callback=ParseParameterForCompressor, type='string', nargs=0, help=info) parser.add_option_group(group) options, _ = parser.parse_args() if len(argv) == 1: parser.print_help() return 0 if options.version: if os.path.isfile('VERSION'): print(GetVersion('VERSION')) return 0 else: parser.error( 'VERSION was not found, so Crosswalk\'s version could not ' 'be determined.') xpk_temp_dir = '' if options.xpk: xpk_name = os.path.splitext(os.path.basename(options.xpk))[0] xpk_temp_dir = tempfile.mkdtemp(prefix="%s-" % xpk_name + '_xpk') CleanDir(xpk_temp_dir) ParseXPK(options, xpk_temp_dir) if options.manifest: options.manifest = os.path.abspath(options.manifest) if not os.path.isfile(options.manifest): print('Error: The manifest file does not exist.') sys.exit(8) if options.app_root and not options.manifest: manifest_path = os.path.join(options.app_root, 'manifest.json') if os.path.exists(manifest_path): print('Using manifest.json distributed with the application.') options.manifest = manifest_path app_info = AppInfo() manifest = None if not options.manifest: # The checks here are really convoluted, but at the moment make_apk # misbehaves any of the following conditions is true. if options.app_url: # 1) --app-url must be passed without either --app-local-path or # --app-root. if options.app_root or options.app_local_path: parser.error( 'You must pass either "--app-url" or "--app-local-path" ' 'with "--app-root", but not all.') else: # 2) --app-url is not passed but only one of --app-local-path and # --app-root is set. if bool(options.app_root) != bool(options.app_local_path): parser.error('You must specify both "--app-local-path" and ' '"--app-root".') # 3) None of --app-url, --app-local-path and --app-root are passed. elif not options.app_root and not options.app_local_path: parser.error( 'You must pass either "--app-url" or "--app-local-path" ' 'with "--app-root".') if options.permissions: permission_list = options.permissions.split(':') else: print( 'Warning: all supported permissions on Android port are added. ' 'Refer to https://github.com/crosswalk-project/' 'crosswalk-website/wiki/Crosswalk-manifest') permission_list = permission_mapping_table.keys() options.permissions = HandlePermissionList(permission_list) options.icon_dict = {} else: try: manifest = ParseManifest(options) except SystemExit as ec: return ec.code if not options.name: parser.error( 'An APK name is required. Please use the "--name" option.') if not options.package: parser.error('A package name is required. Please use the "--package" ' 'option.') VerifyPackageName(options.package) if (options.app_root and options.app_local_path and not os.path.isfile( os.path.join(options.app_root, options.app_local_path))): print('Please make sure that the local path file of launching app ' 'does exist.') sys.exit(7) if options.target_dir: target_dir = os.path.abspath(os.path.expanduser(options.target_dir)) options.target_dir = target_dir if not os.path.isdir(target_dir): os.makedirs(target_dir) if options.project_only and not options.project_dir: print('\nmake_apk.py error: Option --project-only must be used ' 'with --project-dir') sys.exit(8) try: MakeApk(options, app_info, manifest) except SystemExit as ec: return ec.code finally: CleanDir(GetBuildDir(app_info.android_name)) CleanDir(xpk_temp_dir) return 0
def main(argv): parser = optparse.OptionParser() parser.add_option('-v', '--version', action='store_true', dest='version', default=False, help='The version of this python tool.') info = ('The packaging mode of the web application. The value \'shared\' ' 'means that the runtime is shared across multiple application ' 'instances and that the runtime needs to be distributed separately. ' 'The value \'embedded\' means that the runtime is embedded into the ' 'application itself and distributed along with it.' 'Set the default mode as \'embedded\'. For example: --mode=embedded') parser.add_option('--mode', default='embedded', help=info) info = ('The target architecture of the embedded runtime. Supported values ' 'are \'x86\' and \'arm\'. Note, if undefined, APKs for all possible ' 'architestures will be generated.') parser.add_option('--arch', help=info) group = optparse.OptionGroup(parser, 'Application Source Options', 'This packaging tool supports 3 kinds of web application source: ' '1) XPK package; 2) manifest.json; 3) various command line options, ' 'for example, \'--app-url\' for website, \'--app-root\' and ' '\'--app-local-path\' for local web application.') info = ('The path of the XPK package. For example, --xpk=/path/to/xpk/file') group.add_option('--xpk', help=info) info = ('The manifest file with the detail description of the application. ' 'For example, --manifest=/path/to/your/manifest/file') group.add_option('--manifest', help=info) info = ('The url of application. ' 'This flag allows to package website as apk. For example, ' '--app-url=http://www.intel.com') group.add_option('--app-url', help=info) info = ('The root path of the web app. ' 'This flag allows to package local web app as apk. For example, ' '--app-root=/root/path/of/the/web/app') group.add_option('--app-root', help=info) info = ('The relative path of entry file based on the value from ' '\'app_root\'. This flag should work with \'--app-root\' together. ' 'For example, --app-local-path=/relative/path/of/entry/file') group.add_option('--app-local-path', help=info) parser.add_option_group(group) group = optparse.OptionGroup(parser, 'Mandatory arguments', 'They are used for describing the APK information through ' 'command line options.') info = ('The apk name. For example, --name="Your Application Name"') group.add_option('--name', help=info) info = ('The package name. For example, ' '--package=com.example.YourPackage') group.add_option('--package', help=info) parser.add_option_group(group) group = optparse.OptionGroup(parser, 'Optional arguments', 'They are used for various settings for applications through ' 'command line options.') info = ('The version name of the application. ' 'For example, --app-version=1.0.0') group.add_option('--app-version', help=info) info = ('The version code of the application. ' 'For example, --app-versionCode=24') group.add_option('--app-versionCode', type='int', help=info) info = ('The version code base of the application. Version code will ' 'be made by adding a prefix based on architecture to the version ' 'code base. For example, --app-versionCodeBase=24') group.add_option('--app-versionCodeBase', type='int', help=info) info = ('The description of the application. For example, ' '--description=YourApplicationDescription') group.add_option('--description', help=info) group.add_option('--enable-remote-debugging', action='store_true', dest='enable_remote_debugging', default=False, help = 'Enable remote debugging.') info = ('The list of external extension paths splitted by OS separators. ' 'The separators are \':\' , \';\' and \':\' on Linux, Windows and ' 'Mac OS respectively. For example, ' '--extensions=/path/to/extension1:/path/to/extension2.') group.add_option('--extensions', help=info) group.add_option('-f', '--fullscreen', action='store_true', dest='fullscreen', default=False, help='Make application fullscreen.') info = ('The path of application icon. ' 'Such as: --icon=/path/to/your/customized/icon') group.add_option('--icon', help=info) info = ('The orientation of the web app\'s display on the device. ' 'For example, --orientation=landscape. The default value is ' '\'unspecified\'. The permitted values are from Android: ' 'http://developer.android.com/guide/topics/manifest/' 'activity-element.html#screen') group.add_option('--orientation', help=info) info = ('The list of permissions to be used by web application. For example, ' '--permissions=geolocation:webgl') group.add_option('--permissions', help=info) parser.add_option_group(group) group = optparse.OptionGroup(parser, 'Keystore Options', 'The keystore is a signature from web developer, it\'s used when ' 'developer wants to distribute the applications.') info = ('The path to the developer keystore. For example, ' '--keystore-path=/path/to/your/developer/keystore') group.add_option('--keystore-path', help=info) info = ('The alias name of keystore. For example, --keystore-alias=name') group.add_option('--keystore-alias', help=info) info = ('The passcode of keystore. For example, --keystore-passcode=code') group.add_option('--keystore-passcode', help=info) info = ('Minify and obfuscate javascript and css.' '--compressor: compress javascript and css.' '--compressor=js: compress javascript.' '--compressor=css: compress css.') group.add_option('--compressor', dest='compressor', action='callback', callback=parse_optional_arg('all'), help=info) parser.add_option_group(group) options, _ = parser.parse_args() if len(argv) == 1: parser.print_help() return 0 # This option will not export to users. # Initialize here and will be read from manifest.json. options.launch_screen_img = '' if options.version: if os.path.isfile('VERSION'): print(GetVersion('VERSION')) return 0 else: parser.error('Can\'t get version due to the VERSION file missing!') xpk_temp_dir = '' if options.xpk: xpk_name = os.path.splitext(os.path.basename(options.xpk))[0] xpk_temp_dir = xpk_name + '_xpk' ParseXPK(options, xpk_temp_dir) if options.app_root and not options.manifest: manifest_path = os.path.join(options.app_root, 'manifest.json') if os.path.exists(manifest_path): print('Using manifest.json distributed with the application.') options.manifest = manifest_path if not options.manifest: if not options.package: parser.error('The package name is required! ' 'Please use "--package" option.') if not options.name: parser.error('The APK name is required! Please use "--name" option.') if not ((options.app_url and not options.app_root and not options.app_local_path) or ((not options.app_url) and options.app_root and options.app_local_path)): parser.error('The entry is required. If the entry is a remote url, ' 'please use "--app-url" option; If the entry is local, ' 'please use "--app-root" and ' '"--app-local-path" options together!') if options.permissions: permission_list = options.permissions.split(':') else: print ('Warning: all supported permissions on Android port are added. ' 'Refer to https://github.com/crosswalk-project/' 'crosswalk-website/wiki/Crosswalk-manifest') permission_list = permission_mapping_table.keys() options.permissions = HandlePermissionList(permission_list) else: try: ParseManifest(options) except SystemExit as ec: return ec.code options.name = ReplaceInvalidChars(options.name, 'apkname') options.package = ReplaceInvalidChars(options.package) sanitized_name = ReplaceInvalidChars(options.name, 'apkname') try: compress = compress_js_and_css.CompressJsAndCss(options.app_root) if options.compressor == 'all': compress.CompressJavaScript() compress.CompressCss() elif options.compressor == 'js': compress.CompressJavaScript() elif options.compressor == 'css': compress.CompressCss() MakeApk(options, sanitized_name) except SystemExit as ec: CleanDir(sanitized_name) CleanDir('out') if os.path.exists(xpk_temp_dir): CleanDir(xpk_temp_dir) return ec.code return 0
def main(argv): parser = optparse.OptionParser() parser.add_option('-v', '--version', action='store_true', dest='version', default=False, help='The version of this python tool.') info = ('The manifest file with the detail of the app.' 'Such as: --manifest=/path/to/your/manifest/file') parser.add_option('--manifest', help=info) info = ('The package name. Such as: ' '--package=com.example.YourPackage') parser.add_option('--package', help=info) info = ('The apk name. Such as: --name=YourApplicationName') parser.add_option('--name', help=info) info = ('The version number of the app. ' 'Such as: --app-version=TheVersionNumber') parser.add_option('--app-version', help=info) info = ('The application description. Such as:' '--description=YourApplicationDescription') parser.add_option('--description', help=info) info = ('The path of icon. Such as: --icon=/path/to/your/customized/icon') parser.add_option('--icon', help=info) info = ('The permission list. Such as: --permissions="geolocation"' 'For more permissions, such as:' '--permissions="geolocation:permission2"') parser.add_option('--permissions', help=info) info = ('The url of application. ' 'This flag allows to package website as apk. Such as: ' '--app-url=http://www.intel.com') parser.add_option('--app-url', help=info) info = ('The root path of the web app. ' 'This flag allows to package local web app as apk. Such as: ' '--app-root=/root/path/of/the/web/app') parser.add_option('--app-root', help=info) info = ('The relative path of entry file based on |app_root|. ' 'This flag should work with "--app-root" together. ' 'Such as: --app-local-path=/relative/path/of/entry/file') parser.add_option('--app-local-path', help=info) info = ('The path of the developer keystore. Such as: ' '--keystore-path=/path/to/your/developer/keystore') parser.add_option('--keystore-path', help=info) info = ('The alias name of keystore. Such as: --keystore-alias=alias_name') parser.add_option('--keystore-alias', help=info) info = ('The passcode of keystore. Such as: --keystore-passcode=code') parser.add_option('--keystore-passcode', help=info) parser.add_option('--enable-remote-debugging', action='store_true', dest='enable_remote_debugging', default=False, help='Enable remote debugging.') parser.add_option('-f', '--fullscreen', action='store_true', dest='fullscreen', default=False, help='Make application fullscreen.') info = ('The path list for external extensions separated by os separator.' 'On Linux and Mac, the separator is ":". On Windows, it is ";".' 'Such as: --extensions="/path/to/extension1:/path/to/extension2"') parser.add_option('--extensions', help=info) info = ('The packaging mode of the application. "shared" means ' 'the application shares the Xwalk with other applications; ' '"embedded" means the application owns XWalk Runtime itself. ' 'Set the default mode as "shared".' 'Such as: --mode=shared') parser.add_option('--mode', help=info) info = ('The path of the XPK file. Such as: --xpk=/path/to/xpk/file') parser.add_option('--xpk', help=info) info = ( 'The orientation of the web app\'s display on the device. ' 'Such as: --orientation=landscape. The default value is "unspecified"' 'The value options are the same as those on the Android: ' 'http://developer.android.com/guide/topics/manifest/' 'activity-element.html#screen') parser.add_option('--orientation', help=info) options, _ = parser.parse_args() if len(argv) == 1: parser.print_help() return 0 if options.version: if os.path.isfile('VERSION'): print GetVersion('VERSION') return 0 else: parser.error('Can\'t get version due to the VERSION file missing!') xpk_temp_dir = '' if options.xpk: xpk_name = os.path.splitext(os.path.basename(options.xpk))[0] xpk_temp_dir = xpk_name + '_xpk' ParseXPK(options, xpk_temp_dir) if not options.manifest: if not options.package: parser.error('The package name is required! ' 'Please use "--package" option.') if not options.name: parser.error( 'The APK name is required! Pleaes use "--name" option.') if not ((options.app_url and not options.app_root and not options.app_local_path) or ((not options.app_url) and options.app_root and options.app_local_path)): parser.error( 'The entry is required. If the entry is a remote url, ' 'please use "--app-url" option; If the entry is local, ' 'please use "--app-root" and ' '"--app-local-path" options together!') if options.permissions: permission_list = options.permissions.split(':') options.permissions = HandlePermissionList(permission_list) else: try: ParseManifest(options) except KeyError, ec: print 'The manifest file contains syntax errors.' return ec.code