Files
space-station-14/BuildChecker/git_helper.py
Pieter-Jan Briers 787330f5c6 v269.0.0 RT update - .NET 10 (#41855)
* Make ServerPackaging automatically get extra server assemblies

* Make the switch

* Use Content.Server.deps.json instead

* Remove debug

* Rewrite

Now recursively fetches dependencies from Content.Server

Only copies dependencies not covered by Robust

This removes the need to manually specify most of the dependencies, even the content ones!

Also look at runtime key properly to figure out the proper dll name.

This actually removes some assemblies that were duplicated between the main directory and assemblies (various Microsoft.Extensions stuff)

* Fix test compile errors when updating dependencies

Ran across this while updating dependencies on the RT .NET 10 update. Should be fine to merge immediately.

* More .NET 10 prep

* Convert to SLNX

Hell yeah

* slnx now has size-2 indents

* Update SLNX with new RT system

* Remove reference to RT test in toolshed test

* Remove accidental usage of transitive RT dependencies

* Move Robust project references to RobustApi

* Update solution file

* Fix warnings in pow3r

* Fix nullable warnings in integration tests

idk where these came from

* gitignore binlog files

* Fix transitive dependency warnings in Content.Benchmarks

* Update slnx

* Okay, the Robust API thing didn't pan out. New plan.

It apparently broke clean builds, as the dependencies aren't in the project asset list or something anymore. I tried to fix this, but it seems impossible to do without relying on .NET SDK internals, as there's no point in the NuGet graph walk process that seems cleanly extensible.

Instead let's just do the much dumber thing: a bunch of .props files for content to import. Hooray!

This also means that I have to go through and *explicitly* disable transitive dependencies everywhere in RT. This thankfully isn't too hard.

* Update RT to 269.0.0

* One last solution update

* Fix more data definition issues

* Update RT to 269.0.1

* Fix it again

---------

Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
2025-12-22 01:24:24 +00:00

124 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Installs git hooks, updates them, updates submodules, that kind of thing.
"""
import os
import shutil
import subprocess
import sys
import time
from pathlib import Path
from typing import List
SOLUTION_PATH = Path("..") / "SpaceStation14.slnx"
# If this doesn't match the saved version we overwrite them all.
CURRENT_HOOKS_VERSION = "4"
QUIET = len(sys.argv) == 2 and sys.argv[1] == "--quiet"
def run_command(command: List[str], capture: bool = False) -> subprocess.CompletedProcess:
"""
Runs a command with pretty output.
"""
text = ' '.join(command)
if not QUIET:
print("$ {}".format(text))
sys.stdout.flush()
if capture:
completed = subprocess.run(command, stdout=subprocess.PIPE, text=True)
else:
completed = subprocess.run(command)
if completed.returncode != 0:
print("Error: command exited with code {}!".format(completed.returncode))
return completed
def update_submodules():
"""
Updates all submodules.
"""
if 'GITHUB_ACTIONS' in os.environ:
return
if os.path.isfile("DISABLE_SUBMODULE_AUTOUPDATE"):
return
if shutil.which("git") is None:
raise FileNotFoundError("git not found in PATH")
# If the status doesn't match, force VS to reload the solution.
# status = run_command(["git", "submodule", "status"], capture=True)
run_command(["git", "submodule", "update", "--init", "--recursive"])
# status2 = run_command(["git", "submodule", "status"], capture=True)
# Something changed.
# if status.stdout != status2.stdout:
# print("Git submodules changed. Reloading solution.")
# reset_solution()
def install_hooks():
"""
Installs the necessary git hooks into .git/hooks.
"""
# Read version file.
if os.path.isfile("INSTALLED_HOOKS_VERSION"):
with open("INSTALLED_HOOKS_VERSION", "r") as f:
if f.read() == CURRENT_HOOKS_VERSION:
if not QUIET:
print("No hooks change detected.")
return
print("Hooks need updating.")
hooks_target_dir = Path(run_command(["git", "rev-parse", "--git-path", "hooks"], True).stdout.strip())
hooks_source_dir = Path("hooks")
# Clear entire tree since we need to kill deleted files too.
for filename in os.listdir(hooks_target_dir):
os.remove(hooks_target_dir / filename)
for filename in os.listdir(hooks_source_dir):
print("Copying hook {}".format(filename))
shutil.copy2(hooks_source_dir / filename, hooks_target_dir / filename)
with open("INSTALLED_HOOKS_VERSION", "w") as f:
f.write(CURRENT_HOOKS_VERSION)
def reset_solution():
"""
Force VS to think the solution has been changed to prompt the user to reload it, thus fixing any load errors.
"""
with SOLUTION_PATH.open("r") as f:
content = f.read()
with SOLUTION_PATH.open("w") as f:
f.write(content)
def check_for_zip_download():
# Check if .git exists,
if run_command(["git", "rev-parse"]).returncode != 0:
print("It appears that you downloaded this repository directly from GitHub. (Using the .zip download option) \n"
"When downloading straight from GitHub, it leaves out important information that git needs to function. "
"Such as information to download the engine or even the ability to even be able to create contributions. \n"
"Please read and follow https://docs.spacestation14.com/en/general-development/setup/setting-up-a-development-environment.html \n"
"If you just want a Sandbox Server, you are following the wrong guide! You can download a premade server following the instructions here:"
"https://docs.spacestation14.com/en/general-development/setup/server-hosting-tutorial.html \n"
"Closing automatically in 30 seconds.")
time.sleep(30)
exit(1)
if __name__ == '__main__':
check_for_zip_download()
install_hooks()
update_submodules()