Skip to content

Commit

Permalink
Merge pull request #266 from SpaceWarpDev/dev
Browse files Browse the repository at this point in the history
Update Nuget packing for 1.5
  • Loading branch information
cheese3660 authored Oct 24, 2023
2 parents 693451a + 7dcf12b commit fdd046d
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 49 deletions.
26 changes: 26 additions & 0 deletions SpaceWarp.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>SpaceWarp</id>
<version>1.5.1</version>
<authors>SpaceWarp contributors</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.githubusercontent.com/SpaceWarp/SpaceWarp/main/LICENSE</licenseUrl>
<description>A C# modding API for KSP2</description>
<tags>spacewarp ksp2 modding</tags>
<icon>icon.png</icon>
<projectUrl>https://spacewarp.org</projectUrl>
<repository type="git" url="https://github.com/SpaceWarpDev/SpaceWarp" />
<readme>README.md</readme>
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
<files>
<file src=".github\README.md" target="README.md" />
<file src="images\icon.png" target="icon.png" />
<file src="LICENSE" target="LICENSE" />
<file src="build\nuget_temp\*.dll" target="lib/netstandard2.0/" />
<file src="build\nuget_temp\*.xml" target="lib/netstandard2.0/" />
</files>
</package>
26 changes: 0 additions & 26 deletions SpaceWarp/SpaceWarp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,4 @@
<IncludeAssets>SpaceWarpPatcher.dll</IncludeAssets>
</ProjectReference>
</ItemGroup>

<!-- Nuget packaging configuration -->
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Space Warp contributors</Authors>
<Description>A C# modding API for KSP2 built on top of BepInEx</Description>
<PackageIcon>icon.png</PackageIcon>
<PackageId>SpaceWarp</PackageId>
<PackageLicenseUrl>https://raw.githubusercontent.com/SpaceWarpDev/SpaceWarp/main/LICENSE</PackageLicenseUrl>
<PackageOutputPath>..\build</PackageOutputPath>
<PackageProjectUrl>https://spacewarp.org</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>SpaceWarp;KSP2;modding</PackageTags>
<RepositoryUrl>https://github.com/SpaceWarpDev/SpaceWarp</RepositoryUrl>
<Title>Space Warp</Title>
<NoWarn>$(NoWarn),NU5118,NU5125</NoWarn>
</PropertyGroup>

<Target Name="IncludeAllFilesInTargetDir" AfterTargets="Build">
<ItemGroup>
<None Include="..\images\icon.png" Pack="true" PackagePath="\" />
<None Include="..\LICENSE" Pack="true" PackagePath="\" />
<None Include="..\.github\README.md" Pack="true" PackagePath="\" />
<None Include="$(TargetDir)\**" Pack="true" PackagePath="lib\$(TargetFramework)" />
</ItemGroup>
</Target>
</Project>
117 changes: 94 additions & 23 deletions builder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import argparse
from ast import mod
import os
import platform
import shutil
import subprocess
import zipfile


TEMPLATE_DIR = os.path.abspath("SpaceWarpBuildTemplate")
SPACEWARP_DIR = os.path.abspath("SpaceWarp")
SPACEWARP_CORE_DIR = os.path.abspath("SpaceWarp.Core")
Expand All @@ -14,8 +13,7 @@
BUILD_DIR = os.path.abspath("build")
THIRD_PARTY = os.path.abspath("ThirdParty")

MODULES = ["Game","Sound","UI","VersionChecking","Messaging"]

MODULES = ["Game", "Sound", "UI", "VersionChecking", "Messaging"]

parser = argparse.ArgumentParser()
parser.add_argument("-r", "--release", help="Build a release version", action="store_true")
Expand All @@ -40,14 +38,18 @@ def clean():


