Bug 192990

Summary: Mk/bsd.port.mk: PKGFILE wrong at “make -V PKGFILE”
Product: Ports & Packages Reporter: Kalten <kalten>
Component: Ports FrameworkAssignee: Bryan Drewery <bdrewery>
Status: Open ---    
Severity: Affects Many People CC: bdrewery
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   

Description Kalten 2014-08-25 14:28:02 UTC
If one executes “make -V PKGFILE” in e.g. “games/fairymax/” one gets the result “…/games/fairymax/fairymax-4.8S.6.txz” but the package built by “make package” is “…/games/fairymax/work/pkg/fairymax-4.8S.6.txz”.

As far as I can see, ${PKGFILE} is set in “Mk/bsd.port.mk”:
---SCHNIPP---
PKGREPOSITORYSUBDIR?=   All
PKGREPOSITORY?=     ${PACKAGES}/${PKGREPOSITORYSUBDIR}
.if exists(${PACKAGES})
PKGFILE?=       ${PKGREPOSITORY}/${PKGNAME}${PKG_SUFX}
.else
PKGFILE?=       ${.CURDIR}/${PKGNAME}${PKG_SUFX}
.endif
---schnapp---

I suppose the else branch should be changed to
PKGFILE?=       ${WRKDIR}/pkg/${PKGNAME}${PKG_SUFX}

ru,
 Kalten
Comment 1 John Marino freebsd_committer freebsd_triage 2014-08-25 14:55:14 UTC
let's start with portmgr...
Comment 2 Bryan Drewery freebsd_committer freebsd_triage 2014-08-25 16:58:25 UTC
It's complicated because it changes depending on whether it can write to your packages/ dir.

Either way it will write the package to work/pkg/ and then if it can write to your PACKAGES dir it will copy it over to there.

If you are depending on PKGFILE for something then it is best that your PACKAGES dir is writable by you as well.

It may be that a bug exists where it is not creating the PACKAGES dir by default anymore. If so I can fix that. I don't have time to check at the moment though.
Comment 3 Kalten 2014-08-25 17:28:14 UTC
(In reply to Bryan Drewery from comment #2)
> It's complicated because it changes depending on whether it can write to
> your packages/ dir.
We are told to try to “Package as an unprivileged user [or else set] NEED_ROOT=yes”¹⁾—so, yes: I am not allowed to write to that directory. But that had not been my point (it would be the then branch).

> Either way it will write the package to work/pkg/ and then if it can write
> to your PACKAGES dir it will copy it over to there.
exactly: so spitting out “./${PKGNAME}${PKG_SUFX}” happens to be nonsense in any case but instead “${WRKDIR}/pkg/${PKGNAME}${PKG_SUFX}” as you have mentioned yourself right here (as I had in comment #0), namely:

>> I suppose the else branch should be changed to
>> PKGFILE?=       ${WRKDIR}/pkg/${PKGNAME}${PKG_SUFX}

> If you are depending on PKGFILE for something then it is best that your
> PACKAGES dir is writable by you as well.
As noted above, we are more or less told there¹⁾ to not be able to write to that directory, as we are to “Package as an unprivileged user” and we depend on PKGFILE, as we are told there¹⁾ to call
“bzgrep work/stage `make -V PKGFILE`”
(yes, one could substituete the real path for “`make -V PKGFILE`” but I do not deem that to make sense—what we are told to do in official documents like that¹⁾ one should work, in my opinion)

> It may be that a bug exists where it is not creating the PACKAGES dir by
> default anymore. If so I can fix that. I don't have time to check at the
> moment though.
It is only about the else branch as stated in comment #0

I hope to have cleared up everything.

ru,
 Kalten

¹⁾ https://wiki.freebsd.org/ports/StageDir
Comment 4 Bryan Drewery freebsd_committer freebsd_triage 2014-08-25 17:55:12 UTC
(In reply to Kalten from comment #3)
> (In reply to Bryan Drewery from comment #2)
> > It's complicated because it changes depending on whether it can write to
> > your packages/ dir.
> We are told to try to “Package as an unprivileged user [or else set]
> NEED_ROOT=yes”¹⁾—so, yes: I am not allowed to write to that directory. But
> that had not been my point (it would be the then branch).
> 
> > Either way it will write the package to work/pkg/ and then if it can write
> > to your PACKAGES dir it will copy it over to there.
> exactly: so spitting out “./${PKGNAME}${PKG_SUFX}” happens to be nonsense in
> any case but instead “${WRKDIR}/pkg/${PKGNAME}${PKG_SUFX}” as you have
> mentioned yourself right here (as I had in comment #0), namely:
> 
> >> I suppose the else branch should be changed to
> >> PKGFILE?=       ${WRKDIR}/pkg/${PKGNAME}${PKG_SUFX}
> 
> > If you are depending on PKGFILE for something then it is best that your
> > PACKAGES dir is writable by you as well.
> As noted above, we are more or less told there¹⁾ to not be able to write to
> that directory, as we are to “Package as an unprivileged user” and we depend
> on PKGFILE, as we are told there¹⁾ to call

Packaging as non-root is not related to you having a writable PACKAGES dir. It is about it being able to *build*. Many ports do not build unless they are root.

> “bzgrep work/stage `make -V PKGFILE`”
> (yes, one could substituete the real path for “`make -V PKGFILE`” but I do
> not deem that to make sense—what we are told to do in official documents
> like that¹⁾ one should work, in my opinion)
> 
> > It may be that a bug exists where it is not creating the PACKAGES dir by
> > default anymore. If so I can fix that. I don't have time to check at the
> > moment though.
> It is only about the else branch as stated in comment #0
> 
> I hope to have cleared up everything.

Aha, thanks for pointing out it was in this document. This check is not needed at all anymore.

> 
> ru,
>  Kalten
> 
> ¹⁾ https://wiki.freebsd.org/ports/StageDir
Comment 5 Bryan Drewery freebsd_committer freebsd_triage 2014-08-27 15:13:26 UTC
I'll fix all of this. I created the problems.