Exemple #1
0
def command_apps(options):
    app_dirs = [ 'samples',
                 'apps/inputapp',
                 'apps/multiworm',
                 'apps/sampleapp',
                 'apps/templateapp',
                 'apps/viewer',
                 'apps/tictactoe',
                 'apps/protolibsampleapp' ]
    app_dirs = [ os.path.join(TURBULENZROOT, p) for p in app_dirs ]
    all_apps = {}
    for d in app_dirs:
        all_apps[os.path.split(d)[1]] = d

    parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is"
                                                 " given, builds or cleans all the listed apps (except samples).")
    parser.add_argument('--clean', action='store_true', help="Clean specified apps (same as apps-clean)")
    parser.add_argument('--refcheck', action='store_true', help="Build with reference checking")
    parser.add_argument('--verbose', action='store_true', help="Display verbose build output")
    parser.add_argument('--compactor', default='uglifyjs', help="Select a compactor for the code build",
                        choices=['uglifyjs', 'yui', 'closure', 'none'])
    parser.add_argument('--mode', action='append', help="Add build mode (default canvas & canvas-debug)",
                        choices=['all', 'plugin', 'plugin-debug', 'canvas', 'canvas-debug'])
    parser.add_argument('--assets-path', action='append', help="Specify additional asset root paths")
    parser.add_argument('app', default='all_apps', nargs='?', help="Select an individual app to build")
    parser.add_argument('--options', nargs='*', help="Additional options to pass to the build process")

    args = parser.parse_args(options)

    if args.app == 'all_apps':
        # If no app given, build all apps except samples
        apps = [ app for app in all_apps.keys() if app != 'samples' ]
    else:
        if args.app not in all_apps and not os.path.exists(args.app):
            print "ERROR: app name not recognised: %s" % args.app
        apps = [ args.app ]

    if not args.mode:
        modes = ['canvas-debug', 'canvas']
    elif 'all' in args.mode:
        modes = ['all']
    else:
        modes = args.mode

    options = ' '.join(args.options) if args.options else ''

    start_time = time.time()

    # Build / clean each app
    for app in apps:
        try:
            app_dir = all_apps[app]
        except KeyError:
            app_dir = app
        print "APP: %s, DIR: %s, BUILDOPTIONS: %s" \
            % (app, app_dir, options)

        if args.clean:
            for mode in modes:
                cmd = _get_make_command() + " -C " + app_dir + " clean"
                cmd += " MODE=%s" % mode
                #cmd += " BUILDVERBOSE=%d" % args.verbose
                cmd += " CMDVERBOSE=%d" % args.verbose
                cmd += " --no-print-directory"
                if 0 != call(cmd, shell=True):
                    return 1

            rmdir('%s/_build' % app_dir)
            rmdir('%s/staticmax' % app_dir)
            rm('%s/mapping_table.json' % app_dir)

        elif args.refcheck:
            make_cmd = "%s -C %s jslib TS_REFCHECK=1 -j %s" \
                % (_get_make_command(), app_dir, _get_num_cpus() + 1)
            print "BUILD CMD IS: %s" % make_cmd
            if 0 != call(make_cmd, shell=True):
                return 1

        else:
            if 0 != command_jslib([]):
                return 1

            buildassets_cmd = ['python', os.path.join(TURBULENZROOT, 'scripts', 'buildassets.py')]
            buildassets_cmd.extend(['--root', TURBULENZROOT])

            # Add asset paths, start with user supplied paths, then app specific, then default assets
            # Build assets searches the paths in order in the case of duplicate source names
            if args.assets_path:
                for p in args.assets_path:
                    buildassets_cmd.extend(['--assets-path', p])
            app_assets = os.path.abspath(os.path.join(app_dir, 'assets'))
            if os.path.isdir(app_assets):
                buildassets_cmd.extend(['--assets-path', app_assets])
            buildassets_cmd.extend(['--assets-path', os.path.join(TURBULENZROOT, 'assets') ])

            if args.verbose:
                buildassets_cmd.append('--verbose')

            try:
                sh(buildassets_cmd, cwd=app_dir, console=True)
            except CalledProcessError as e:
                return e.retcode

            for mode in modes:
                cmd = _get_make_command() + " -C " + app_dir + " build"
                cmd += " -j %d" % (_get_num_cpus() + 1)
                cmd += " MODE=%s" % mode
                cmd += " COMPACTOR=" + args.compactor
                #cmd += " BUILDVERBOSE=%d" % args.verbose
                cmd += " CMDVERBOSE=%d" % args.verbose
                cmd += " --no-print-directory"
                if 0 != call(cmd, shell=True):
                    return 1

    print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)
