Repository: mesonbuild/meson

Issue:
meson compile broken with VS backend unless PLATFORM is defined
**Describe the bug**
If you initialize a build with `--backend=vs`, then use `meson compile`, it doesn't work unless the `PLATFORM` environment variable is defined.

**To Reproduce**
Open Developer PowerShell for VS 2019. Recreate the [tutorial project](https://mesonbuild.com/Tutorial.html). Then run this in the project directory:

```
> meson --backend=vs build
> meson compile -C build
```
The output from the latter command is as follows:

```
Traceback (most recent call last):
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mesonmain.py", line 134, in run
    return options.run_func(options)
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mcompile.py", line 349, in run
    cmd, env = get_parsed_args_vs(options, bdir)
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mcompile.py", line 236, in get_parsed_args_vs
    del env['PLATFORM']
KeyError: 'PLATFORM'
```

**Expected behavior**
Meson should build the project.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)? Native build.
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)? Windows 10.
* what Python version are you using e.g. 3.8.0? 3.9.4.
* what `meson --version`? 0.58.0.
* what `ninja --version` if it's a Ninja build? N/A

meson compile broken with VS backend unless PLATFORM is defined
**Describe the bug**
If you initialize a build with `--backend=vs`, then use `meson compile`, it doesn't work unless the `PLATFORM` environment variable is defined.

**To Reproduce**
Open Developer PowerShell for VS 2019. Recreate the [tutorial project](https://mesonbuild.com/Tutorial.html). Then run this in the project directory:

```
> meson --backend=vs build
> meson compile -C build
```
The output from the latter command is as follows:

```
Traceback (most recent call last):
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mesonmain.py", line 134, in run
    return options.run_func(options)
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mcompile.py", line 349, in run
    cmd, env = get_parsed_args_vs(options, bdir)
  File "C:\Users\dpb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mesonbuild\mcompile.py", line 236, in get_parsed_args_vs
    del env['PLATFORM']
KeyError: 'PLATFORM'
```

**Expected behavior**
Meson should build the project.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)? Native build.
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)? Windows 10.
* what Python version are you using e.g. 3.8.0? 3.9.4.
* what `meson --version`? 0.58.0.
* what `ninja --version` if it's a Ninja build? N/A



Discussion:

Resolving patch:
diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py
--- a/mesonbuild/mcompile.py
+++ b/mesonbuild/mcompile.py
@@ -224,9 +224,10 @@ def get_parsed_args_vs(options: 'argparse.Namespace', builddir: Path) -> T.Tuple
 
     cmd += options.vs_args
 
-    # Remove platform from env so that msbuild does not pick x86 platform when solution platform is Win32
+    # Remove platform from env if set so that msbuild does not
+    # pick x86 platform when solution platform is Win32
     env = os.environ.copy()
-    del env['PLATFORM']
+    env.pop('PLATFORM', None)
 
     return cmd, env
 


Test patch: