Files
RedScarfEngine/prepare_env.py
T
Piotr Krygier a82550d414 Addded depenendency load tool
Added simple python script that will load needed libraries into
the project folder structure. Most libraries are now not needed to be
present in development system.
2023-08-07 13:48:30 +02:00

79 lines
2.6 KiB
Python

#!/usr/bin/python
# !WARNING! When run, this script will create prepare.lock file, which will indicate that the script has been run before.
# This is used for automation with CMake, which will run this script if and only if this file does not exists.
# If you want to run this script again, remove this file manually first.
# Script used for preparing build envirionment. I cannot use submodules, because I cannot specify commit/tag
# in submodule config. What's more, preparing vulkan SDK is complicated, so a custom scrip is needed for that.
import io
import re
import git
import os
import requests
import subprocess
REPO_DIR = os.path.join(os.getcwd(), "third_party")
class Dependency:
def __init__(self, name, file: io.TextIOWrapper):
self.name = name
while 1:
line = file.readline().split("=", 1)
if len(line) > 1:
match line[0].strip():
case "git_url":
self.git_url = line[1].strip()
case "dl_url":
self.dl_url = line[1].strip()
case "tag":
self.tag = line[1].strip()
case "custom_commands":
self.custom_commands = line[1].strip()
else:
break
def download(self):
# Git repository
if hasattr(self, "git_url") and self.git_url:
repo = git.Repo.clone_from(self.git_url, os.path.join(REPO_DIR, self.name))
repo.git.checkout(self.tag)
elif hasattr(self, "dl_url") and self.dl_url:
response = requests.get(self.dl_url)
if response.status_code == 200: # everything went fine
open(os.path.join(REPO_DIR, self.name), "wb").write(response.content)
if hasattr(self, "custom_commands") and self.custom_commands:
p = subprocess.Popen(self.custom_commands, shell=True)
def main():
if not os.path.isdir(REPO_DIR):
os.mkdir(REPO_DIR)
f = open("dependencies.dep", "r")
os.chdir(REPO_DIR)
while True:
line = f.readline()
if not line:
break
stripped = line.strip()
# Remove comments
if stripped.startswith("#"):
return
uncommented = stripped.split("#", 1)[0]
if len(uncommented) == 0:
return
if uncommented.startswith("["):
dep_name = re.search('\[(.*)\]', uncommented).group(1)
dep = Dependency(dep_name, f)
dep.download()
f.close()
if __name__ == "__main__":
main()