Repository: zooba/pymsbuild (language: python)

Issue:
Source directory should always be include dir
Because generated files end up elsewhere, we need to point IncludeDir back at the source


Discussion / hints:

Fix patch:
diff --git a/pymsbuild/targets/cpp-POSIX_x64.targets b/pymsbuild/targets/cpp-POSIX_x64.targets
index d411f1f..d345228 100644
--- a/pymsbuild/targets/cpp-POSIX_x64.targets
+++ b/pymsbuild/targets/cpp-POSIX_x64.targets
@@ -28,7 +28,25 @@
 
   <Target Name="ClCompile" Inputs="@(ClCompile)" Outputs="%(ClCompile._ResolvedOutput)">
     <Message Text="%(ClCompile.Identity) -> %(ClCompile.ObjectFile)" Importance="high" />
-    <Exec Command="$(CC_Cmd) -c -o %(ClCompile._ResolvedOutput) %(ClCompile.Identity) $(PythonCFlags)" />
+    <ItemGroup>
+      <_IncludeSpec Remove="@(_IncludeSpec)" />
+      <_IncludeSpec Include="%(ClCompile.AdditionalIncludeDirectories)" />
+    </ItemGroup>
+    <PropertyGroup>
+      <!-- Base command -->
+      <_Cmd>$(CC_Cmd) -c</_Cmd>
+      <!-- Output file -->
+      <_Cmd>$(_Cmd) -o %(ClCompile._ResolvedOutput)</_Cmd>
+      <!-- Source file -->
+      <_Cmd>$(_Cmd) %(ClCompile.Identity)</_Cmd>
+      <!-- Include directories -->
+      <_IncludeSpec>@(_IncludeSpec, ' -I')</_IncludeSpec>
+      <_Cmd Condition="$(_IncludeSpec) != ''">$(_Cmd) -I$(_IncludeSpec)</_Cmd>
+      <!-- Python flags -->
+      <_Cmd>$(_Cmd) $(PythonCFlags)</_Cmd>
+    </PropertyGroup>
+    <Message Importance="Normal" Text="Executing $(_Cmd)" />
+    <Exec Command="$(_Cmd)" />
     <ItemGroup>
       <FileWrites Include="%(ClCompile._ResolvedOutput)" />
     </ItemGroup>
@@ -36,7 +54,25 @@
 
   <Target Name="Link" Inputs="@(_LinkerInputs)" Outputs="$(TargetPath)">
     <Message Text="-> $([msbuild]::MakeRelative($(OutDir), $(TargetPath)))" Importance="high" />
-    <Exec Command="$(Link_Cmd) -o $(TargetPath) @(_LinkerInputs,' ') $(PythonLDFlags)" />
+    <ItemGroup>
+      <_LibSpec Remove="@(_LibSpec)" />
+      <_LibSpec Include="%(_LinkerInputs.AdditionalLibraryDirectories)" />
+    </ItemGroup>
+    <PropertyGroup>
+      <!-- Base command -->
+      <_Cmd>$(Link_Cmd)</_Cmd>
+      <!-- Output file -->
+      <_Cmd>$(_Cmd) -o $(TargetPath)</_Cmd>
+      <!-- Lib directories -->
+      <_LibSpec>@(_LibSpec, ' -L')</_LibSpec>
+      <_Cmd Condition="$(_LibSpec) != ''">$(_Cmd) -L$(_LibSpec)</_Cmd>
+      <!-- Source files -->
+      <_Cmd>$(_Cmd) @(_LinkerInputs, ' ')</_Cmd>
+      <!-- Python flags -->
+      <_Cmd>$(_Cmd) $(PythonLDFlags)</_Cmd>
+    </PropertyGroup>
+    <Message Importance="Normal" Text="Executing $(_Cmd)" />
+    <Exec Command="$(_Cmd)" />
     <ItemGroup>
       <FileWrites Include="$(TargetPath)" />
     </ItemGroup>
diff --git a/pymsbuild/targets/pyd.props b/pymsbuild/targets/pyd.props
index 0268eb5..6a50089 100644
--- a/pymsbuild/targets/pyd.props
+++ b/pymsbuild/targets/pyd.props
@@ -6,7 +6,7 @@
   </PropertyGroup>
   <ItemDefinitionGroup>
     <ClCompile>
-      <AdditionalIncludeDirectories>$(PythonIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(SourceRootDir);$(PythonIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <AdditionalLibraryDirectories>$(PythonLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>


Test patch:
diff --git a/tests/testcython/_msbuild.py b/tests/testcython/_msbuild.py
index 702bb82..c70ea85 100644
--- a/tests/testcython/_msbuild.py
+++ b/tests/testcython/_msbuild.py
@@ -4,6 +4,7 @@
 PACKAGE = Package(
     "testcython",
     CythonPydFile("mod1",
+        IncludeFile("my_header.h"),
         CythonIncludeFile("header.pxd"),
         PyxFile(
             "src.pyx",
diff --git a/tests/testcython/header.pxd b/tests/testcython/header.pxd
index 4333046..6334110 100644
--- a/tests/testcython/header.pxd
+++ b/tests/testcython/header.pxd
@@ -3,3 +3,6 @@
 
 cdef extern from "":
     const char *value
+
+cdef extern from "my_header.h":
+    pass
diff --git a/tests/testcython/my_header.h b/tests/testcython/my_header.h
new file mode 100644
index 0000000..10540f9
--- /dev/null
+++ b/tests/testcython/my_header.h
@@ -0,0 +1,1 @@
+#define MY_HEADER 1