def Prepare(app_info, compressor): """Copy the Android template project to a new app project named app_info.app_name """ # create new app_dir in temp dir app_name = app_info.android_name app_dir = GetBuildDir(app_name) app_package = app_info.package app_root = app_info.app_root template_app_dir = os.path.join(xwalk_dir, TEMPLATE_DIR_NAME) # 1) copy template project to app_dir CleanDir(app_dir) if not os.path.isdir(template_app_dir): print('Error: The template directory could not be found (%s).' % template_app_dir) sys.exit(7) shutil.copytree(template_app_dir, app_dir) # 2) replace app_dir 'src' dir with template 'src' dir CleanDir(os.path.join(app_dir, 'src')) template_src_root = os.path.join(template_app_dir, 'src', 'org', 'xwalk', 'app', 'template') # 3) Create directory tree from app package (org.xyz.foo -> src/org/xyz/foo) # and copy AppTemplateActivity.java to <app_name>Activity.java template_activity_file = os.path.join(template_src_root, 'AppTemplateActivity.java') if not os.path.isfile(template_activity_file): print('Error: The template file %s was not found. ' 'Please make sure this file exists.' % template_activity_file) sys.exit(7) app_pkg_dir = os.path.join(app_dir, 'src', app_package.replace('.', os.path.sep)) if not os.path.exists(app_pkg_dir): os.makedirs(app_pkg_dir) app_activity_file = app_name + 'Activity.java' shutil.copyfile(template_activity_file, os.path.join(app_pkg_dir, app_activity_file)) # 4) Copy all HTML source from app_root to app_dir if app_root: app_assets_dir = os.path.join(app_dir, 'assets', 'www') CleanDir(app_assets_dir) shutil.copytree(app_root, app_assets_dir) if compressor: CompressSourceFiles(app_assets_dir, compressor)
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(): parser = optparse.OptionParser() info = ('The package name. Such as: ' '--package=com.example.YourPackage') parser.add_option('--package', help=info) info = ('The apk name. Such as: --name="Your Application Name"') parser.add_option('--name', help=info) info = ('The version of the app. Such as: --app-version=TheVersionNumber') parser.add_option('--app-version', help=info) info = ('The versionCode of the app. Such as: --app-versionCode=24') parser.add_option('--app-versionCode', type='int', help=info) info = ('The application description. Such as:' '--description=YourApplicationdDescription') parser.add_option('--description', 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 reletive path of entry file based on |app_root|. ' 'This flag should work with "--app-root" together. ' 'Such as: --app-local-path=/reletive/path/of/entry/file') parser.add_option('--app-local-path', help=info) parser.add_option('--enable-remote-debugging', action='store_true', dest='enable_remote_debugging', default=False, help='Enable remote debugging.') parser.add_option('--use-animatable-view', action='store_true', dest='use_animatable_view', default=False, help='Enable using animatable view (TextureView).') parser.add_option('-f', '--fullscreen', action='store_true', dest='fullscreen', default=False, help='Make application fullscreen.') parser.add_option('--keep-screen-on', action='store_true', default=False, help='Support keeping screen on') 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 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) parser.add_option('--manifest', help='The manifest path') 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\'') info = ('Create an Android project directory at this location. ') parser.add_option('--project-dir', help=info) parser.add_option('--xwalk-command-line', default='', help=info) info = ('Minify and obfuscate javascript and css.' '--compressor: compress javascript and css.' '--compressor=js: compress javascript.' '--compressor=css: compress css.') parser.add_option('--compressor', dest='compressor', action='callback', callback=ParseParameterForCompressor, type='string', nargs=0, help=info) options, _ = parser.parse_args() try: icon_dict = { 144: 'icons/icon_144.png', 72: 'icons/icon_72.png', 96: 'icons/icon_96.png', 48: 'icons/icon_48.png' } app_info = AppInfo() if options.name is not None: app_info.android_name = options.name if options.app_root is None: app_info.app_root = os.path.join(xwalk_dir, 'test_data', 'manifest') else: app_info.app_root = options.app_root if options.package is not None: app_info.package = options.package if options.orientation is not None: app_info.orientation = options.orientation if options.app_version is not None: app_info.app_version = options.app_version if options.enable_remote_debugging is not None: app_info.remote_debugging = options.enable_remote_debugging if options.fullscreen is not None: app_info.fullscreen_flag = options.fullscreen app_info.icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png') CustomizeAll(app_info, options.description, icon_dict, options.permissions, options.app_url, options.app_local_path, options.keep_screen_on, options.extensions, None, options.xwalk_command_line, options.compressor) # build project is now in /tmp/<name>. Copy to project_dir if options.project_dir: src_dir = GetBuildDir(app_info.android_name) dest_dir = os.path.join(options.project_dir, app_info.android_name) CreateAndCopyDir(src_dir, dest_dir, True) except SystemExit as ec: print('Exiting with error code: %d' % ec.code) return ec.code finally: CleanDir(GetBuildDir(app_info.android_name)) return 0
def HandleRemove(remove_name, extensions_path): extension_path = os.path.join(extensions_path, remove_name) if os.path.exists(extension_path): CleanDir(extension_path) else: print "ERROR: Don't have extension \"%s\"" % (remove_name)