combining directories / moving files within Portfile

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

combining directories / moving files within Portfile

Michael Dickens-4
I have an issue with SIP that needs to be addressed, that I'm not sure
how do execute in port via Portfiles. I have a solution, but it's kinda
a hack.

Background
---
Some SIP dependencies use sipconfig to glean the directory into which to
install generated SIP files [in Python: "import sipconfig"; "sipcfg =
sipconfig.Configuration()"; "sipcfg.default_sip_dir" -> default
"--sipdir" for installing generated SIP files].

Other SIP dependencies use a configuration --sipdir for this directory,
with the default generally being "$prefix/share/pyXY-sip/$subport", but
sometimes "$PYTHON_PREFIX/share/sip/$subport" where "PYTHON_PREFIX" is
the top-level Python directory (in MacPorts,
"$frameworks_dir/Python.framework/Versions/X.Y/").

I've been told that the "sipconfig" import is being removed from SIP
sometime soonish, so we're better off specifying a directory into which
ports install SIP files. Also, different ports choose different SIP
directories, and combining these makes sense. What I'd like to do is
symlink "$prefix/share/pyXY-sip/$subport" ->
"$PYTHON_PREFIX/share/sip/$subport", so that it doesn't matter which
method the port chooses, even if we specify one directory or the other.

I can fix all of the ports that I know of that use SIP to install into
the PYTHON_PREFIX version, but the ordering makes a difference because
both of the SIP directories are populated at least on my MacPorts
install. This poses the issue that the SIP port should be creating the
latter directory as well as symlink, but it cannot while the former
directory has anything in it.

I can update the dependencies first, so that they are all installing
into the PYTHON_PREFIX directory, then update SIP ... but, if someone
does a "sudo port selfupdate" then port will do the update with SIP
first followed by dependencies, which won't work. I can do this & update
SIP maybe a year down the road ... but, that seems silly ... there has
got to be a better way!

I'd prefer to not require the user to deactivate various ports, instead
automating the process of moving the files to allow the symlink to be
created by the SIP port.

My Hack
---
My "hack" is to have SIP check in pre-activate for the directory
"$prefix/share/pyXY-sip/" and if found then create an archive of its
contents (into /tmp/something.tar), and "cd $prefix/share && rm -rf
pyXY-sip". Then the 'activate' takes place, which creates the symlink to
the "$PYTHON_PREFIX/share/sip/$subport" directory. Then in post-activate
check for the archive & if found restore the contents into the directory
"$PYTHON_PREFIX/share/sip/" && remove the archive.

In my testing, this hack works perfectly & without user intervention.
That said, it's a hack & maybe not the right thing to do. Hence me
reaching out to MP devs: is there a good way to combine the contents of
multiple directories via a common port? Should I just give up on trying
to automate the process, instead force the user to deactivate /
reactivate ports?

Thanks for your thoughts / comments. - MLD
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: combining directories / moving files within Portfile

Rainer Müller-4
On 2017-07-19 23:09, Michael Dickens wrote:
> I have an issue with SIP that needs to be addressed, that I'm not sure
> how do execute in port via Portfiles. I have a solution, but it's kinda
> a hack.

This confused me a lot as I first assumed you are talking about
System Integrity Protection... :-)

> [...]

> My Hack
> ---
> My "hack" is to have SIP check in pre-activate for the directory
> "$prefix/share/pyXY-sip/" and if found then create an archive of its
> contents (into /tmp/something.tar), and "cd $prefix/share && rm -rf
> pyXY-sip". Then the 'activate' takes place, which creates the symlink to
> the "$PYTHON_PREFIX/share/sip/$subport" directory. Then in post-activate
> check for the archive & if found restore the contents into the directory
> "$PYTHON_PREFIX/share/sip/" && remove the archive.

These files would no longer be properly attributed to the port in the
registry, so they might be left behind on uninstall.

It sounds like you need the deactivate hack that is already in use for
some ports that needed to replace files:
https://trac.macports.org/wiki/PortfileRecipes#deactivatehack

I would deactivate all ports known to install files there in a
pre-activate phase in the main sip port.

Rainer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: combining directories / moving files within Portfile

Michael Dickens-4
On Thu, Jul 20, 2017, at 10:46 AM, Rainer Müller wrote:
> On 2017-07-19 23:09, Michael Dickens wrote:
> > I have an issue with SIP that needs to be addressed, that I'm not sure
> > how do execute in port via Portfiles. I have a solution, but it's kinda
> > a hack.
>
> This confused me a lot as I first assumed you are talking about
> System Integrity Protection... :-)

LOL

> > My Hack
> > ---
> > My "hack" is to have SIP check in pre-activate for the directory
> > "$prefix/share/pyXY-sip/" and if found then create an archive of its
> > contents (into /tmp/something.tar), and "cd $prefix/share && rm -rf
> > pyXY-sip". Then the 'activate' takes place, which creates the symlink to
> > the "$PYTHON_PREFIX/share/sip/$subport" directory. Then in post-activate
> > check for the archive & if found restore the contents into the directory
> > "$PYTHON_PREFIX/share/sip/" && remove the archive.
>
> These files would no longer be properly attributed to the port in the
> registry, so they might be left behind on uninstall.

The registry seemed OK with the move, since port follows links correctly
for installing or removing files. That said, I can't do "port provides
..." on any of those files any longer, but I don't care since they will
be dealt with via their port upgrades anyway.

> It sounds like you need the deactivate hack that is already in use for
> some ports that needed to replace files:
> https://trac.macports.org/wiki/PortfileRecipes#deactivatehack
>
> I would deactivate all ports known to install files there in a
> pre-activate phase in the main sip port.

Yes! That's the trick.

Instead of deactivating all ports known to install files there, is there
a way to query the registry for which port owns the files present (e.g.,
"port provides ..." except in TCL registry function calls)? - MLD
Loading...