コード例 #1
0
def add_osx_system_framework(build_params, framework):
    xcode_project = XcodeProject('ForgeInspector.xcodeproj/project.pbxproj')
    if framework.endswith('.framework'):
        xcode_project.add_framework("System/Library/Frameworks/" + framework,
                                    "SDKROOT")
    elif framework.endswith('.dylib'):
        xcode_project.add_framework("usr/lib/" + framework, "SDKROOT")
    else:
        raise Exception(
            "Unsupported OSX framework type for '%s', must end in .framework or .dylib."
            % framework)
    xcode_project.save()
コード例 #2
0
ファイル: build.py プロジェクト: adesmet/Up2Smth
def apply_module_to_osx_project(module_path,
                                project_path,
                                skip_framework=False,
                                inspector_config=False,
                                include_tests=False,
                                local_build_steps=None,
                                app_config=None):
    """Take the module in a specific folder and apply it to an xcode ios project in another folder"""
    if not os.path.exists(os.path.join(module_path, 'manifest.json')):
        LOG.warning("Failed to include module: %s" % module_path)
        return

    if os.path.exists(os.path.join(module_path, 'identity.json')):
        with open(os.path.join(module_path, 'identity.json')) as identity_file:
            module_name = json.load(identity_file)['name']
    else:
        with open(os.path.join(module_path, 'manifest.json')) as manifest_file:
            module_name = json.load(manifest_file)['name']

    # JS
    if os.path.exists(os.path.join(module_path, 'javascript', 'module.js')):
        with open(os.path.join(module_path, 'javascript',
                               'module.js')) as module_js:
            with open(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'all.js'), 'a') as alljs:
                alljs.write('(function () {\n')
                alljs.write(module_js.read())
                alljs.write('\n})();')

    # Tests
    if include_tests:
        if os.path.exists(os.path.join(module_path, 'tests', 'fixtures')):
            if os.path.exists(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures', module_name)):
                shutil.rmtree(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures', module_name))
            if not os.path.exists(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures')):
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures'))
            shutil.copytree(
                os.path.join(module_path, 'tests', 'fixtures'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'src',
                             'fixtures', module_name))
        if os.path.exists(os.path.join(module_path, 'tests', 'automated.js')):
            try:
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'tests', 'automated'))
            except OSError:
                pass
            shutil.copy2(
                os.path.join(module_path, 'tests', 'automated.js'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'forge',
                             'tests', 'automated', module_name + '.js'))
        if os.path.exists(os.path.join(module_path, 'tests',
                                       'interactive.js')):
            try:
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'tests', 'interactive'))
            except OSError:
                pass
            shutil.copy2(
                os.path.join(module_path, 'tests', 'interactive.js'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'forge',
                             'tests', 'interactive', module_name + '.js'))

    # Add module a if we want it
    if not skip_framework:
        module_framework = os.path.join(module_path, 'osx',
                                        '%s.framework' % module_name)
        if os.path.isdir(module_framework):
            shutil.copytree(
                module_framework,
                os.path.join(project_path, '%s.framework' % module_name))
            xcode_project = XcodeProject(
                os.path.join(project_path, 'ForgeInspector.xcodeproj',
                             'project.pbxproj'))
            xcode_project.add_framework(module_name + '.framework', "<group>")
            xcode_project.add_saved_framework(module_name + '.framework',
                                              "<group>")
            xcode_project.save()

    if inspector_config:
        # Add inspector config for module to app_config.js(on).
        if app_config is None:
            with open(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'app_config.json')) as app_config_json:
                app_config = json.load(app_config_json)
        if os.path.exists(os.path.join(module_path, 'inspector_config.json')):
            with open(os.path.join(module_path, 'inspector_config.json'),
                      "r") as inspector_config_file:
                inspector_config = json.load(inspector_config_file)
        else:
            inspector_config = {
                "modules": {
                    module_name: {
                        "version": "exampleversion"
                    }
                }
            }

        app_config = dict_merge(app_config, inspector_config)

        with open(
                os.path.join(project_path, 'ForgeInspector', 'assets',
                             'app_config.json'), 'w') as app_config_json:
            json.dump(app_config, app_config_json)
        with open(
                os.path.join(project_path, 'ForgeInspector', 'assets', 'forge',
                             'app_config.js'), 'w') as app_config_js:
            app_config_js.write(
                "window.forge = {}; window.forge.config = %s;" %
                json.dumps(app_config))

    # Validate app_config for module being added
    if os.path.exists(os.path.join(module_path, 'config_schema.json')) and \
      "config" in app_config['modules'][module_name]:
        with open(os.path.join(module_path,
                               'config_schema.json')) as schema_file:
            config_schema = json.load(schema_file)

        try:
            validictory.validate(app_config['modules'][module_name]['config'],
                                 config_schema)
        except validictory.ValidationError as e:
            raise Exception(
                "Validation failed for module '%s' with error: %s" %
                (module_name, str(e)))

    # frameworks
    module_frameworks = os.path.join(module_path, 'osx', 'frameworks')
    if os.path.isdir(module_frameworks):
        if os.path.exists(os.path.join(project_path, 'ForgeModule')):
            xcode_project = XcodeProject(
                os.path.join(project_path, 'ForgeModule',
                             'ForgeModule.xcodeproj', 'project.pbxproj'))
        xcode_inspector_project = XcodeProject(
            os.path.join(project_path, 'ForgeInspector.xcodeproj',
                         'project.pbxproj'))
        for framework in os.listdir(module_frameworks):
            if framework.endswith(".framework"):
                shutil.copytree(os.path.join(module_frameworks, framework),
                                os.path.join(project_path, framework))
                if os.path.exists(os.path.join(project_path, 'ForgeModule')):
                    xcode_project.add_framework(os.path.join('..', framework),
                                                '<group>')
                xcode_inspector_project.add_saved_framework(
                    framework, '<group>')

        if os.path.exists(os.path.join(project_path, 'ForgeModule')):
            xcode_project.save()
        xcode_inspector_project.save()

    # build steps
    module_steps_path = os.path.join(module_path, 'osx', 'build_steps.json')
    if os.path.isfile(module_steps_path):
        with open(module_steps_path, 'r') as build_steps_file:
            module_build_steps = json.load(build_steps_file)
            with cd(project_path):
                build_params = {
                    'app_config': app_config,
                    'project_path': project_path,
                    'src_path': local_build_steps
                }
                for step in module_build_steps:
                    if "do" in step:
                        for task in step["do"]:
                            task_func = getattr(build_steps, task, None)
                            if task_func is not None:
                                _call_with_params(task_func, build_params,
                                                  step["do"][task])
                            elif local_build_steps is not None:
                                task_func = getattr(build_steps_local, task,
                                                    None)
                                if task_func is not None:
                                    _call_with_params(task_func, build_params,
                                                      step["do"][task])

        if local_build_steps is None:
            if not os.path.exists(
                    os.path.join(project_path, "dist", "build_steps")):
                os.makedirs(os.path.join(project_path, "dist", "build_steps"))
            shutil.copy2(
                module_steps_path,
                os.path.join(project_path, "dist", "build_steps",
                             module_name + ".json"))
