Skip to content

Commit 532581d

Browse files
committed
Make post build into a shell script, allowing cross-platform compatibility
Just requires sh to be installed on Windows. Relies on $PDB2MDB to find the pdb2mdb executable, and $KSPDIR to find where to copy to. If either of these are absent, it will be ignored (but the build will still work)
1 parent 97a1968 commit 532581d

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

ModuleManager/ModuleManager.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@
136136
</ItemGroup>
137137
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
138138
<PropertyGroup>
139-
<PostBuildEvent>echo copying to "%25KSPDIR%25\GameData\"
140-
"C:\Games\Tools\pdb2mdb\pdb2mdb.exe" $(TargetFileName)
141-
xcopy /Y "$(TargetPath)" "C:\Games\ksp-win_dev\GameData\"
142-
xcopy /Y "$(TargetDir)$(TargetName).pdb" "C:\Games\ksp-win_dev\GameData\"
143-
xcopy /Y "$(TargetDir)$(TargetName).dll.mdb" "C:\Games\ksp-win_dev\GameData\"
144-
del "C:\Games\ksp-win_dev\GameData\ModuleManager.ConfigCache"</PostBuildEvent>
139+
<PostBuildEvent>sh -c "TARGET_PATH='$(TargetPath)' TARGET_DIR='$(TargetDir)' TARGET_NAME='$(TargetName)' sh '$(ProjectDir)/copy_build.sh'"</PostBuildEvent>
145140
</PropertyGroup>
146141
</Project>

ModuleManager/copy_build.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
if [ -z "${TARGET_PATH}" ] ; then
2+
echo 'Expected $TARGET_PATH to be defined but it is not' >&2
3+
exit 1
4+
elif ! [ -f "${TARGET_PATH}" ] ; then
5+
echo 'Expected $TARGET_PATH to be a file but it is not' >&2
6+
exit 1
7+
fi
8+
9+
if [ -z "${TARGET_DIR}" ] ; then
10+
echo 'Expected $TARGET_DIR to be defined but it is not' >&2
11+
exit 1
12+
elif ! [ -d "${TARGET_DIR}" ] ; then
13+
echo 'Expected $TARGET_DIR to be a directory but it is not' >&2
14+
exit 1
15+
fi
16+
17+
if [ -z "${TARGET_NAME}" ] ; then
18+
echo 'Expected $TARGET_NAME to be defined but it is not' >&2
19+
exit 1
20+
fi
21+
22+
if [ -z "${PDB2MDB}" ] ; then
23+
echo '$PDB2MDB not found'
24+
else
25+
echo "Running '${PDB2MDB}'"
26+
"${PDB2MDB}" "${TARGET_PATH}"
27+
fi
28+
29+
if [ -z "${KSPDIR}" ] ; then
30+
echo '$KSPDIR not found'
31+
else
32+
if ! [ -d "${KSPDIR}" ] ; then
33+
echo 'Expected $KSPDIR to point to a directory but it is not' >&2
34+
exit 1
35+
fi
36+
if ! [ -d "${KSPDIR}/GameData" ] ; then
37+
echo 'Expected $KSPDIR to contain a GameData subdirectory but it does not' >&2
38+
exit 1
39+
fi
40+
echo "Copying to '${KSPDIR}'"
41+
cp "${TARGET_PATH}" "${KSPDIR}/GameData/"
42+
test -f "${TARGET_DIR}/${TARGET_NAME}.pdb" && cp "${TARGET_DIR}/${TARGET_NAME}.pdb" "${KSPDIR}/GameData/"
43+
test -f "${TARGET_DIR}/${TARGET_NAME}.dll.mdb" && cp "${TARGET_DIR}/${TARGET_NAME}.dll.mdb" "${KSPDIR}/GameData/"
44+
rm -f "${KSPDIR}/GameData/ModuleManager.ConfigCache"
45+
fi

0 commit comments

Comments
 (0)