[OpenWrt-Devel] cyclic dependency for /lib/functions.sh and /lib/functions/system.sh in special case

mans0n mans0n at gorani.run
Fri Mar 13 09:35:07 EDT 2020


Hi Adrian,

On 2020-03-13 03:38, mail at adrianschmutzler.de (Adrian Schmutzler) wrote:
 > Hi,
 >
 > I just wanted to source /lib/functions.sh in /lib/functions/system.sh
 > (base-files package), as several functions in the latter require the 
former and
 > it's annoying (and untidy) to have to include both files in several 
places.
 >
 > However, I realized that currently /lib/functions/system.sh is sourced in
 > /lib/functions.sh, function default_postinst():
 >
 > 
https://github.com/openwrt/openwrt/blob/8df14c229c02a3b9329afc6e3ebf4f8aec5b59ed
 > /package/base-files/files/lib/functions.sh#L257
 >
 > So, currently effectively both files depend on each other in at least 
one case.
 >
 > However, in default_postinst(), it looks to me like no function from 
system.sh
 > is actually used directly, but it's merely put there as an "external 
include"
 > for the /etc/uci-defaults/* files processed there.
 >
 > I'd like to resolve this, both as I think the sourcing of 
/lib/functions.sh in
 > /lib/functions/system.sh is helpful and tidy and because I think the 
cross
 > dependency is quite undesirable.
 >
 > I see two solutions to that problem:
 >
 > 1. Remove the sourcing of /lib/functions/system.sh in 
default_postinst(). That
 > would be the tidiest way IMO, as dependencies used in a uci-default 
script
 > should just be put there. But it might break things if people relied 
on it. It
 > would be relatively easy to fix uci-default scripts in openwrt repos, but
 > downstream might complain. Still, I'd prefer this solution.

I like your first solution. It seems there's only one uci-defaults file 
in OpenWrt
repo which really uses /lib/functions/system.sh. I guess downstream 
projects can
handle it relatively easily.

And if we are going to break things, I'd also like to create something like
/lib/functions/mtd.sh and move all mtd functions to there (and rename 
system.sh
to macaddr.sh if possible). I don't feel there's no good reason to keep 
find_mtd_part()
in functions.sh and find_mtd_chardev() in system.sh.
Then we might even don't need to source /lib/functions.sh in 
/lib/functions/system.sh
at the first place. (I think /lib/functions.sh is too big to be sourced 
everywhere...)
But that would really break things heavily, so it's just my thought.

Thanks.

 >
 > 2. A second option would be to keep the include, but just move the 
function
 > default_postinst() out of /lib/functions.sh (from my perspective, it 
doesn't
 > really match there anyway) into a different library file (which?). 
This would
 > still resolve my "dependency problem".
 >
 > Any opinions?
 >
 > Best
 >
 > Adrian
 >
 >


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list