コード例 #3
0
ファイル: build.py プロジェクト: adesmet/Up2Smth
def apply_module_to_ios_project(module_path,
                                project_path,
                                app_config,
                                skip_a=False,
                                include_tests=False,
                                local_build_steps=None):
    """Take the module in a specific folder and apply it to an xcode ios project in another folder"""
    if not os.path.exists(os.path.join(module_path, 'manifest.json')):
        LOG.warning("Failed to include module: %s" % module_path)
        return

    if os.path.exists(os.path.join(module_path, 'identity.json')):
        with open(os.path.join(module_path, 'identity.json')) as identity_file:
            module_name = json.load(identity_file)['name']
    else:
        with open(os.path.join(module_path, 'manifest.json')) as manifest_file:
            module_name = json.load(manifest_file)['name']

    # JS
    if os.path.exists(os.path.join(module_path, 'javascript', 'module.js')):
        LOG.info("iOS module '%s': Appending module.js to all.js" %
                 module_name)
        with open(os.path.join(module_path, 'javascript',
                               'module.js')) as module_js:
            with open(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'all.js'), 'a') as alljs:
                alljs.write('(function () {\n')
                alljs.write(module_js.read())
                alljs.write('\n})();')

    # Tests
    if include_tests:
        LOG.info("iOS module '%s': Including test files" % module_name)
        if os.path.exists(os.path.join(module_path, 'tests', 'fixtures')):
            if os.path.exists(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures', module_name)):
                shutil.rmtree(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures', module_name))
            if not os.path.exists(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures')):
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'src', 'fixtures'))
            shutil.copytree(
                os.path.join(module_path, 'tests', 'fixtures'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'src',
                             'fixtures', module_name))
        if os.path.exists(os.path.join(module_path, 'tests', 'automated.js')):
            try:
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'tests', 'automated'))
            except OSError:
                pass
            shutil.copy2(
                os.path.join(module_path, 'tests', 'automated.js'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'forge',
                             'tests', 'automated', module_name + '.js'))
        if os.path.exists(os.path.join(module_path, 'tests',
                                       'interactive.js')):
            try:
                os.makedirs(
                    os.path.join(project_path, 'ForgeInspector', 'assets',
                                 'forge', 'tests', 'interactive'))
            except OSError:
                pass
            shutil.copy2(
                os.path.join(module_path, 'tests', 'interactive.js'),
                os.path.join(project_path, 'ForgeInspector', 'assets', 'forge',
                             'tests', 'interactive', module_name + '.js'))

    # Add module a if we want it
    if not skip_a:
        LOG.info("iOS module '%s': Including module.a" % module_name)
        module_a = os.path.join(module_path, 'ios', 'module.a')
        if os.path.isfile(module_a):
            # Copy to libs
            shutil.copy2(module_a,
                         os.path.join(project_path, module_name + '.a'))

            # Add to xcode build
            xcode_project = XcodeProject(
                os.path.join(project_path, 'ForgeInspector.xcodeproj',
                             'project.pbxproj'))
            xcode_project.add_framework(module_name + '.a', "<group>")
            xcode_project.save()

    # Validate config
    if os.path.exists(os.path.join(module_path, 'config_schema.json')) and \
      "config" in app_config['modules'][module_name]:
        with open(os.path.join(module_path,
                               'config_schema.json')) as schema_file:
            config_schema = json.load(schema_file)

        try:
            validictory.validate(app_config['modules'][module_name]['config'],
                                 config_schema)
        except validictory.ValidationError as e:
            raise Exception(
                "Validation failed for module '%s' with error: %s" %
                (module_name, str(e)))

    # bundles
    module_bundles = os.path.join(module_path, 'ios', 'bundles')
    if os.path.isdir(module_bundles):
        LOG.info("iOS module '%s': Including bundles" % module_name)
        xcode_project = XcodeProject(
            os.path.join(project_path, 'ForgeInspector.xcodeproj',
                         'project.pbxproj'))
        for bundle in os.listdir(module_bundles):
            if bundle.endswith(".bundle"):
                shutil.copytree(os.path.join(module_bundles, bundle),
                                os.path.join(project_path, bundle))
                xcode_project.add_resource(bundle)

        xcode_project.save()

    # headers
    module_headers = os.path.join(module_path, 'ios', 'headers')
    if os.path.isdir(module_headers):
        LOG.info("iOS module '%s': Including headers" % module_name)
        shutil.copytree(
            module_headers,
            os.path.join(project_path, 'ForgeModule', 'forge_headers',
                         module_name))

    # build steps
    module_steps_path = os.path.join(module_path, 'ios', 'build_steps.json')
    if os.path.isfile(module_steps_path):
        LOG.info("iOS module '%s': Applying build steps" % module_name)
        with open(module_steps_path, 'r') as build_steps_file:
            module_build_steps = json.load(build_steps_file)
            with cd(project_path):
                build_params = {
                    'app_config': app_config,
                    'project_path': os.path.join(project_path,
                                                 "ForgeInspector"),
                    'src_path': local_build_steps
                }
                for step in module_build_steps:
                    if "when" in step:
                        should_continue = False
                        for predicate in step["when"]:
                            predicate_func = getattr(build_steps_predicates,
                                                     predicate, None)
                            if predicate_func is not None:
                                if not _call_with_params(
                                        predicate_func, build_params,
                                        step["when"][predicate]):
                                    should_continue = True
                                    break
                            else:
                                should_continue = True
                                break
                        if should_continue:
                            continue
                    if "do" in step:
                        for task in step["do"]:
                            task_func = getattr(build_steps, task, None)
                            if task_func is not None:
                                _call_with_params(task_func, build_params,
                                                  step["do"][task])
                            elif local_build_steps is not None:
                                task_func = getattr(build_steps_local, task,
                                                    None)
                                if task_func is not None:
                                    _call_with_params(task_func, build_params,
                                                      step["do"][task])

        if local_build_steps is None:
            if not os.path.exists(
                    os.path.join(project_path, "dist", "build_steps")):
                os.makedirs(os.path.join(project_path, "dist", "build_steps"))
            shutil.copy2(
                module_steps_path,
                os.path.join(project_path, "dist", "build_steps",
                             module_name + ".json"))