From 1b1ff806d0ece308e23bc32b0a2114aeb2903f27 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Tue, 31 Dec 2019 20:46:36 +0100
Subject: [PATCH 23/26] Add /d1trimfile:%SRC_DIR% to make pdbs more relocatable

---
 Lib/distutils/_msvccompiler.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Lib/distutils/_msvccompiler.py b/Lib/distutils/_msvccompiler.py
index 03a5986d98..c80ceef350 100644
--- a/Lib/distutils/_msvccompiler.py
+++ b/Lib/distutils/_msvccompiler.py
@@ -350,6 +350,13 @@ class MSVCCompiler(CCompiler) :
                 # without asking the user to browse for it
                 src = os.path.abspath(src)
 
+            # Anaconda/conda-forge customisation, we want our pdbs to be
+            # relocatable:
+            # https://developercommunity.visualstudio.com/comments/623156/view.html
+            d1trimfile_opts = []
+            if 'SRC_DIR' in os.environ:
+                d1trimfile_opts.append("/d1trimfile:" + os.environ['SRC_DIR'])
+
             if ext in self._c_extensions:
                 input_opt = "/Tc" + src
             elif ext in self._cpp_extensions:
@@ -394,7 +401,7 @@ class MSVCCompiler(CCompiler) :
                 raise CompileError("Don't know how to compile {} to {}"
                                    .format(src, obj))
 
-            args = [self.cc] + compile_opts + pp_opts
+            args = [self.cc] + compile_opts + pp_opts + d1trimfile_opts
             if add_cpp_opts:
                 args.append('/EHsc')
             args.append(input_opt)
-- 
2.24.3 (Apple Git-128)

