Browse Source

Kludge around System Integrity Protection on Darwin.

Fixes #175.

Change-Id: I744efe1a59fcbe9274cd1988444c012783952382
Reviewed-on: https://code-review.googlesource.com/24510
Reviewed-by: Paul Wankadia <junyer@google.com>
Paul Wankadia 1 year ago
parent
commit
a14ed9db8c
2 changed files with 25 additions and 18 deletions
  1. 7 12
      Makefile
  2. 18 6
      runtests

+ 7 - 12
Makefile

@@ -246,22 +246,13 @@ testofiles: $(TESTOFILES)
 test: $(DTESTS) $(TESTS) $(STESTS) debug-test static-test shared-test
 
 debug-test: $(DTESTS)
-	@echo
-	@echo Running debug binary tests.
-	@echo
 	@./runtests $(DTESTS)
 
 static-test: $(TESTS)
-	@echo
-	@echo Running static binary tests.
-	@echo
 	@./runtests $(TESTS)
 
 shared-test: $(STESTS)
-	@echo
-	@echo Running dynamic binary tests.
-	@echo
-	@LD_LIBRARY_PATH=obj/so:$(LD_LIBRARY_PATH) ./runtests $(STESTS)
+	@./runtests -shared-library-path obj/so $(STESTS)
 
 debug-bigtest: $(DTESTS) $(DBIGTESTS)
 	@./runtests $(DTESTS) $(DBIGTESTS)
@@ -270,7 +261,7 @@ static-bigtest: $(TESTS) $(BIGTESTS)
 	@./runtests $(TESTS) $(BIGTESTS)
 
 shared-bigtest: $(STESTS) $(SBIGTESTS)
-	@LD_LIBRARY_PATH=obj/so:$(LD_LIBRARY_PATH) ./runtests $(STESTS) $(SBIGTESTS)
+	@./runtests -shared-library-path obj/so $(STESTS) $(SBIGTESTS)
 
 benchmark: obj/test/regexp_benchmark
 
@@ -314,7 +305,11 @@ shared-testinstall:
 	@mkdir -p obj
 	@cp testinstall.cc obj
 	(cd obj && $(CXX) testinstall.cc -o testinstall $(CXXFLAGS) $(LDFLAGS))
-	LD_LIBRARY_PATH=$(DESTDIR)$(libdir) obj/testinstall
+ifeq ($(shell uname),Darwin)
+	DYLD_LIBRARY_PATH="$(DESTDIR)$(libdir):$(DYLD_LIBRARY_PATH)" obj/testinstall
+else
+	LD_LIBRARY_PATH="$(DESTDIR)$(libdir):$(LD_LIBRARY_PATH)" obj/testinstall
+endif
 
 benchlog: obj/test/regexp_benchmark
 	(echo '==BENCHMARK==' `hostname` `date`; \

+ 18 - 6
runtests

@@ -1,11 +1,22 @@
 #!/usr/bin/env sh
 
+# System Integrity Protection on Darwin complicated these matters somewhat.
+# See https://github.com/google/re2/issues/175 for details.
+if [ "x$1" = "x-shared-library-path" ]; then
+	if [ "x$(uname)" = "xDarwin" ]; then
+		DYLD_LIBRARY_PATH="$2:$DYLD_LIBRARY_PATH"
+		export DYLD_LIBRARY_PATH
+	else
+		LD_LIBRARY_PATH="$2:$LD_LIBRARY_PATH"
+		export LD_LIBRARY_PATH
+	fi
+	shift 2
+fi
+
 success=true
-for i
-do
+for i; do
 	printf "%-40s" $i
-	if $($i >$i.log 2>&1) 2>/dev/null
-	then
+	if $($i >$i.log 2>&1) 2>/dev/null; then
 		echo PASS
 	else
 		echo FAIL';' output in $i.log
@@ -16,6 +27,7 @@ done
 if $success; then
 	echo 'ALL TESTS PASSED.'
 	exit 0
+else
+	echo 'TESTS FAILED.'
+	exit 1
 fi
-echo 'TESTS FAILED.'
-exit 1