Skip to content

Commit 4137cda

Browse files
committed
Also symlink modulemap
1 parent d037b67 commit 4137cda

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

rules/framework.bzl

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,46 @@ def _find_framework_dir(outputs):
4646
return prefix + ".framework"
4747
return None
4848

49+
def _framework_packaging_symlink_headers(ctx, inputs, outputs):
50+
inputs_by_basename = {input.basename: input for input in inputs}
51+
52+
# If this check is true it means that multiple inputs have the same 'basename',
53+
# an additional check is done to see if that was caused by 'action_inputs' containing
54+
# two different paths to the same file
55+
#
56+
# In that case fails with a msg listing the differences found
57+
if len(inputs_by_basename) < len(inputs):
58+
inputs_by_basename_paths = [x.path for x in inputs_by_basename.values()]
59+
inputs_with_duplicated_basename = [x for x in inputs if not x.path in inputs_by_basename_paths]
60+
if len(inputs_with_duplicated_basename) > 0:
61+
fail("""
62+
[Error] Multiple files with the same name exists.\n
63+
See below for the list of paths found for each basename:\n
64+
{}
65+
""".format({x.basename: (x.path, inputs_by_basename[x.basename].path) for x in inputs_with_duplicated_basename}))
66+
67+
# If no error occurs create symlinks for each output with
68+
# each input as 'target_file'
69+
output_input_dict = {output: inputs_by_basename[output.basename] for output in outputs}
70+
for (output, input) in output_input_dict.items():
71+
ctx.actions.symlink(output = output, target_file = input)
72+
73+
def _framework_packaging_symlink_modulemap(ctx, inputs, outputs):
74+
if len(inputs) != 1 or len(outputs) != 1:
75+
fail("""
76+
Multiple .modulemap files found, double check expected inputs and outputs:\n
77+
inputs: {}\n
78+
outputs: {}
79+
""".format([x.path for x in inputs], [x.path for x in outputs]))
80+
ctx.actions.symlink(output = outputs[0], target_file = inputs[0])
81+
4982
def _framework_packaging(ctx, action, inputs, outputs, manifest = None):
5083
if not inputs:
5184
return []
5285
if inputs == [None]:
5386
return []
5487
if action in ctx.attr.skip_packaging:
5588
return []
56-
actions_to_symlink = ["header", "private_header"]
5789
action_inputs = [manifest] + inputs if manifest else inputs
5890
outputs = [ctx.actions.declare_file(f) for f in outputs]
5991
framework_name = ctx.attr.framework_name
@@ -65,29 +97,10 @@ def _framework_packaging(ctx, action, inputs, outputs, manifest = None):
6597
args.add_all("--inputs", inputs)
6698
args.add_all("--outputs", outputs)
6799

68-
if action in actions_to_symlink:
69-
inputs_by_basename = {input.basename: input for input in action_inputs}
70-
71-
# If this check is true it means that multiple inputs have the same 'basename',
72-
# an additional check is done to see if that was caused by 'action_inputs' containing
73-
# two different paths to the same file
74-
#
75-
# In that case fails with a msg listing the differences found
76-
if len(inputs_by_basename) < len(action_inputs):
77-
inputs_by_basename_paths = [x.path for x in inputs_by_basename.values()]
78-
inputs_with_duplicated_basename = [x for x in action_inputs if not x.path in inputs_by_basename_paths]
79-
if len(inputs_with_duplicated_basename) > 0:
80-
fail("""
81-
[Error] Multiple files with the same name exists.\n
82-
See below for the list of paths found for each basename:\n
83-
{}
84-
""".format({x.basename: (x.path, inputs_by_basename[x.basename].path) for x in inputs_with_duplicated_basename}))
85-
86-
# If no error occurs create symlinks for each output with
87-
# each input as 'target_file'
88-
output_input_dict = {output: inputs_by_basename[output.basename] for output in outputs}
89-
for (output, input) in output_input_dict.items():
90-
ctx.actions.symlink(output = output, target_file = input)
100+
if action in ["header", "private_header"]:
101+
_framework_packaging_symlink_headers(ctx, inputs, outputs)
102+
elif action == "modulemap":
103+
_framework_packaging_symlink_modulemap(ctx, inputs, outputs)
91104
else:
92105
ctx.actions.run(
93106
executable = ctx.executable._framework_packaging,

rules/framework/framework_packaging.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ def _merge_binaries(framework_root, framework_name, binary_in):
4242
] + binary_in
4343
subprocess.check_call(commands)
4444

45-
46-
def _copy_modulemap(framework_root, modulemap_path):
47-
"""Copy modulemaps to its destination.
48-
49-
Args:
50-
framework_root: root folder of the framework
51-
modulemap_path: path of the original modulemap
52-
"""
53-
dest = os.path.join(framework_root, "Modules", "module.modulemap")
54-
_mkdir(os.path.dirname(dest))
55-
_cp(modulemap_path, dest)
56-
5745
def _clean(framework_root, manifest_file, output_manifest_file):
5846
"""Remove stale files from the framework root.
5947
@@ -106,8 +94,6 @@ def main():
10694
actions = {
10795
"binary":
10896
lambda args: _merge_binaries(args.framework_root, args.framework_name, args.inputs),
109-
"modulemap":
110-
lambda args: _copy_modulemap(args.framework_root, args.input()),
11197
"swiftmodule":
11298
lambda args: _cp(args.input(), args.output()),
11399
"swiftdoc":

0 commit comments

Comments
 (0)