Skip to content

Commit

Permalink
Generate shim in separate pass
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlocke committed Oct 2, 2024
1 parent 15cb68c commit d8d54d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
10 changes: 10 additions & 0 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
action='store_true',
help='Generate the Objective-C compatibile files.',
)
_cmdline_parser.add_argument(
'--objc-shim',
action='store_true',
help='Generate the Objective-C to Swift migration files.',
)


class SwiftBackend(SwiftBaseBackend):
Expand Down Expand Up @@ -172,6 +177,7 @@ def _generate_client(self, api):
self._write_output_in_target_folder(template.render(),
'DBX{}.swift'.format(self.args.module_name))

elif self.args.objc_shim:
self._generate_sdk_migration_shim(api)
else:
template = self._jinja_template("SwiftClient.jinja")
Expand Down Expand Up @@ -235,6 +241,8 @@ def _generate_routes(self, namespace):

self._write_output_in_target_folder(output_from_parsed_template,
'DBX{}Routes.swift'.format(ns_class))
elif self.args.objc_shim:
return
else:
template = self._jinja_template("SwiftRoutes.jinja")
template.globals = template_globals
Expand Down Expand Up @@ -273,6 +281,8 @@ def _generate_request_boxes(self, api):
file_name = 'DBX{}RequestBox.swift'.format(self.args.class_name)
self._write_output_in_target_folder(output,
file_name)
elif self.args.objc_shim:
return
else:
template = self._jinja_template("SwiftRequestBox.jinja")
template.globals = template_globals
Expand Down
24 changes: 13 additions & 11 deletions stone/backends/swift_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@
_cmdline_parser.add_argument(
'--objc',
action='store_true',
help='Generate the Objective-C compatibile files',
help='Generate the Objective-C compatibile files.',
)
_cmdline_parser.add_argument(
'-d',
'--documentation',
action='store_true',
help=('Sets whether documentation is generated.'),
)
_cmdline_parser.add_argument(
'--objc-shim',
action='store_true',
help='Generate the Objective-C to Swift migration files.',
)

class SwiftTypesBackend(SwiftBaseBackend):
"""
Expand Down Expand Up @@ -203,9 +208,7 @@ def generate(self, api):
template_globals['swift_union_arg_to_objc'] = self._swift_union_arg_to_objc
template_globals['union_swift_arg_guard'] = self._union_swift_arg_guard

shim_flag = self.args.objc

if shim_flag:
if self.args.objc_shim:
self._add_shim_template_globals(template_globals)

swift_template_file = "SwiftTypes.jinja"
Expand All @@ -232,12 +235,7 @@ def generate(self, api):
route_schema=api.route_schema)
self._write_output_in_target_folder(objc_output,
'DBX{}.swift'.format(ns_class))
else:
swift_output = swift_template.render(namespace=namespace,
route_schema=api.route_schema)
self._write_output_in_target_folder(swift_output,
'{}.swift'.format(ns_class))
if shim_flag:
elif self.args.objc_shim:
shim_output = shim_template.render(namespace=namespace,
route_schema=api.route_schema)
self._write_output_in_target_folder(shim_output,
Expand All @@ -246,7 +244,11 @@ def generate(self, api):
route_schema=api.route_schema)
self._write_output_in_target_folder(arg_shim_output,
'ShimArgTypeMappings{}.swift'.format(ns_class))

else:
swift_output = swift_template.render(namespace=namespace,
route_schema=api.route_schema)
self._write_output_in_target_folder(swift_output,
'{}.swift'.format(ns_class))
if self.args.documentation:
self._generate_jazzy_docs(api)

Expand Down

0 comments on commit d8d54d7

Please sign in to comment.