Example #1
0
def __generate_component_client(context, base_code_path, destination_code_path,
                                namespace_name, jinja, swagger):

    if not os.path.exists(destination_code_path):
        print 'Making directory {}'.format(destination_code_path)
        os.makedirs(destination_code_path)

    template_h = jinja.get_template('component-client/component_template.h')
    out_path_h = os.path.join(destination_code_path,
                              '{}ClientComponent.h'.format(namespace_name))

    template_cpp = jinja.get_template(
        'component-client/component_template.cpp')
    out_path_cpp = os.path.join(destination_code_path,
                                '{}ClientComponent.cpp'.format(namespace_name))

    jinja_json = component_gen_utils.generate_component_json(
        namespace_name, swagger)
    jinja_json["UUIDs"] = component_gen_utils.get_UUIDs(
        out_path_cpp, jinja_json)

    __write_file(template_h, jinja_json, out_path_h)
    __write_file(template_cpp, jinja_json, out_path_cpp)

    return {
        'auto': {
            'Include':
            [__make_wscript_relative_path(base_code_path, out_path_h)],
            'Source':
            [__make_wscript_relative_path(base_code_path, out_path_cpp)]
        }
    }
Example #2
0
    def test_order_of_definitions(self):
        swagger = self.__setup_swagger()
        # given two definitions where the first depends on the second
        swagger["definitions"]["objectA"] = {
            "type": "object",
            "properties": {
                "objectDep": {
                    "$ref": "#/definitions/objectB"
                }
            }
        }

        swagger["definitions"]["objectB"] = {
            "type": "object",
            "properties": {
                "data": {
                    "type": "string"
                }
            }
        }

        # the objects should be listed after their dependencies
        test_jinja_json = component_gen_utils.generate_component_json(
            "TestGroup", swagger)
        self.assertEquals(1,
                          self.__find_object_index(test_jinja_json, "objectA"))
        self.assertEquals(0,
                          self.__find_object_index(test_jinja_json, "objectB"))
Example #3
0
    def test_auto_generate_property_type(self):
        AUTO_GENERATED_PROPERTY_NAME = 'ObjectAPropertyInlineArrayProp'
        swagger = self.__setup_swagger()
        # given an object with a non-primitive property defined inline
        swagger["definitions"]["objectA"] = {
            "type": "object",
            "properties": {
                "inlineArrayProp": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }

        test_jinja_json = component_gen_utils.generate_component_json(
            "TestGroup", swagger)
        # make sure that the inline is defined first (because of objectA's dependency on it)
        self.assertEquals(
            0,
            self.__find_object_index(test_jinja_json,
                                     AUTO_GENERATED_PROPERTY_NAME))
        # make sure it is an array
        self.assertTrue(test_jinja_json["otherClasses"][0]["isArray"],
                        "inline defined array was not marked as array")
        # make sure object A is defined
        self.assertEquals(1,
                          self.__find_object_index(test_jinja_json, "objectA"))
    def test_undefinied_ref_fails(self):
        swagger = self.__setup_swagger()
        hit_error = False
        # Given a swagger with a reference to #/definitions/objectA
        try:
            test_jinja_json = component_gen_utils.generate_component_json("TestGroup", swagger)
        except ValueError as e:
            # fail on ValueError if objectA is not defined
            hit_error = True

        # fail on ValueError if objectA is not defined
        self.assertTrue(hit_error, "Error was not hit for unresolvable definition")
Example #5
0
def __generate_component_client(context, base_code_path, destination_code_path,
                                namespace_name, jinja, swagger, gem):

    if not os.path.exists(destination_code_path):
        print 'Making directory {}'.format(destination_code_path)
        os.makedirs(destination_code_path)

    template_h = jinja.get_template('component-client/component_template.h')
    out_path_h = os.path.join(destination_code_path,
                              '{}ClientComponent.h'.format(namespace_name))

    template_cpp = jinja.get_template(
        'component-client/component_template.cpp')
    out_path_cpp = os.path.join(destination_code_path,
                                '{}ClientComponent.cpp'.format(namespace_name))

    jinja_json = component_gen_utils.generate_component_json(
        namespace_name, swagger)
    jinja_json["UUIDs"] = component_gen_utils.get_UUIDs(
        out_path_cpp, jinja_json)

    jinja_json["HasStdAfx"] = component_gen_utils.has_stdafx_files(
        gem.cpp_base_directory_path)

    # Set to True to match CLOUD_GEM_WSCRIPT_FILE_CONTENT->disable_pch.
    jinja_json["DisabledPCH"] = True

    __write_file(template_h, jinja_json, out_path_h)
    __write_file(template_cpp, jinja_json, out_path_cpp)

    return {
        'auto': {
            'Include':
            [__make_wscript_relative_path(base_code_path, out_path_h)],
            'Source':
            [__make_wscript_relative_path(base_code_path, out_path_cpp)]
        }
    }
Example #6
0
def __generate_component_client(context, args, jinja, swagger):

    destination_code_path = args.component_client_path
    if destination_code_path is None:
        resource_group = context.resource_groups.get(args.resource_group, None)
        if resource_group.is_gem:
            destination_code_path = os.path.abspath(
                os.path.join(resource_group.directory_path, '..', 'Code',
                             'Include', 'AWS', 'ServiceAPI'))
        else:
            destination_code_path = os.path.join(
                resource_group.game_cpp_code_path, 'ServiceAPI')

    if not os.path.exists(destination_code_path):
        print 'Making directory {}'.format(destination_code_path)
        os.makedirs(destination_code_path)

    template = jinja.get_template('component-client/component_template.h')

    out_file_path = os.path.join(
        destination_code_path,
        '{}ClientComponent.h'.format(args.resource_group))

    jinja_json = component_gen_utils.generate_component_json(
        args.resource_group, swagger)
    jinja_json["UUIDs"] = component_gen_utils.get_UUIDs(
        out_file_path, jinja_json)

    result = template.render(json_object=jinja_json)

    print 'Writing file {}.'.format(out_file_path)
    print 'Add to the approriate .waf_files file to include in your project'
    with open(out_file_path, 'w') as file:
        file.write(result)

    lambda_code_path = context.resource_groups.get(args.resource_group,
                                                   None).lambda_code_path
    print 'lambda_code_path', lambda_code_path