Repository: mesonbuild/meson

Issue:
Potential regression: incorrect selinux context after install
**Describe the bug**
Potential regression of https://github.com/mesonbuild/meson/issues/1967
The selinux context is wrong after a ninja install. 

**To Reproduce**
```
# meson.build
project('test', 'c', version : '0')

systemd = dependency('systemd')
systemd_unit_dir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir')

install_data(
  'test.service',
  install_dir: systemd_unit_dir # /usr/lib/systemd/system
)
```
```
$ touch test.service
$ meson --prefix=/usr build
# ninja -C build install
```
**Current behaviour**
```
$ ls -lZ /usr/lib/systemd/system | grep test
-rw-r--r--. 1 root root unconfined_u:object_r:user_home_t:s0                     0 Jul 19 04:38 test.service
```
As shown here, the selinux context is `unconfined_u:object_r:user_home_t:s0`.

**Expected behavior**
Ideally the installed file should have `system_u:object_r:systemd_unit_file_t:s0` (this is what is set if using `/usr/bin/install` or `restorecon -F` afterwards).
Otherwise, at least `unconfined_u:object_r:systemd_unit_file_t:s0` (using `restorecon` afterwards)

**system parameters**
Fedora 36 with default selinux settings
Python 3.10.5
Meson 0.62.2
Ninja 1.10.2
```
$ selinuxenabled
$ which restorecon
/usr/sbin/restorecon
```


Discussion:

Resolving patch:
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -1394,20 +1394,22 @@ def partition(pred: T.Callable[[_T], object], iterable: T.Iterable[_T]) -> T.Tup
 
 
 def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
+               stdin: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.DEVNULL,
                stdout: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE,
                stderr: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE,
                **kwargs: T.Any) -> T.Tuple['subprocess.Popen[str]', str, str]:
     import locale
     encoding = locale.getpreferredencoding()
-    # Redirect stdin to DEVNULL otherwise the command run by us here might mess
+    # Stdin defaults to DEVNULL otherwise the command run by us here might mess
     # up the console and ANSI colors will stop working on Windows.
-    if 'stdin' not in kwargs:
-        kwargs['stdin'] = subprocess.DEVNULL
+    # If write is not None, set stdin to PIPE so data can be sent.
+    if write is not None:
+        stdin = subprocess.PIPE
     if not sys.stdout.encoding or encoding.upper() != 'UTF-8':
-        p, o, e = Popen_safe_legacy(args, write=write, stdout=stdout, stderr=stderr, **kwargs)
+        p, o, e = Popen_safe_legacy(args, write=write, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
     else:
         p = subprocess.Popen(args, universal_newlines=True, close_fds=False,
-                             stdout=stdout, stderr=stderr, **kwargs)
+                             stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
         o, e = p.communicate(write)
     # Sometimes the command that we run will call another command which will be
     # without the above stdin workaround, so set the console mode again just in
@@ -1417,11 +1419,12 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
 
 
 def Popen_safe_legacy(args: T.List[str], write: T.Optional[str] = None,
+                      stdin: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.DEVNULL,
                       stdout: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE,
                       stderr: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE,
                       **kwargs: T.Any) -> T.Tuple['subprocess.Popen[str]', str, str]:
     p = subprocess.Popen(args, universal_newlines=False, close_fds=False,
-                         stdout=stdout, stderr=stderr, **kwargs)
+                         stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
     input_ = None  # type: T.Optional[bytes]
     if write is not None:
         input_ = write.encode('utf-8')


Test patch: