Re: [gentoo-portage-dev] usage of /bin/bash in shebangs

2022-07-25 Thread Zac Medico

On 7/24/22 23:17, Fabian Groffen wrote:

On 24-07-2022 13:58:31 -0700, Zac Medico wrote:

On 7/24/22 12:29, Fabian Groffen wrote:

Hi,

Quick question, I noticed that portage uses /bin/bash hardcoded in
shebang of scripts, while it uses /usr/bin/env python for python
executable files.

Is there anything against using /usr/bin/env bash for shell scripts?
Changing this would help for Prefix.



I can't think of any reason not to do this.


Do you want to see a patch, or is it OK to push this myself?


It's OK to just push this yourself. Thanks!
--
Thanks,
Zac


OpenPGP_signature
Description: OpenPGP digital signature


[gentoo-portage-dev] [PATCH] doins: fix D check, add EPREFIX check

2022-07-25 Thread Fabian Groffen
bin/ebuild-helpers/doins: fix D check, add EPREFIX check

ED = D/EPREFIX, so checking for ED includes EPREFIX, which when this is
absent fails to check for D.  Simply check for D instead, which catches
both the case for D and ED.

Add check for usage of EPREFIX, like for using D with helpers.

Signed-off-by: Fabian Groffen 

diff --git a/bin/ebuild-helpers/doins b/bin/ebuild-helpers/doins
index 24fe48121..4315a038f 100755
--- a/bin/ebuild-helpers/doins
+++ b/bin/ebuild-helpers/doins
@@ -42,7 +42,7 @@ if ! ___eapi_has_prefix_variables; then
export ED="${D}"
 fi
 
