foo-snapshot / foo-diff convenience functions

René J.V. Bertin rjvbertin at gmail.com
Wed Oct 19 02:50:56 PDT 2016


Hi,

Here's another one of my  probably rhetorical questions...

It's not that uncommon that one includes a PortGroup that adds build settings (e.g. to depends_lib) in a port where those settings are irrelevant and even unwanted. For instance, a port providing translation files for a KDE port would probably need to include a KDE PortGroup but doesn't need to depend on Qt.

If one wants to filter out all those settings that were added automatically one currently needs to do that by hand, by keeping track of what gets added oneself or via a code snippet like this

{{{
        if {[info exists depends_lib]} {
            set curdeps ${depends_lib}
        } else {
            set curdeps ""
        }
        # include PortGroup(s)
        if {${curdeps} eq "" || [string first ${curdeps} ${depends_lib}] >= 0} {
            depends_lib-delete [string map {${curdeps} ""} ${depends_lib}]
        }
}}}

which obviously only handles simple changes.

I never looked into this in detail but I presume that all those "variables" which support the -append, -delete, -replace, &c functions are based on common code. How complicated (and justified) would it be to add code that keeps track of changes made by those functions through convenience functions like below?

	foo-snapshot # start recording differences

	foo-diff # return the difference and stop recording

or more likely

	foo-added # return appended and/or prepended and/or replaced-(new) elements and stop recording
	foo-deleted # return deleted and/or replaced-(old) elements and stop recording

The snippet above would become

{{{
	depends_lib.snapshot
	# include PortGroup(s)
	# we don't need any new dependencies that may have been added, so:
	depends_lib-delete ${depends_lib-added}
}}}

Not that I think this would see very frequent use, but it could be worth the effort if the implementation isn't too complicated and allows for cleaner portfiles and (esp.) dependency relationships, no?

R.


More information about the macports-dev mailing list