[MacPorts] #69585: path depspecs containing special regex characters are not escaped (was: gtk3-devel: path-style dependencies not working now)
MacPorts
noreply at macports.org
Tue Jun 4 13:01:49 UTC 2024
#69585: path depspecs containing special regex characters are not escaped
-------------------------------------------------+-------------------------
Reporter: barracuda156 | Owner: mascguy
Type: defect | Status: assigned
Priority: Normal | Milestone: MacPorts
| Future
Component: base | Version: 2.9.3
Resolution: | Keywords: haspatch
Port: gtk2, gtk2-devel, gtk3, gtk3-devel |
-------------------------------------------------+-------------------------
Changes (by ryandesign):
* keywords: => haspatch
* milestone: => MacPorts Future
* component: ports => base
* port: gtk3, gtk3-devel, gtk4, gtk4-devel, glibmm, glibmm-devel => gtk2,
gtk2-devel, gtk3, gtk3-devel
Comment:
Replying to [comment:15 barracuda156]:
> Same issue with `gtk4-devel`, path-style deps are not recognized:
> However `gtkmm4` sets the dependency as a path-style.
The gtk4 problem should be fixed. Ports that depended on gtk4 did so via a
path that did not exist (`lib/pkgconfig/gtk+-4.0.pc`); I fixed it (to
`lib/pkgconfig/gtk4.pc`).
The gtk3 problem remains and I see it on my machine as well, and the key
lies in this line from the log:
{{{
Didn't find receipt, going to depspec regex for: gtk3
}}}
MacPorts takes the middle part of the depspec
`path:lib/pkgconfig/gtk+-3.0.pc:gtk3`—`lib/pkgconfig/gtk+-3.0.pc`—and
turns the last path component—`gtk+-3.0.pc`—into a regular expression.
Specifically, it anchors it at the beginning (`^`) and end (`$`) but other
than that it is copied directly into the regular expression without
escaping (even though the MacPorts Guide says it's just a file path). This
is significant for gtk2 and gtk3 since `+` is a special character in
regular expressions. The path leading up to the last path component—e.g.
`lib/pkgconfig/`—is not treated as a regular expression.
From portutil.tcl:
{{{#!tcl
proc _pathtest {depspec {return_match 0}} {
global prefix
set depregex [lindex [split $depspec :] 1]
# separate directory from regex
set fullname $depregex
regexp {^(.*)/(.*?)$} "$fullname" match search_path depregex
if {[string index $search_path 0] ne "/"} {
# Prepend prefix if not an absolute path
set search_path "${prefix}/${search_path}"
}
set depregex \^$depregex\$
return [_mportsearchpath $depregex $search_path 0 $return_match]
}
}}}
I would guess that this was not intentional and it was simply not
considered that a filename that we might want to test would contain the
`+` character. The problem would also occur for any filenames we might
test that contain other special regex characters—like `*`, `[`, `]`, `{`,
`}`, `(`, `)`—but I don't think we've encountered those. `.` is also a
special regex character meaning "any character" although that has not led
to any problems.
One solution is to change all depspecs and escape all special regex
characters. For example, the depspec
`path:lib/pkgconfig/gtk\\+-3\\.0\\.pc:gtk3` allows gtk3-devel to be used
but this is ugly; we surely don't want to have to write that in every
Portfile. The double backslash is needed because one level of escaping is
interpreted by Tcl before it gets interpreted as a regex.
The better solution, I think, is to fix MacPorts base so that it escapes
special characters in the depspec using `quotemeta`. That's implemented
here: https://github.com/macports/macports-base/pull/337
--
Ticket URL: <https://trac.macports.org/ticket/69585#comment:21>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list