-if [[ ${_E_INSDESTTREE_#${ED}} != "${_E_INSDESTTREE_}" ]]; then
+if [[ ${_E_INSDESTTREE_#${D}} != "${_E_INSDESTTREE_}" ]]; then
__vecho "---" 1>&2
__vecho "You should not use \${D} or \${ED} with helpers." 1>&2
__vecho "  --> ${_E_INSDESTTREE_}" 1>&2
@@ -50,6 +51,16 @@ if [[ ${_E_INSDESTTREE_#${ED}} != "${_E_INSDESTTREE_}" ]]; 
then
__helpers_die "${helper} used with \${D} or \${ED}"
exit 1
 fi
+if [[ -n ${EPREFIX} && \
+   ${_E_INSDESTTREE_#${EPREFIX}} != "${_E_INSDESTTREE_}" ]];
+then
+   __vecho "---" 1>&2
+   __vecho "You should not use \${EPREFIX} with helpers." 1>&2
+   __vecho "  --> ${_E_INSDESTTREE_}" 1>&2
+   __vecho "---" 1>&2
+   __helpers_die "${helper} used with \${EPREFIX}"
+   exit 1
+fi
 
 if ___eapi_doins_and_newins_preserve_symlinks; then
DOINS_ARGS+=( --preserve_symlinks )

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


Re: [gentoo-portage-dev] usage of /bin/bash in shebangs

2022-07-25 Thread Fabian Groffen
On 25-07-2022 08:09:02 -0700, Zac Medico wrote:
> On 7/24/22 23:17, Fabian Groffen wrote:
> > On 24-07-2022 13:58:31 -0700, Zac Medico wrote:
> >> On 7/24/22 12:29, Fabian Groffen wrote:
> >>> Hi,
> >>>
> >>> Quick question, I noticed that portage uses /bin/bash hardcoded in
> >>> shebang of scripts, while it uses /usr/bin/env python for python
> >>> executable files.
> >>>
> >>> Is there anything against using /usr/bin/env bash for shell scripts?
> >>> Changing this would help for Prefix.
> >>
> >>
> >> I can't think of any reason not to do this.
> > 
> > Do you want to see a patch, or is it OK to push this myself?
> 
> It's OK to just push this yourself. Thanks!

Pushed, thanks, b716e3591


-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] emake: explicitly set SHELL

2022-07-25 Thread Fabian Groffen
bin/ebuild-helpers/emake: force SHELL to be set

On Prefix systems /bin/sh can be anything, including very ancient.  So
ensure we're running with bash, since that's what Gentoo Linux is
expecting /bin/sh to be (by default, at least).

Provide a fallback for the (near impossible) case that we use a bash
that doesn't set BASH, or when we don't use bash at all.  This is not
expected, though, as we explicitly require bash throughout all Portage,
so we don't really care about using a non-Prefixed one, for this really
shouldn't happen.

Signed-off-by: Fabian Groffen 

diff --git a/bin/ebuild-helpers/emake b/bin/ebuild-helpers/emake
index 60718a2e4..21da85845 100755
--- a/bin/ebuild-helpers/emake
+++ b/bin/ebuild-helpers/emake
@@ -12,7 +12,7 @@
 source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1
 
 cmd=(
-   ${MAKE:-make} ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
+   ${MAKE:-make} SHELL="${BASH:-/bin/bash}" ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
 )
 
 if [[ ${PORTAGE_QUIET} != 1 ]] ; then

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] 80libraries: add support for Darwin targets

2022-07-25 Thread Fabian Groffen
bin/install-qa-check.d/80libraries: support Darwin/Mach-O objects

Check for dylib on Darwin, so on everything else.

Signed-off-by: Fabian Groffen 

diff --git a/bin/install-qa-check.d/80libraries 
b/bin/install-qa-check.d/80libraries
index 8dc35bb87..a477ec9cb 100644
--- a/bin/install-qa-check.d/80libraries
+++ b/bin/install-qa-check.d/80libraries
@@ -140,7 +140,9 @@ lib_check() {
local abort="no"
local a s
for a in "${ED%/}"/usr/lib*/*.a ; do
-   s=${a%.a}.so
+   [[ ${CHOST} == *-darwin* ]] \
+   && s=${a%.a}.dylib \
+   || s=${a%.a}.so
if [[ ! -e ${s} ]] ; then
s=${s%usr/*}${s##*/usr/}
if [[ -e ${s} ]] ; then

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] multilib-strict: fix for Prefix

2022-07-25 Thread Fabian Groffen
bin/install-qa-check.d/80multilib-strict: use file/find from Prefix

diff --git a/bin/install-qa-check.d/80multilib-strict 
b/bin/install-qa-check.d/80multilib-strict
index afd223250..3db4ecce3 100644
--- a/bin/install-qa-check.d/80multilib-strict
+++ b/bin/install-qa-check.d/80multilib-strict
@@ -1,7 +1,7 @@
 # Strict multilib directory checks
 multilib_strict_check() {
if has multilib-strict ${FEATURES} && \
-  [[ -x /usr/bin/file && -x /usr/bin/find ]] && \
+  [[ -x ${EPREFIX}/usr/bin/file && -x ${EPREFIX}/usr/bin/find ]] && \
   [[ -n ${MULTILIB_STRICT_DIRS} && -n ${MULTILIB_STRICT_DENY} ]]
then
rm -f "${T}/multilib-strict.log"

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] world-writable: tune for Prefix

2022-07-25 Thread Fabian Groffen
bin/install-qa-check.d/90world-writable: include EPREFIX in reports

It is much less confusing and consistent to report full paths including
the leading EPREFIX.

Signed-off-by: Fabian Groffen 

diff --git a/bin/install-qa-check.d/90world-writable 
b/bin/install-qa-check.d/90world-writable
index 820683bd6..90b961a86 100644
--- a/bin/install-qa-check.d/90world-writable
+++ b/bin/install-qa-check.d/90world-writable
@@ -2,7 +2,7 @@
 
 world_writable_check() {
# Now we look for all world writable files.
-   local unsafe_files=$(find "${ED}" -type f -perm -2 | sed -e 
"s:^${ED}:/:")
+   local unsafe_files=$(find "${ED}" -type f -perm -2 | sed -e 
"s:^${D}:/:")
local OLDIFS x prev_shopts=$-
 
OLDIFS=$IFS
@@ -19,7 +21,7 @@ world_writable_check() {
eqawarn
fi
 
-   local unsafe_files=$(find "${ED}" -type f '(' -perm -2002 -o -perm 
-4002 ')' | sed -e "s:^${ED}:/:")
+   local unsafe_files=$(find "${ED}" -type f '(' -perm -2002 -o -perm 
-4002 ')' | sed -e "s:^${D}:/:")
if [[ -n ${unsafe_files} ]] ; then
eqawarn "QA Notice: Unsafe files detected (set*id and world 
writable)"
 

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] misc-functions: Prefix fixes

2022-07-25 Thread Fabian Groffen
bin/misc-functions.sh: some Prefix fixes

- ED needs not to exist, whereas D does, so ensure we check for that,
  and create ED if absent, necessary for further checks to succeed
- use EPREFIX in INSTALL_MASK

Signed-off-by: Fabian Groffen 

diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index c8bac08e7..8fcc23588 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -19,6 +19,8 @@ source "${PORTAGE_BIN_PATH}/ebuild.sh" || exit 1
 install_symlink_html_docs() {
if ! ___eapi_has_prefix_variables; then
local ED=${D}
+   else
+   [[ ! -d ${ED} && -d ${D} ]] && dodir /
fi
cd "${ED}" || die "cd failed"
# Symlink the html documentation (if DOC_SYMLINKS_DIR is set in 
make.conf)
@@ -83,7 +87,7 @@ install_qa_check() {
local EPREFIX= ED=${D}
fi
 
-   cd "${ED}" || die "cd failed"
+   cd "${D}" || die "cd failed"
 
# Collect the paths for QA checks, highest prio first.
paths=(
@@ -367,7 +718,7 @@ preinst_mask() {
local f x
for f in man info doc; do
if has no${f} ${FEATURES}; then
-   INSTALL_MASK+=" /usr/share/${f}"
+   INSTALL_MASK+=" ${EPREFIX}/usr/share/${f}"
fi
done
 

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


[gentoo-portage-dev] [PATCH] phase-functions: make ED, EROOT read-only

2022-07-25 Thread Fabian Groffen
bin/phase-functions.sh: make ED and EROOT read-only too

Like D, make ED and EROOT read-only vars.

Signed-off-by: Fabian Groffen 

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index ccf7eeea7..212b19fc1 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -12,7 +12,7 @@ PORTAGE_READONLY_METADATA="BDEPEND DEFINED_PHASES DEPEND 
DESCRIPTION
PDEPEND RDEPEND REPOSITORY RESTRICT SLOT SRC_URI"
 
 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
-   EBUILD_SH_ARGS EMERGE_FROM FILESDIR MERGE_TYPE \
+   EBUILD_SH_ARGS ED EMERGE_FROM EROOT FILESDIR MERGE_TYPE \
PM_EBUILD_HOOK_DIR \
PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC  \
PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \

-- 
Fabian Groffen
Gentoo on a different level


signature.asc
Description: PGP signature


Re: [gentoo-portage-dev] [PATCH] doins: fix D check, add EPREFIX check

2022-07-25 Thread Ulrich Mueller
> On Mon, 25 Jul 2022, Fabian Groffen wrote:

> @@ -50,6 +51,16 @@ if [[ ${_E_INSDESTTREE_#${ED}} != "${_E_INSDESTTREE_}" ]]; 
> then
>   __helpers_die "${helper} used with \${D} or \${ED}"
>   exit 1
>  fi
> +if [[ -n ${EPREFIX} && \
> + ${_E_INSDESTTREE_#${EPREFIX}} != "${_E_INSDESTTREE_}" ]];

The semicolon is redundant.

> +then
> + __vecho "---" 1>&2
> + __vecho "You should not use \${EPREFIX} with helpers." 1>&2
> + __vecho "  --> ${_E_INSDESTTREE_}" 1>&2
> + __vecho "---" 1>&2
> + __helpers_die "${helper} used with \${EPREFIX}"
> + exit 1
> +fi


signature.asc
Description: PGP signature


Re: [gentoo-portage-dev] [PATCH] doins: fix D check, add EPREFIX check

2022-07-25 Thread Mike Gilbert
Could you please create a PR at https://github.com/gentoo/portage so
that the CI system can test the changes for this patch series?



Re: [gentoo-portage-dev] [PATCH] 80libraries: add support for Darwin targets

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 11:38 AM Fabian Groffen  wrote:
>
> bin/install-qa-check.d/80libraries: support Darwin/Mach-O objects
>
> Check for dylib on Darwin, so on everything else.
>
> Signed-off-by: Fabian Groffen 
>
> diff --git a/bin/install-qa-check.d/80libraries 
> b/bin/install-qa-check.d/80libraries
> index 8dc35bb87..a477ec9cb 100644
> --- a/bin/install-qa-check.d/80libraries
> +++ b/bin/install-qa-check.d/80libraries
> @@ -140,7 +140,9 @@ lib_check() {
> local abort="no"
> local a s
> for a in "${ED%/}"/usr/lib*/*.a ; do
> -   s=${a%.a}.so
> +   [[ ${CHOST} == *-darwin* ]] \
> +   && s=${a%.a}.dylib \
> +   || s=${a%.a}.so

I would find this much easier to read if you converted it to an
if/else statement instead of chaining && and ||.



Re: [gentoo-portage-dev] [PATCH] emake: explicitly set SHELL

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 11:28 AM Fabian Groffen  wrote:
>
> bin/ebuild-helpers/emake: force SHELL to be set
>
> On Prefix systems /bin/sh can be anything, including very ancient.  So
> ensure we're running with bash, since that's what Gentoo Linux is
> expecting /bin/sh to be (by default, at least).
>
> Provide a fallback for the (near impossible) case that we use a bash
> that doesn't set BASH, or when we don't use bash at all.  This is not
> expected, though, as we explicitly require bash throughout all Portage,
> so we don't really care about using a non-Prefixed one, for this really
> shouldn't happen.

I'm a little on the fence about this: in theory, Makefiles should use
POSIX-compatible shell commands unless the author explicitly chooses
to use bash.

I guess we can get away with this since ebuilds always require bash anyway.



Re: [gentoo-portage-dev] [PATCH] multilib-strict: fix for Prefix

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 12:26 PM Fabian Groffen  wrote:
>
> bin/install-qa-check.d/80multilib-strict: use file/find from Prefix
>
> diff --git a/bin/install-qa-check.d/80multilib-strict 
> b/bin/install-qa-check.d/80multilib-strict
> index afd223250..3db4ecce3 100644
> --- a/bin/install-qa-check.d/80multilib-strict
> +++ b/bin/install-qa-check.d/80multilib-strict
> @@ -1,7 +1,7 @@
>  # Strict multilib directory checks
>  multilib_strict_check() {
> if has multilib-strict ${FEATURES} && \
> -  [[ -x /usr/bin/file && -x /usr/bin/find ]] && \
> +  [[ -x ${EPREFIX}/usr/bin/file && -x ${EPREFIX}/usr/bin/find ]] && \
>[[ -n ${MULTILIB_STRICT_DIRS} && -n ${MULTILIB_STRICT_DENY} ]]
> then
> rm -f "${T}/multilib-strict.log"

Seems good to me.



Re: [gentoo-portage-dev] [PATCH] world-writable: tune for Prefix

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 12:41 PM Fabian Groffen  wrote:
>
> bin/install-qa-check.d/90world-writable: include EPREFIX in reports
>
> It is much less confusing and consistent to report full paths including
> the leading EPREFIX.

Makes sense to me.



Re: [gentoo-portage-dev] [PATCH] misc-functions: Prefix fixes

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 12:47 PM Fabian Groffen  wrote:
>
> bin/misc-functions.sh: some Prefix fixes
>
> - ED needs not to exist, whereas D does, so ensure we check for that,
>   and create ED if absent, necessary for further checks to succeed
> - use EPREFIX in INSTALL_MASK

Seems good to me.



Re: [gentoo-portage-dev] [PATCH] phase-functions: make ED, EROOT read-only

2022-07-25 Thread Mike Gilbert
On Mon, Jul 25, 2022 at 1:03 PM Fabian Groffen  wrote:
>
> bin/phase-functions.sh: make ED and EROOT read-only too
>
> Like D, make ED and EROOT read-only vars.

Makes sense.



Re: [gentoo-portage-dev] [PATCH] emake: explicitly set SHELL

2022-07-25 Thread Sam James


> On 25 Jul 2022, at 16:28, Fabian Groffen  wrote:
> 
> bin/ebuild-helpers/emake: force SHELL to be set
> 
> On Prefix systems /bin/sh can be anything, including very ancient.  So
> ensure we're running with bash, since that's what Gentoo Linux is
> expecting /bin/sh to be (by default, at least).
> 
> Provide a fallback for the (near impossible) case that we use a bash
> that doesn't set BASH, or when we don't use bash at all.  This is not
> expected, though, as we explicitly require bash throughout all Portage,
> so we don't really care about using a non-Prefixed one, for this really
> shouldn't happen.
> 
> Signed-off-by: Fabian Groffen 
> 
> diff --git a/bin/ebuild-helpers/emake b/bin/ebuild-helpers/emake
> index 60718a2e4..21da85845 100755
> --- a/bin/ebuild-helpers/emake
> +++ b/bin/ebuild-helpers/emake
> @@ -12,7 +12,7 @@
> source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1
> 
> cmd=(
> - ${MAKE:-make} ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
> + ${MAKE:-make} SHELL="${BASH:-/bin/bash}" ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
> )
> 
> if [[ ${PORTAGE_QUIET} != 1 ]] ; then
> 

I don't think I agree with this as it is. Why not just ${EPREFIX}/bin/sh to 
avoid using
an ancient host sh?

I might use Bash for Portage but my /bin/sh is dash usually.

> --
> Fabian Groffen
> Gentoo on a different level



signature.asc
Description: Message signed with OpenPGP


Re: [gentoo-portage-dev] [PATCH] 80libraries: add support for Darwin targets

2022-07-25 Thread Sam James


> On 26 Jul 2022, at 00:33, Mike Gilbert  wrote:
> 
> On Mon, Jul 25, 2022 at 11:38 AM Fabian Groffen  wrote:
>> 
>> bin/install-qa-check.d/80libraries: support Darwin/Mach-O objects
>> 
>> Check for dylib on Darwin, so on everything else.
>> 
>> Signed-off-by: Fabian Groffen 
>> 
>> diff --git a/bin/install-qa-check.d/80libraries 
>> b/bin/install-qa-check.d/80libraries
>> index 8dc35bb87..a477ec9cb 100644
>> --- a/bin/install-qa-check.d/80libraries
>> +++ b/bin/install-qa-check.d/80libraries
>> @@ -140,7 +140,9 @@ lib_check() {
>>local abort="no"
>>local a s
>>for a in "${ED%/}"/usr/lib*/*.a ; do
>> -   s=${a%.a}.so
>> +   [[ ${CHOST} == *-darwin* ]] \
>> +   && s=${a%.a}.dylib \
>> +   || s=${a%.a}.so
> 
> I would find this much easier to read if you converted it to an
> if/else statement instead of chaining && and ||.

Yes, please.


signature.asc
Description: Message signed with OpenPGP


Re: [gentoo-portage-dev] [PATCH] emake: explicitly set SHELL

2022-07-25 Thread Sam James


> On 26 Jul 2022, at 04:00, Sam James  wrote:
> 
> 
> 
>> On 25 Jul 2022, at 16:28, Fabian Groffen  wrote:
>> 
>> bin/ebuild-helpers/emake: force SHELL to be set
>> 
>> On Prefix systems /bin/sh can be anything, including very ancient.  So
>> ensure we're running with bash, since that's what Gentoo Linux is
>> expecting /bin/sh to be (by default, at least).
>> 
>> Provide a fallback for the (near impossible) case that we use a bash
>> that doesn't set BASH, or when we don't use bash at all.  This is not
>> expected, though, as we explicitly require bash throughout all Portage,
>> so we don't really care about using a non-Prefixed one, for this really
>> shouldn't happen.
>> 
>> Signed-off-by: Fabian Groffen 
>> 
>> diff --git a/bin/ebuild-helpers/emake b/bin/ebuild-helpers/emake
>> index 60718a2e4..21da85845 100755
>> --- a/bin/ebuild-helpers/emake
>> +++ b/bin/ebuild-helpers/emake
>> @@ -12,7 +12,7 @@
>> source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1
>> 
>> cmd=(
>> -${MAKE:-make} ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
>> +${MAKE:-make} SHELL="${BASH:-/bin/bash}" ${MAKEOPTS} "$@" ${EXTRA_EMAKE}
>> )
>> 
>> if [[ ${PORTAGE_QUIET} != 1 ]] ; then
>> 
> 
> I don't think I agree with this as it is. Why not just ${EPREFIX}/bin/sh to 
> avoid using
> an ancient host sh?
> 

Sorry, ${BROOT}, I guess.

> I might use Bash for Portage but my /bin/sh is dash usually.
> 
>> --
>> Fabian Groffen
>> Gentoo on a different level



signature.asc
Description: Message signed with OpenPGP