Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea0c382

Browse files
committed
- Get _environ through the NSEnviron call in a MacOSX framework. This allows
us to completely decouple the framework from the executable, so we can use a two-level namespace. - Do framework builds with a twolevel namespace. - Reorganized the code that creates the minimal framework in the build directory, to make it more robust against incomplete frameworks (from earlier aborted builds, or builds of previous Python versions).
1 parent be3e1f7 commit ea0c382

4 files changed

Lines changed: 39 additions & 53 deletions

File tree

Makefile.pre.in

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,30 @@ libpython$(VERSION).so: $(LIBRARY_OBJS)
346346
libpython$(VERSION).sl: $(LIBRARY_OBJS)
347347
$(LDSHARED) -o $@ $(LIBRARY_OBJS) $(LIBC) $(LIBM)
348348

349-
# This rule is here for OPENSTEP/Rhapsody/MacOSX
350-
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): $(LIBRARY) $(PYTHONFRAMEWORKDIR)
349+
# This rule is here for OPENSTEP/Rhapsody/MacOSX. It builds a temporary
350+
# minimal framework (not including the Lib directory and such) in the current
351+
# directory.
352+
RESSRCDIR=$(srcdir)/Mac/OSXResources/framework
353+
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
354+
$(LIBRARY) \
355+
$(RESSRCDIR)/Info.plist \
356+
$(RESSRCDIR)/version.plist \
357+
$(RESSRCDIR)/English.lproj/InfoPlist.strings
351358
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)
352359
libtool -o $(LDLIBRARY) -dynamic $(OTHER_LIBTOOL_OPT) $(LIBRARY) \
353360
-framework System @LIBTOOL_CRUFT@
361+
$(INSTALL) -d -m $(DIRMODE) \
362+
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj
363+
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist \
364+
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/Info.plist
365+
$(INSTALL_DATA) $(RESSRCDIR)/version.plist \
366+
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/version.plist
367+
$(INSTALL_DATA) $(RESSRCDIR)/English.lproj/InfoPlist.strings \
368+
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj/InfoPlist.strings
369+
$(LN) -fsh $(VERSION) $(PYTHONFRAMEWORKDIR)/Versions/Current
370+
$(LN) -fsh Versions/Current/Python $(PYTHONFRAMEWORKDIR)/Python
371+
$(LN) -fsh Versions/Current/Headers $(PYTHONFRAMEWORKDIR)/Headers
372+
$(LN) -fsh Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
354373

355374
# This rule builds the Cygwin Python DLL
356375
libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
@@ -743,32 +762,6 @@ sharedinstall:
743762
--install-scripts=$(BINDIR) \
744763
--install-platlib=$(DESTSHARED)
745764

746-
# Install a MacOSX framework During build (before
747-
# setup.py), make a minimal Python.framework directory structure in the build
748-
# directory. This framework is minimal, it doesn't contain the Lib directory
749-
# and such, but together with some magic in Modules/getpath.c it is good enough
750-
# to run python from the install dir.
751-
752-
FRAMEWORKDEST=$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)
753-
RESSRCDIR=$(srcdir)/Mac/OSXResources/framework
754-
$(PYTHONFRAMEWORKDIR): $(RESSRCDIR)/Info.plist \
755-
$(RESSRCDIR)/version.plist \
756-
$(RESSRCDIR)/English.lproj/InfoPlist.strings
757-
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
758-
echo Not configured with --enable-framework; \
759-
exit 1; \
760-
else true; \
761-
fi
762-
$(INSTALL) -d -m $(DIRMODE) $(FRAMEWORKDEST)/Resources/English.lproj
763-
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(FRAMEWORKDEST)/Resources/Info.plist
764-
$(INSTALL_DATA) $(RESSRCDIR)/version.plist $(FRAMEWORKDEST)/Resources/version.plist
765-
$(INSTALL_DATA) $(RESSRCDIR)/English.lproj/InfoPlist.strings \
766-
$(FRAMEWORKDEST)/Resources/English.lproj/InfoPlist.strings
767-
$(LN) -fsh $(VERSION) $(PYTHONFRAMEWORKDIR)/Versions/Current
768-
$(LN) -fsh Versions/Current/Python $(PYTHONFRAMEWORKDIR)/Python
769-
$(LN) -fsh Versions/Current/Headers $(PYTHONFRAMEWORKDIR)/Headers
770-
$(LN) -fsh Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
771-
772765
# On install, we re-make the framework
773766
# structure in the install location, /Library/Frameworks/ or the argument to
774767
# --enable-framework. If --enable-framework has been specified then we have

Modules/posixmodule.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,13 @@ extern int lstat(const char *, struct stat *);
276276
#endif
277277

