Hi,

On 2022-09-30 21:19:03 -0400, Tom Lane wrote:
> Andres Freund <and...@anarazel.de> writes:
> > I see two potential ways of dealing with this reliably on windows: - error 
> > out
> > if a prefix is not drive-local, that's easy enough to check, something like:
> > normalized_prefix.startswith('/') and not normalized_prefix.startswith('//')
> > as the installation on windows is relocatable, that's not too bad a
> > restriction - if on windows call a small python helper to compute the path 
> > of
> > tmp_install + prefix, using the code that meson uses for the purpose
> 
> I'd be inclined to keep it simple for now.  This seems like something
> that could be improved later in a pretty localized way, and it's not
> like there's not tons of other things that need work.

Just not sure which of the two are simpler, particularly taking docs into
account...

The attached 0001 calls into a meson helper command to do this. Not
particularly pretty, but less code than before, and likely more reliable.


Alternatively, the code meson uses for this is trivial, we could just stash it
in a windows_tempinstall_helper.py as well:

import sys
from pathlib import PureWindowsPath as PurePath

def destdir_join(d1: str, d2: str) -> str:
    if not d1:
        return d2
    # c:\destdir + c:\prefix must produce c:\destdir\prefix
    return str(PurePath(d1, *PurePath(d2).parts[1:]))

print(destdir_join(sys.argv[1], sys.argv[2]))

Greetings,

Andres Freund
>From 20db3a7cbe72dcaaf21ec310f486718de4905f91 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Fri, 30 Sep 2022 18:54:11 -0700
Subject: [PATCH v2 1/2] meson: windows: Determine path to tmp_install + prefix
 using meson

Previously some paths (like c:\ or d:/) worked, but plenty others (like
/path/to or //computer/share/path) didn't. As we'd like to change the default
prefix to /usr/local/pgsql, that's a problem.

Instead of trying to do this in meson.build, call out to the implementation
meson install uses. This isn't pretty, but it's more reliable than what we had
before.

Discussion: https://postgr.es/caeg8a3lgwe-gg6vuddmh91rorhi8gws0mmb-hctmp3_nvgm...@mail.gmail.com
---
 meson.build | 40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/meson.build b/meson.build
index 0cd09ba4308..0a62be8bc69 100644
--- a/meson.build
+++ b/meson.build
@@ -29,6 +29,7 @@ fs = import('fs')
 pkgconfig = import('pkgconfig')
 
 host_system = host_machine.system()
+build_system = build_machine.system()
 host_cpu = host_machine.cpu_family()
 
 cc = meson.get_compiler('c')
@@ -2739,32 +2740,23 @@ endif
 # Test prep
 ###############################################################
 
-# The determination of where a DESTDIR install points to is ugly, it's somewhat hard
-# to combine two absolute paths portably...
-
-prefix = get_option('prefix')
-
-test_prefix = fs.as_posix(prefix)
-
-if fs.is_absolute(get_option('prefix'))
-  if host_system == 'windows'
-    if prefix.split(':/').length() == 1
-      # just a drive
-      test_prefix = ''
-    else
-      test_prefix = prefix.split(':/')[1]
-    endif
-  else
-    assert(prefix.startswith('/'))
-    test_prefix = './@0@'.format(prefix)
-  endif
-endif
-
-# DESTDIR for the installation used to run tests in
+# DESTDIR for the installation we'll run tests in
 test_install_destdir = meson.build_root() / 'tmp_install/'
-# DESTDIR + prefix appropriately munged
-test_install_location = test_install_destdir / test_prefix
 
+# DESTDIR + prefix appropriately munged
+if build_system != 'windows'
+  # On unixoid systems this is trivial, we just prepend the destdir
+  assert(dir_prefix.startswith('/')) # enforced by meson
+  test_install_location = '@0@@1@'.format(test_install_destdir, dir_prefix)
+else
+  # drives, drive-relative paths, etc make this complicated on windows, call
+  # meson's logic for it
+  command = [
+    meson_bin, meson_args, 'runpython', '-c',
+    'import sys; from mesonbuild.scripts import destdir_join; print(destdir_join(sys.argv[4], sys.argv[5]))',
+    test_install_destdir, dir_prefix]
+  test_install_location = run_command(command, check: true).stdout().strip()
+endif
 
 meson_install_args = meson_args + ['install'] + {
     'meson': ['--quiet', '--only-changed', '--no-rebuild'],
-- 
2.37.3.542.gdd3f6c4cae

>From e191b6b8b262461c8725a8706a68d9fc366a0048 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Fri, 30 Sep 2022 10:51:45 -0700
Subject: [PATCH v2 2/2] meson: Add prefix=/usr/local/pgsql to default_options

autoconf set PREFIX to /usr/local/pgsql, so using the same default for meson
makes sense. The effect on windows is that installation defaults to installing
to C:/usr/local/pgsql rather than meson's default of C:/, which doesn't seem
perfect, but OK enough.

Signed-off-by: Junwang Zhao <zhjw...@gmail.com>
Author: Junwang Zhao <zhjw...@gmail.com>
Discussion: https://postgr.es/caeg8a3lgwe-gg6vuddmh91rorhi8gws0mmb-hctmp3_nvgm...@mail.gmail.com
---
 meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meson.build b/meson.build
index 0a62be8bc69..7719270a2e6 100644
--- a/meson.build
+++ b/meson.build
@@ -16,6 +16,7 @@ project('postgresql',
   default_options: [
     'warning_level=1', #-Wall equivalent
     'buildtype=release',
+    'prefix=/usr/local/pgsql',
   ]
 )
 
-- 
2.37.3.542.gdd3f6c4cae

Reply via email to