@@ -46,14 +46,46 @@ def _find_framework_dir(outputs):
46
46
return prefix + ".framework"
47
47
return None
48
48
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
+
49
82
def _framework_packaging (ctx , action , inputs , outputs , manifest = None ):
50
83
if not inputs :
51
84
return []
52
85
if inputs == [None ]:
53
86
return []
54
87
if action in ctx .attr .skip_packaging :
55
88
return []
56
- actions_to_symlink = ["header" , "private_header" ]
57
89
action_inputs = [manifest ] + inputs if manifest else inputs
58
90
outputs = [ctx .actions .declare_file (f ) for f in outputs ]
59
91
framework_name = ctx .attr .framework_name
@@ -65,29 +97,10 @@ def _framework_packaging(ctx, action, inputs, outputs, manifest = None):
65
97
args .add_all ("--inputs" , inputs )
66
98
args .add_all ("--outputs" , outputs )
67
99
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 )
91
104
else :
92
105
ctx .actions .run (
93
106
executable = ctx .executable ._framework_packaging ,
0 commit comments