Make python27 build as an unprivileged user

John Hein john.hein at microsemi.com
Sat Apr 12 22:47:22 UTC 2014


Antoine Brodin wrote at 11:57 +0200 on Apr  4, 2014:
 > On Fri, Apr 4, 2014 at 12:51 AM, Julio Merino <jmmv at freebsd.org> wrote:
 > > On Thu, Apr 3, 2014 at 3:30 PM, Antoine Brodin <antoine at freebsd.org> wrote:
 > >> koobs' new python34 port (not committed yet) packages fine as non
 > >> root, so it seems doable.
 > >
 > > Sorry but I don't see how that's relevant. Python 3.4 is a much more
 > > modern package than 2.7 and many things may have changed in its build
 > > infrastructure.
 > >
 > > Yes, fixing the root cause is doable for sure, and I agree with you
 > > that, ideally, this should be properly fixed. But: I don't think it's
 > > worth our time considering that: 1) this is for the "old" 2.x branch
 > > and 2) some knowledgeable people have already tried and failed at
 > > doing so.
 > >
 > > As things currently are, the python27 package is broken when building
 > > from ports as non-root.  (Which by the way is annoying for
 > > architectures without prebuilt packages; I have found this problem
 > > under powerpc64!)
 > >
 > > What I'm proposing is that we trivially workaround the problem by
 > > *temporarily* defining NEED_ROOT and later investigating the failure.
 > > Doing the former does not preclude the latter, but at least fixes the
 > > obvious bug.
 > >
 > > I don't want to put words on your mouth, but what I think you are
 > > proposing is that we leave the package broken for an arbitrary
 > > (possibly infinite) amount of time until someone decides to track and
 > > fix the root cause. If you are offering to investigate this relatively
 > > soon as the maintainer that's perfect though.
 > >
 > > So up to you really! If you do not agree with the workaround, I will
 > > at least file a PR for proper tracking.
 > 
 > Try attached patch.
 > 
 > Cheers,
 > 
 > Antoine
 > Allow staging python27 as a regular user:
 > 
 > - when compiling, don't compile the running command otherwise it fails to compile modules imported by the running command
 > 
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/getopt.pyc'
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/py_compile.pyc'
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/struct.pyc'
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/getopt.pyo'
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/py_compile.pyo'
 > Sorry [Errno 13] Permission denied: '/wrkdirs/usr/ports/lang/python27/work/stage/usr/local/lib/python2.7/struct.pyo'
 > 
 > - ranlib before installing read only
 > 
 > Index: lang/python27/files/patch-Makefile.pre.in
 > ===================================================================
 > --- lang/python27/files/patch-Makefile.pre.in	(revision 350060)
 > +++ lang/python27/files/patch-Makefile.pre.in	(working copy)
 > @@ -1,6 +1,6 @@
 > ---- ./Makefile.pre.in.orig	2013-04-06 18:02:34.000000000 +0400
 > -+++ ./Makefile.pre.in	2013-04-07 22:30:19.000000000 +0400
 > -@@ -281,9 +281,9 @@
 > +--- ./Makefile.pre.in.orig	2013-11-10 07:36:41.000000000 +0000
 > ++++ ./Makefile.pre.in	2014-04-04 09:16:00.000000000 +0000
 > +@@ -285,9 +285,9 @@
 >   
 >   ##########################################################################
 >   # AST
 > @@ -12,3 +12,28 @@
 >   AST_C=		$(AST_C_DIR)/Python-ast.c
 >   AST_ASDL=	$(srcdir)/Parser/Python.asdl
 >   
 > +@@ -1006,12 +1006,12 @@
 > + 			$(DESTDIR)$(LIBDEST)/distutils/tests ; \
 > + 	fi
 > + 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
 > +-		$(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
 > ++		$(PYTHON_FOR_BUILD) -B -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
 > + 		-d $(LIBDEST) -f \
 > + 		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
 > + 		$(DESTDIR)$(LIBDEST)
 > + 	PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
 > +-		$(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
 > ++		$(PYTHON_FOR_BUILD) -B -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
 > + 		-d $(LIBDEST) -f \
 > + 		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
 > + 		$(DESTDIR)$(LIBDEST)
 > +@@ -1089,8 +1089,8 @@
 > + 			if test "$(SO)" = .dll; then \
 > + 				$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
 > + 			else \
 > ++				$(RANLIB) $(LIBRARY) ; \
 > + 				$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
 > +-				$(RANLIB) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
 > + 			fi; \
 > + 		else \
 > + 			echo Skip install of $(LIBRARY) - use make frameworkinstall; \


I'm a little late, but I've had this patch ever since python was
staged.  I _always_ build the 'stage' stage of ports as non-root (and
I think tinderbox, et. al., should do so, too - but that's a bit
beyond scope for this email thread):

@@ -975,6 +975,7 @@
 			echo $(INSTALL_DATA) $$i $(LIBDEST); \
 		fi; \
 	done
+	chmod u+w $(DESTDIR)$(LIBDEST)/*.py
 	@for d in $(LIBSUBDIRS); \
 	do \
 		a=$(srcdir)/Lib/$$d; \
@@ -1090,6 +1091,7 @@
 				$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
 			else \
 				$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
+				chmod u+w $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
 				$(RANLIB) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
 			fi; \
 		else \


Antoine's patch is even better.


More information about the freebsd-python mailing list