Exemple #2
0
def command_apps(options):
    app_dirs = ['samples',
                'apps/inputapp',
                'apps/multiworm',
                'apps/sampleapp',
                'apps/templateapp',
                'apps/viewer',
                'apps/tictactoe',
                'apps/protolibsampleapp']
    app_dirs = [os.path.join(TURBULENZROOT, p) for p in app_dirs]
    all_apps = {}
    for d in app_dirs:
        all_apps[os.path.split(d)[1]] = d

    parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is"
                                     " given, builds or cleans all the listed apps (except samples).")
    parser.add_argument('--clean', action='store_true', help="Clean specified apps (same as apps-clean)")
    parser.add_argument('--refcheck', action='store_true', help="Build with reference checking")
    parser.add_argument('--verbose', action='store_true', help="Display verbose build output")
    parser.add_argument('--compactor', default='uglifyjs', help="Select a compactor for the code build",
                        choices=['uglifyjs', 'yui', 'closure', 'none'])
    parser.add_argument('--mode', action='append', help="Add build mode (default canvas & canvas-debug)",
                        choices=['all', 'plugin', 'plugin-debug', 'canvas', 'canvas-debug'])
    parser.add_argument('--assets-path', action='append', help="Specify additional asset root paths")
    parser.add_argument('app', default='all_apps', nargs='?', help="Select an individual app to build")
    parser.add_argument('--d3d11', action='store_true', help="Build shaders for d3d11")
    parser.add_argument('--d3d9', action='store_true', help="Build shaders for d3d11")
    parser.add_argument('--cgfx-flag', action='append',
                        help="flag for cgfx2json")
    parser.add_argument('--options', nargs='*', help="Additional options to pass to the build process")

    args = parser.parse_args(options)

    if args.app == 'all_apps':
        # If no app given, build all apps except samples
        apps = [app for app in all_apps.keys() if app != 'samples']
    else:
        if args.app not in all_apps and not os.path.exists(args.app):
            print "ERROR: app name not recognised: %s" % args.app
        apps = [args.app]

    if not args.mode:
        modes = ['canvas-debug', 'canvas']
    elif 'all' in args.mode:
        modes = ['all']
    else:
        modes = args.mode

    if 'plugin-debug' in modes:
        warning('**DEPRECATED** plugin-debug has been deprecated as a build mode. '
                'Please use canvas-debug for debugging. Removing from list of modes.')
        modes = [m for m in modes if m != 'plugin-debug']
        if not modes:
            error("No remaining modes to build.")
            return

    options = ' '.join(args.options) if args.options else ''

    asset_options = []
    if args.cgfx_flag:
        asset_options.extend([ '--cgfx-flag=%s' % c for c in args.cgfx_flag ])

    if args.d3d11:
        d3d11_flags = _d3d11_cgfx2json_flags()
        asset_options.extend([ "--cgfx-flag=%s" % f for f in d3d11_flags ])
    if args.d3d9:
        d3d9_flags = _d3d9_cgfx2json_flags()
        asset_options.extend([ "--cgfx-flag=%s" % f for f in d3d9_flags ])

    start_time = time.time()

    # Build / clean each app

    for app in apps:
        try:
            app_dir = all_apps[app]
        except KeyError:
            app_dir = app
        print "APP: %s, DIR: %s, BUILDOPTIONS: %s" \
            % (app, app_dir, options)

        if args.clean:
            for mode in modes:
                cmd = _get_make_command() + " -C " + app_dir + " clean"
                cmd += " MODE=%s" % mode
                #cmd += " BUILDVERBOSE=%d" % args.verbose
                cmd += " CMDVERBOSE=%d" % args.verbose
                cmd += " --no-print-directory"
                if 0 != call(cmd, shell=True):
                    return 1

            rmdir('%s/_build' % app_dir, False)
            rmdir('%s/staticmax' % app_dir, False)
            rm('%s/mapping_table.json' % app_dir, False)

        elif args.refcheck:
            make_cmd = "%s -C %s jslib TS_REFCHECK=1 -j %s" \
                % (_get_make_command(), app_dir, _get_num_cpus() + 1)
            print "BUILD CMD IS: %s" % make_cmd
            if 0 != call(make_cmd, shell=True):
                return 1

        else:
            if 0 != command_jslib([]):
                return 1

            buildassets_cmd = ['python', os.path.join(TURBULENZROOT, 'scripts', 'buildassets.py')]
            buildassets_cmd.extend(['--root', TURBULENZROOT])
            buildassets_cmd.extend(asset_options)

            # Add asset paths, start with user supplied paths, then app specific, then default assets
            # Build assets searches the paths in order in the case of duplicate source names
            if args.assets_path:
                for p in args.assets_path:
                    buildassets_cmd.extend(['--assets-path', p])
            app_assets = os.path.abspath(os.path.join(app_dir, 'assets'))
            if os.path.isdir(app_assets):
                buildassets_cmd.extend(['--assets-path', app_assets])
            buildassets_cmd.extend(['--assets-path', os.path.join(TURBULENZROOT, 'assets')])

            if args.verbose:
                buildassets_cmd.append('--verbose')

            try:
                sh(buildassets_cmd, cwd=app_dir, console=True)
            except CalledProcessError as e:
                return e.retcode

            for mode in modes:
                cmd = _get_make_command() + " -C " + app_dir + " build"
                cmd += " -j %d" % (_get_num_cpus() + 1)
                cmd += " MODE=%s" % mode
                cmd += " COMPACTOR=" + args.compactor
                #cmd += " BUILDVERBOSE=%d" % args.verbose
                cmd += " CMDVERBOSE=%d" % args.verbose
                cmd += " --no-print-directory"
                if 0 != call(cmd, shell=True):
                    return 1

    print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)