def build(release=False):
dotnet_args = ["dotnet", "build", os.path.join(SPACEWARP_DIR,"SpaceWarp.csproj"), "-c", "Release" if release else "Debug"]
dotnet_core_args = ["dotnet", "build", os.path.join(SPACEWARP_CORE_DIR,"SpaceWarp.Core.csproj"), "-c", "Release" if release else "Debug"]
dotnet_args = ["dotnet", "build", os.path.join(SPACEWARP_DIR, "SpaceWarp.csproj"), "-c",
"Release" if release else "Debug"]
dotnet_core_args = ["dotnet", "build", os.path.join(SPACEWARP_CORE_DIR, "SpaceWarp.Core.csproj"), "-c",
"Release" if release else "Debug"]
build_output_dir = os.path.join(SPACEWARP_DIR, "bin", "Release" if release else "Debug")
build_output_dir_core = os.path.join(SPACEWARP_CORE_DIR, "bin", "Release" if release else "Debug")
output_dir = os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp")
nuget_temp_dir = os.path.join(BUILD_DIR, "nuget_temp")
# copy over the internals of the template
print("=> Creating build directory...")
os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp"), True)
os.makedirs(nuget_temp_dir, True)
print("=> Copying BepInEx")
os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins"), True)
os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "patchers", "SpaceWarp"), True)
Expand All @@ -74,7 +76,7 @@ def build(release=False):

for line in str(output.stderr, "utf-8").splitlines():
print(f" {line}")

print(f"=> Executing: {' '.join(dotnet_core_args)}")

output = subprocess.run(args=dotnet_core_args, capture_output=True)
Expand All @@ -88,14 +90,14 @@ def build(release=False):
for line in str(output.stderr, "utf-8").splitlines():
print(f" {line}")

print("=> Compiling Modules")
os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp","modules"), True)
print("=> Compiling Modules")
os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp", "modules"), True)
for module in MODULES:
path = os.path.abspath("SpaceWarp." +module)
csproj = os.path.join(path,"SpaceWarp."+module+".csproj")
path = os.path.abspath("SpaceWarp." + module)
csproj = os.path.join(path, "SpaceWarp." + module + ".csproj")
module_args = ["dotnet", "build", csproj, "-c", "Release" if release else "Debug"]
module_build_output_dir = os.path.join(path,"bin","Release" if release else "Debug")
module_output_dir = os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp","modules")
module_build_output_dir = os.path.join(path, "bin", "Release" if release else "Debug")
module_output_dir = os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp", "modules")

print(f"=> Executing: {' '.join(module_args)}")

Expand All @@ -111,17 +113,24 @@ def build(release=False):
print(f" {line}")

print("=> Copying module")

def shutil_copy_module(file):
shutil.copyfile(os.path.join(module_build_output_dir, file), os.path.join(module_output_dir, file))
if not release and os.path.exists(os.path.join(module_build_output_dir,"SpaceWarp."+module+".pdb")):
shutil_copy_module("SpaceWarp."+module+".pdb")
shutil_copy_module("SpaceWarp."+module+".dll")


def shutil_copy_nuget_module(file):
shutil.copyfile(os.path.join(module_build_output_dir, file), os.path.join(nuget_temp_dir, file))

if not release and os.path.exists(os.path.join(module_build_output_dir, "SpaceWarp." + module + ".pdb")):
shutil_copy_module("SpaceWarp." + module + ".pdb")

shutil_copy_module("SpaceWarp." + module + ".dll")
shutil_copy_nuget_module("SpaceWarp." + module + ".dll")
shutil_copy_nuget_module("SpaceWarp." + module + ".xml")

# patcher libraries
patcher_library_dir = os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "patchers", "SpaceWarp", "lib")
print(f"=> Copying Patcher Libraries")
shutil.copytree(PATCHER_LIB_DIR,patcher_library_dir)
shutil.copytree(PATCHER_LIB_DIR, patcher_library_dir)

