simplify destdir_join for readability

We can immediately short-circuit if there is no destdir, as we simply
return the prefix unchanged.

If there is some kind of destdir and the prefix contains a drive letter,
then no matter what we need to remove the drive letter before joining.
Technically, if the destdir is a relative path e.g. `destdir\` and
`C:\prefix`, we should still install to `destdir\prefix` without the
drive letter.

But... we also guarantee that destdir is an absolute path (or empty)
anyway. And even if we didn't, non-absolute destdir is a broken concept
for a variety of complicated reasons. So none of this matters in
practice.

One way or another, we don't need to actually check whether destdir is
an absolute path before cutting off the prefix drive letter.
pull/10278/head
Eli Schwartz 3 years ago
parent 19de032d20
commit 6a287fae5d
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 6
      mesonbuild/scripts/__init__.py

@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: consider switching to pathlib for this
def destdir_join(d1: str, d2: str) -> str:
if not d1:
return d2
# c:\destdir + c:\prefix must produce c:\destdir\prefix
if len(d1) > 1 and d1[1] == ':' \
and len(d2) > 1 and d2[1] == ':':
if len(d2) > 1 and d2[1] == ':':
return d1 + d2[2:]
return d1 + d2

Loading…
Cancel
Save