From acd641c19d687c7117b08cdd568a91a381043ebb Mon Sep 17 00:00:00 2001
From: Fred Riss <friss@apple.com>
Date: Wed, 18 Mar 2020 20:12:21 -0700
Subject: [PATCH] [lldb/testsuite] Slightly rework TestHiddenIvars.py

The test was stripping the binaries from the Python
code. Unfortunately, if running on darwin embedded in a context that
requires code signing, the stripping was invalidating the signature,
thus breaking the test.

This patch moves the stripping to the Makefile and resigns the
stripped binaries if required.
---
 lldb/test/API/lang/objc/hidden-ivars/Makefile | 20 +++++++++++++++++++
 .../lang/objc/hidden-ivars/TestHiddenIvars.py | 18 ++++-------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/lldb/test/API/lang/objc/hidden-ivars/Makefile b/lldb/test/API/lang/objc/hidden-ivars/Makefile
index 0664769456ef..283e8a118fb1 100644
--- a/lldb/test/API/lang/objc/hidden-ivars/Makefile
+++ b/lldb/test/API/lang/objc/hidden-ivars/Makefile
@@ -4,4 +4,24 @@ OBJC_SOURCES := main.m
 
 LD_EXTRAS = -framework Foundation
 
+all: a.out libInternalDefiner.dylib stripped
+
 include Makefile.rules
+
+ifeq "$(MAKE_DSYM)" "YES"
+stripped: a.out.dSYM
+endif
+
+stripped: a.out libInternalDefiner.dylib
+	mkdir stripped
+	strip -Sx a.out -o stripped/a.out
+	strip -Sx libInternalDefiner.dylib -o stripped/libInternalDefiner.dylib
+ifneq "$(CODESIGN)" ""
+	$(CODESIGN) -fs - stripped/a.out
+endif
+ifneq "$(CODESIGN)" ""
+	$(CODESIGN) -fs - stripped/libInternalDefiner.dylib
+endif
+ifeq "$(MAKE_DSYM)" "YES"
+	cp -r a.out.dSYM stripped/a.out.dSYM
+endif
diff --git a/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py b/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
index 03a325ac49c6..5930ffdc958a 100644
--- a/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
+++ b/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
@@ -80,20 +80,11 @@ class HiddenIvarsTestCase(TestBase):
     def common_setup(self, strip):
 
         if strip:
-            self.assertTrue(subprocess.call(
-                ['/usr/bin/strip', '-Sx',
-                 self.getBuildArtifact('libInternalDefiner.dylib')]) == 0,
-                            'stripping dylib succeeded')
-            self.assertTrue(subprocess.call(
-                ['/bin/rm', '-rf',
-                 self.getBuildArtifact('libInternalDefiner.dylib.dSYM')]) == 0,
-                            'remove dylib dSYM file succeeded')
-            self.assertTrue(subprocess.call(['/usr/bin/strip', '-Sx',
-                                             self.getBuildArtifact("a.out")
-                                            ]) == 0,
-                            'stripping a.out succeeded')
+            exe = self.getBuildArtifact("stripped/a.out")
+        else:
+            exe = self.getBuildArtifact("a.out")
         # Create a target by the debugger.
-        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        target = self.dbg.CreateTarget(exe)
         self.assertTrue(target, VALID_TARGET)
 
         # Create the breakpoint inside function 'main'.
@@ -110,7 +101,6 @@ class HiddenIvarsTestCase(TestBase):
             None, environment, self.get_process_working_directory())
         self.assertTrue(process, PROCESS_IS_VALID)
 
-        exe = self.getBuildArtifact("a.out")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # Break inside the foo function which takes a bar_ptr argument.