278278
/* Return a dictionary corresponding to the POSIX environment table */
279-
280-
#if !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
279+
#ifdef WITH_NEXT_FRAMEWORK
280+
/* On Darwin/MacOSX a shared library or framework has no access to
281+
** environ directly, we must obtain it with _NSGetEnviron().
282+
*/
283+
#include <crt_externs.h>
284+
static char **environ;
285+
#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
281286
extern char **environ;
282287
#endif /* !_MSC_VER */
283288

@@ -289,6 +294,10 @@ convertenviron(void)
289294
d = PyDict_New();
290295
if (d == NULL)
291296
return NULL;
297+
#ifdef WITH_NEXT_FRAMEWORK
298+
if (environ == NULL)
299+
environ = *_NSGetEnviron();
300+
#endif
292301
if (environ == NULL)
293302
return d;
294303
/* This part ignores errors */

configure

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.337 .
2+
# From configure.in Revision: 1.338 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53.
55
#
@@ -8759,14 +8759,12 @@ echo "${ECHO_T}$enable_toolbox_glue" >&6
87598759
87608760
case $ac_sys_system/$ac_sys_release in
87618761
Darwin/1.3*)
8762-
ns_undef_sym='_environ'
8763-
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc -U $ns_undef_sym"
8762+
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc"
87648763
LIBTOOL_CRUFT="$LIBTOOL_CRUFT $extra_frameworks"
87658764
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Python'
87668765
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
87678766
Darwin/*)
8768-
ns_undef_sym='_environ'
8769-
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc -flat_namespace -U $ns_undef_sym"
8767+
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc"
87708768
LIBTOOL_CRUFT="$LIBTOOL_CRUFT $extra_frameworks"
87718769
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Python'
87728770
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
@@ -8777,15 +8775,9 @@ echo $ECHO_N "checking for --enable-framework... $ECHO_C" >&6
87778775
if test "$enable_framework"
87788776
then
87798777
OPT="$OPT -fno-common -dynamic"
8780-
# -U __environ is needed since bundles don't have access
8781-
# to crt0 when built but will always be linked against it
87828778
# -F. is needed to allow linking to the framework while
87838779
# in the build location.
8784-
8785-
case $ac_sys_system/$ac_sys_release in
8786-
Darwin/1.3*)LDFLAGS="$LDFLAGS -Wl,-F. -Wl,-U,$ns_undef_sym";;
8787-
Darwin/*)LDFLAGS="$LDFLAGS -Wl,-F. -Wl,-flat_namespace,-U,$ns_undef_sym";;
8788-
esac
8780+
LDFLAGS="$LDFLAGS -Wl,-F."
87898781
87908782
cat >>confdefs.h <<\_ACEOF
87918783
#define WITH_NEXT_FRAMEWORK 1

configure.in

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,14 +820,12 @@ AC_MSG_RESULT($enable_toolbox_glue)
820820
AC_SUBST(LIBTOOL_CRUFT)
821821
case $ac_sys_system/$ac_sys_release in
822822
Darwin/1.3*)
823-
ns_undef_sym='_environ'
824-
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc -U $ns_undef_sym"
823+
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc"
825824
LIBTOOL_CRUFT="$LIBTOOL_CRUFT $extra_frameworks"
826825
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Python'
827826
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
828827
Darwin/*)
829-
ns_undef_sym='_environ'
830-
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc -flat_namespace -U $ns_undef_sym"
828+
LIBTOOL_CRUFT="-lcc_dynamic -arch_only ppc"
831829
LIBTOOL_CRUFT="$LIBTOOL_CRUFT $extra_frameworks"
832830
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Python'
833831
LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
@@ -837,15 +835,9 @@ AC_MSG_CHECKING(for --enable-framework)
837835
if test "$enable_framework"
838836
then
839837
OPT="$OPT -fno-common -dynamic"
840-
# -U __environ is needed since bundles don't have access
841-
# to crt0 when built but will always be linked against it
842838
# -F. is needed to allow linking to the framework while
843839
# in the build location.
844-
845-
case $ac_sys_system/$ac_sys_release in
846-
Darwin/1.3*)LDFLAGS="$LDFLAGS -Wl,-F. -Wl,-U,$ns_undef_sym";;
847-
Darwin/*)LDFLAGS="$LDFLAGS -Wl,-F. -Wl,-flat_namespace,-U,$ns_undef_sym";;
848-
esac
840+
LDFLAGS="$LDFLAGS -Wl,-F."
849841
AC_DEFINE(WITH_NEXT_FRAMEWORK, 1,
850842
[Define if you want to produce an OpenStep/Rhapsody framework
851843
(shared library plus accessory files).])

0 commit comments

Comments
 (0)