# patcher build
patcher_dotnet_args = ["dotnet", "build", os.path.join(PATCHER_DIR, "SpaceWarpPatcher.csproj"), "-c",
Expand All @@ -146,20 +155,78 @@ def shutil_copy_module(file):

def shutil_copy(file):
shutil.copyfile(os.path.join(build_output_dir, file), os.path.join(output_dir, file))

def shutil_copy_core(file):
shutil.copyfile(os.path.join(build_output_dir_core, file), os.path.join(output_dir, file))

def shutil_copy_patcher(file):
shutil.copyfile(os.path.join(patcher_build_output_dir, file), os.path.join(patcher_output_dir, file))

if not release and os.path.exists(os.path.join(build_output_dir_core,"SpaceWarp.Core.pdb")):
def shutil_nuget_copy(file):
shutil.copyfile(os.path.join(build_output_dir, file), os.path.join(nuget_temp_dir, file))

def shutil_nuget_copy_core(file):
shutil.copyfile(os.path.join(build_output_dir_core, file), os.path.join(nuget_temp_dir, file))

def shutil_nuget_copy_patcher(file):
shutil.copyfile(os.path.join(patcher_build_output_dir, file), os.path.join(nuget_temp_dir, file))

if not release and os.path.exists(os.path.join(build_output_dir_core, "SpaceWarp.Core.pdb")):
shutil_copy_core("SpaceWarp.Core.pdb")
if not release and os.path.exists(os.path.join(build_output_dir, "SpaceWarp.pdb")):
shutil_copy("SpaceWarp.pdb")
if not release and os.path.exists(os.path.join(patcher_build_output_dir, "SpaceWarpPatcher.pdb")):
shutil_copy_patcher("SpaceWarpPatcher.pdb")

shutil_copy("SpaceWarp.dll")
shutil_copy_patcher("SpaceWarpPatcher.dll")
shutil_nuget_copy("SpaceWarp.dll")
shutil_nuget_copy("SpaceWarp.xml")

shutil_copy_core("SpaceWarp.Core.dll")
shutil_nuget_copy_core("SpaceWarp.Core.dll")
shutil_nuget_copy_core("SpaceWarp.Core.xml")

shutil_copy_patcher("SpaceWarpPatcher.dll")
shutil_nuget_copy_patcher("SpaceWarpPatcher.dll")
shutil_nuget_copy_patcher("SpaceWarpPatcher.xml")


def get_console_encoding():
command = 'powershell -command "[Console]::OutputEncoding.WebName"'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
encoding_name = result.stdout.strip()
return encoding_name
else:
raise RuntimeError(f'Failed to get console encoding: {result.stderr}')


def nuget_pack():
if platform.system() == "Windows":
nuget_args = [
"nuget",
"pack",
os.path.abspath("SpaceWarp.nuspec"),
"-OutputDirectory",
BUILD_DIR
]
command_str = subprocess.list2cmdline(nuget_args)
print(f"=> Executing: {command_str}")

encoding = get_console_encoding()

output = subprocess.run(args=command_str, capture_output=True)
print(" |=>| STDOUT")

for line in str(output.stdout, encoding).splitlines():
print(f" {line}")

print(" |=>| STDERR")

for line in str(output.stderr, encoding).splitlines():
print(f" {line}")

shutil.rmtree(os.path.join(BUILD_DIR, "nuget_temp"))


def create_zip_name(prefix):
Expand All @@ -185,7 +252,7 @@ def compress(release=False):

def main():
args = parser.parse_args()
total_steps = 3
total_steps = 4
print(f"====> [1/{total_steps}] Cleaning...")

clean()
Expand All @@ -194,7 +261,11 @@ def main():

build(args.release)

print(f"====> [3/{total_steps}] Compressing...")
print(f"====> [3/{total_steps}] Packing NuGet...")

nuget_pack()

print(f"====> [4/{total_steps}] Compressing...")

compress(args.release)

Expand Down

0 comments on commit fdd046d

Please sign in to comment.