Skip to content

Commit 2e97f80

Browse files
committed
Fix binary stripping
1 parent 2000428 commit 2e97f80

File tree

7 files changed

+316
-6
lines changed

7 files changed

+316
-6
lines changed

apple/internal/compilation_support.bzl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,7 @@ def _classify_libraries(libraries_to_link):
240240
return always_link_libraries.keys(), as_needed_libraries.keys()
241241

242242
def _emit_builtin_objc_strip_action(ctx):
243-
return (
244-
getattr(ctx.fragments.objc, "builtin_objc_strip_action", False) and
245-
ctx.fragments.objc.builtin_objc_strip_action and
246-
ctx.fragments.cpp.objc_enable_binary_stripping() and
247-
ctx.fragments.cpp.compilation_mode() == "opt"
248-
)
243+
return ctx.fragments.cpp.objc_should_strip_binary
249244

250245
def _register_configuration_specific_link_actions(
251246
name,

test/starlark_tests/ios_application_tests.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ load(
2929
load(
3030
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
3131
"analysis_target_actions_tree_artifacts_outputs_test",
32+
"make_analysis_target_actions_test",
3233
)
3334
load(
3435
"//test/starlark_tests/rules:analysis_target_outputs_test.bzl",
@@ -73,6 +74,30 @@ load(
7374
"common",
7475
)
7576

77+
_analysis_ios_strip_enabled_opt_test = make_analysis_target_actions_test(
78+
config_settings = {
79+
"//command_line_option:compilation_mode": "opt",
80+
"//command_line_option:ios_multi_cpus": "x86_64",
81+
"//command_line_option:objc_enable_binary_stripping": True,
82+
},
83+
)
84+
85+
_analysis_ios_strip_disabled_opt_test = make_analysis_target_actions_test(
86+
config_settings = {
87+
"//command_line_option:compilation_mode": "opt",
88+
"//command_line_option:ios_multi_cpus": "x86_64",
89+
"//command_line_option:objc_enable_binary_stripping": False,
90+
},
91+
)
92+
93+
_analysis_ios_strip_disabled_dbg_test = make_analysis_target_actions_test(
94+
config_settings = {
95+
"//command_line_option:compilation_mode": "dbg",
96+
"//command_line_option:ios_multi_cpus": "x86_64",
97+
"//command_line_option:objc_enable_binary_stripping": True,
98+
},
99+
)
100+
76101
def ios_application_test_suite(name):
77102
"""Test suite for ios_application.
78103
@@ -145,6 +170,32 @@ def ios_application_test_suite(name):
145170
tags = [name],
146171
)
147172

173+
# Tests that strip action is registered when building in opt mode with binary stripping enabled.
174+
_analysis_ios_strip_enabled_opt_test(
175+
name = "{}_binary_strip_action_enabled_in_opt_test".format(name),
176+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app",
177+
target_mnemonic = "ObjcBinarySymbolStrip",
178+
tags = [name],
179+
)
180+
181+
# Tests that strip action is not registered when in opt mode but stripping is disabled.
182+
_analysis_ios_strip_disabled_opt_test(
183+
name = "{}_binary_strip_action_disabled_without_flag_test".format(name),
184+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app",
185+
target_mnemonic = "ObjcLink",
186+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
187+
tags = [name],
188+
)
189+
190+
# Tests that strip action is not registered in dbg mode even if stripping is enabled.
191+
_analysis_ios_strip_disabled_dbg_test(
192+
name = "{}_binary_strip_action_disabled_in_dbg_test".format(name),
193+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app",
194+
target_mnemonic = "ObjcLink",
195+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
196+
tags = [name],
197+
)
198+
148199
# Tests that an app with a mixed target framework compiles
149200
analysis_target_outputs_test(
150201
name = "{}_mixed_target_framework_test".format(name),

test/starlark_tests/macos_application_tests.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ load(
2929
load(
3030
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
3131
"analysis_target_actions_test",
32+
"make_analysis_target_actions_test",
3233
)
3334
load(
3435
"//test/starlark_tests/rules:apple_dsym_bundle_info_test.bzl",
@@ -52,6 +53,30 @@ load(
5253
"common",
5354
)
5455

56+
_analysis_macos_strip_enabled_opt_test = make_analysis_target_actions_test(
57+
config_settings = {
58+
"//command_line_option:compilation_mode": "opt",
59+
"//command_line_option:macos_cpus": "x86_64",
60+
"//command_line_option:objc_enable_binary_stripping": True,
61+
},
62+
)
63+
64+
_analysis_macos_strip_disabled_opt_test = make_analysis_target_actions_test(
65+
config_settings = {
66+
"//command_line_option:compilation_mode": "opt",
67+
"//command_line_option:macos_cpus": "x86_64",
68+
"//command_line_option:objc_enable_binary_stripping": False,
69+
},
70+
)
71+
72+
_analysis_macos_strip_disabled_dbg_test = make_analysis_target_actions_test(
73+
config_settings = {
74+
"//command_line_option:compilation_mode": "dbg",
75+
"//command_line_option:macos_cpus": "x86_64",
76+
"//command_line_option:objc_enable_binary_stripping": True,
77+
},
78+
)
79+
5580
def macos_application_test_suite(name):
5681
"""Test suite for macos_application.
5782
@@ -82,6 +107,32 @@ def macos_application_test_suite(name):
82107
tags = [name],
83108
)
84109

110+
# Tests that strip action is registered when building in opt mode with binary stripping enabled.
111+
_analysis_macos_strip_enabled_opt_test(
112+
name = "{}_binary_strip_action_enabled_in_opt_test".format(name),
113+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
114+
target_mnemonic = "ObjcBinarySymbolStrip",
115+
tags = [name],
116+
)
117+
118+
# Tests that strip action is not registered when in opt mode but stripping is disabled.
119+
_analysis_macos_strip_disabled_opt_test(
120+
name = "{}_binary_strip_action_disabled_without_flag_test".format(name),
121+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
122+
target_mnemonic = "ObjcLink",
123+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
124+
tags = [name],
125+
)
126+
127+
# Tests that strip action is not registered in dbg mode even if stripping is enabled.
128+
_analysis_macos_strip_disabled_dbg_test(
129+
name = "{}_binary_strip_action_disabled_in_dbg_test".format(name),
130+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
131+
target_mnemonic = "ObjcLink",
132+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
133+
tags = [name],
134+
)
135+
85136
apple_verification_test(
86137
name = "{}_imported_versioned_fmwk_codesign_test".format(name),
87138
build_type = "device",

test/starlark_tests/macos_command_line_application_tests.bzl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ load(
2222
"//test/starlark_tests/rules:analysis_runfiles_test.bzl",
2323
"analysis_runfiles_dsym_test",
2424
)
25+
load(
26+
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
27+
"make_analysis_target_actions_test",
28+
)
2529
load(
2630
"//test/starlark_tests/rules:apple_dsym_bundle_info_test.bzl",
2731
"apple_dsym_bundle_info_test",
@@ -43,6 +47,30 @@ load(
4347
"common",
4448
)
4549

50+
_analysis_macos_strip_enabled_opt_test = make_analysis_target_actions_test(
51+
config_settings = {
52+
"//command_line_option:compilation_mode": "opt",
53+
"//command_line_option:macos_cpus": "x86_64",
54+
"//command_line_option:objc_enable_binary_stripping": True,
55+
},
56+
)
57+
58+
_analysis_macos_strip_disabled_opt_test = make_analysis_target_actions_test(
59+
config_settings = {
60+
"//command_line_option:compilation_mode": "opt",
61+
"//command_line_option:macos_cpus": "x86_64",
62+
"//command_line_option:objc_enable_binary_stripping": False,
63+
},
64+
)
65+
66+
_analysis_macos_strip_disabled_dbg_test = make_analysis_target_actions_test(
67+
config_settings = {
68+
"//command_line_option:compilation_mode": "dbg",
69+
"//command_line_option:macos_cpus": "x86_64",
70+
"//command_line_option:objc_enable_binary_stripping": True,
71+
},
72+
)
73+
4674
def macos_command_line_application_test_suite(name):
4775
"""Test suite for macos_command_line_application.
4876
@@ -65,6 +93,32 @@ def macos_command_line_application_test_suite(name):
6593
tags = [name],
6694
)
6795

96+
# Tests that strip action is registered when building in opt mode with binary stripping enabled.
97+
_analysis_macos_strip_enabled_opt_test(
98+
name = "{}_binary_strip_action_enabled_in_opt_test".format(name),
99+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
100+
target_mnemonic = "ObjcBinarySymbolStrip",
101+
tags = [name],
102+
)
103+
104+
# Tests that strip action is not registered when in opt mode but stripping is disabled.
105+
_analysis_macos_strip_disabled_opt_test(
106+
name = "{}_binary_strip_action_disabled_without_flag_test".format(name),
107+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
108+
target_mnemonic = "ObjcLink",
109+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
110+
tags = [name],
111+
)
112+
113+
# Tests that strip action is not registered in dbg mode even if stripping is enabled.
114+
_analysis_macos_strip_disabled_dbg_test(
115+
name = "{}_binary_strip_action_disabled_in_dbg_test".format(name),
116+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
117+
target_mnemonic = "ObjcLink",
118+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
119+
tags = [name],
120+
)
121+
68122
binary_contents_test(
69123
name = "{}_merged_info_plist_binary_contents_test".format(name),
70124
build_type = "device",

test/starlark_tests/tvos_application_tests.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ load(
2525
load(
2626
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
2727
"analysis_target_actions_test",
28+
"make_analysis_target_actions_test",
2829
)
2930
load(
3031
"//test/starlark_tests/rules:apple_dsym_bundle_info_test.bzl",
@@ -51,6 +52,30 @@ load(
5152
"common",
5253
)
5354

55+
_analysis_tvos_strip_enabled_opt_test = make_analysis_target_actions_test(
56+
config_settings = {
57+
"//command_line_option:compilation_mode": "opt",
58+
"//command_line_option:tvos_cpus": "x86_64",
59+
"//command_line_option:objc_enable_binary_stripping": True,
60+
},
61+
)
62+
63+
_analysis_tvos_strip_disabled_opt_test = make_analysis_target_actions_test(
64+
config_settings = {
65+
"//command_line_option:compilation_mode": "opt",
66+
"//command_line_option:tvos_cpus": "x86_64",
67+
"//command_line_option:objc_enable_binary_stripping": False,
68+
},
69+
)
70+
71+
_analysis_tvos_strip_disabled_dbg_test = make_analysis_target_actions_test(
72+
config_settings = {
73+
"//command_line_option:compilation_mode": "dbg",
74+
"//command_line_option:tvos_cpus": "x86_64",
75+
"//command_line_option:objc_enable_binary_stripping": True,
76+
},
77+
)
78+
5479
def tvos_application_test_suite(name):
5580
"""Test suite for tvos_application.
5681
@@ -130,6 +155,32 @@ def tvos_application_test_suite(name):
130155
tags = [name],
131156
)
132157

158+
# Tests that strip action is registered when building in opt mode with binary stripping enabled.
159+
_analysis_tvos_strip_enabled_opt_test(
160+
name = "{}_binary_strip_action_enabled_in_opt_test".format(name),
161+
target_under_test = "//test/starlark_tests/targets_under_test/tvos:app",
162+
target_mnemonic = "ObjcBinarySymbolStrip",
163+
tags = [name],
164+
)
165+
166+
# Tests that strip action is not registered when in opt mode but stripping is disabled.
167+
_analysis_tvos_strip_disabled_opt_test(
168+
name = "{}_binary_strip_action_disabled_without_flag_test".format(name),
169+
target_under_test = "//test/starlark_tests/targets_under_test/tvos:app",
170+
target_mnemonic = "ObjcLink",
171+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
172+
tags = [name],
173+
)
174+
175+
# Tests that strip action is not registered in dbg mode even if stripping is enabled.
176+
_analysis_tvos_strip_disabled_dbg_test(
177+
name = "{}_binary_strip_action_disabled_in_dbg_test".format(name),
178+
target_under_test = "//test/starlark_tests/targets_under_test/tvos:app",
179+
target_mnemonic = "ObjcLink",
180+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
181+
tags = [name],
182+
)
183+
133184
archive_contents_test(
134185
name = "{}_resources_simulator_test".format(name),
135186
build_type = "simulator",

test/starlark_tests/visionos_application_tests.bzl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ load(
2121
load(
2222
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
2323
"analysis_target_actions_test",
24+
"make_analysis_target_actions_test",
2425
)
2526
load(
2627
"//test/starlark_tests/rules:analysis_target_outputs_test.bzl",
@@ -53,6 +54,30 @@ load(
5354

5455
visibility("private")
5556

57+
_analysis_visionos_strip_enabled_opt_test = make_analysis_target_actions_test(
58+
config_settings = {
59+
"//command_line_option:compilation_mode": "opt",
60+
"//command_line_option:visionos_cpus": "sim_arm64",
61+
"//command_line_option:objc_enable_binary_stripping": True,
62+
},
63+
)
64+
65+
_analysis_visionos_strip_disabled_opt_test = make_analysis_target_actions_test(
66+
config_settings = {
67+
"//command_line_option:compilation_mode": "opt",
68+
"//command_line_option:visionos_cpus": "sim_arm64",
69+
"//command_line_option:objc_enable_binary_stripping": False,
70+
},
71+
)
72+
73+
_analysis_visionos_strip_disabled_dbg_test = make_analysis_target_actions_test(
74+
config_settings = {
75+
"//command_line_option:compilation_mode": "dbg",
76+
"//command_line_option:visionos_cpus": "sim_arm64",
77+
"//command_line_option:objc_enable_binary_stripping": True,
78+
},
79+
)
80+
5681
def visionos_application_test_suite(name):
5782
"""Test suite for visionos_application.
5883
@@ -98,6 +123,38 @@ def visionos_application_test_suite(name):
98123
],
99124
)
100125

126+
# Tests that strip action is registered when building in opt mode with binary stripping enabled.
127+
_analysis_visionos_strip_enabled_opt_test(
128+
name = "{}_binary_strip_action_enabled_in_opt_test".format(name),
129+
target_under_test = "//test/starlark_tests/targets_under_test/visionos:app",
130+
target_mnemonic = "ObjcBinarySymbolStrip",
131+
tags = [
132+
name,
133+
],
134+
)
135+
136+
# Tests that strip action is not registered when in opt mode but stripping is disabled.
137+
_analysis_visionos_strip_disabled_opt_test(
138+
name = "{}_binary_strip_action_disabled_without_flag_test".format(name),
139+
target_under_test = "//test/starlark_tests/targets_under_test/visionos:app",
140+
target_mnemonic = "ObjcLink",
141+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
142+
tags = [
143+
name,
144+
],
145+
)
146+
147+
# Tests that strip action is not registered in dbg mode even if stripping is enabled.
148+
_analysis_visionos_strip_disabled_dbg_test(
149+
name = "{}_binary_strip_action_disabled_in_dbg_test".format(name),
150+
target_under_test = "//test/starlark_tests/targets_under_test/visionos:app",
151+
target_mnemonic = "ObjcLink",
152+
not_expected_mnemonic = ["ObjcBinarySymbolStrip"],
153+
tags = [
154+
name,
155+
],
156+
)
157+
101158
archive_contents_test(
102159
name = "{}_binary_contents_arm_simulator_platform_test".format(name),
103160
build_type = "simulator",

0 commit comments

Comments
 (0)