Added simple downloading of dependencies.

This commit is contained in:
Sleepy Monax 2023-02-17 20:30:27 +01:00
parent e8beacf559
commit c5f66d6c9b
5 changed files with 82 additions and 2 deletions

View file

@ -166,6 +166,22 @@ def graphCmd(args: Args):
cmds += [Cmd("g", "graph", "Show dependency graph", graphCmd)]
def installCmd(args: Args):
project = context.loadProject(".")
for extSpec in project.extern:
ext = project.extern[extSpec]
extPath = f"{const.EXTERN_DIR}/{extSpec}"
print(f"Installing {extSpec}-{ext.tag} from {ext.git}...")
shell.popen("git", "clone", "--depth", "1", "--branch",
ext.tag, ext.git, extPath)
cmds += [Cmd("i", "install", "Install all the external packages", installCmd)]
def usage():
print(f"Usage: {const.ARGV0} <command> [args...]")

View file

@ -7,6 +7,7 @@ ARGV0 = os.path.basename(sys.argv[0])
OSDK_DIR = ".osdk"
BUILD_DIR = f"{OSDK_DIR}/build"
CACHE_DIR = f"{OSDK_DIR}/cache"
EXTERN_DIR = f"{OSDK_DIR}/extern"
SRC_DIR = "src/"
META_DIR = f"meta"
TARGETS_DIR = f"{META_DIR}/targets"

View file

@ -1,8 +1,9 @@
from typing import cast, Protocol, Iterable
from pathlib import Path
import os
from osdk.model import TargetManifest, ComponentManifest, Props, Type, Tool, Tools
from osdk.model import ProjectManifest, TargetManifest, ComponentManifest, Props, Type, Tool, Tools
from osdk.logger import Logger
from osdk import const, shell, jexpr, utils, rules, mixins
@ -106,6 +107,11 @@ def loadAllTargets() -> list[TargetManifest]:
map(lambda path: TargetManifest(jexpr.evalRead(path), path), files))
def loadProject(path: str) -> ProjectManifest:
path = os.path.join(path, "project.json")
return ProjectManifest(jexpr.evalRead(path), path)
def loadTarget(id: str) -> TargetManifest:
try:
return next(filter(lambda t: t.id == id, loadAllTargets()))
@ -115,6 +121,8 @@ def loadTarget(id: str) -> TargetManifest:
def loadAllComponents() -> list[ComponentManifest]:
files = shell.find(const.SRC_DIR, ["manifest.json"])
files += shell.find(const.EXTERN_DIR, ["manifest.json"])
return list(
map(
lambda path: ComponentManifest(jexpr.evalRead(path), path),

View file

@ -15,6 +15,7 @@ Props = dict[str, Any]
class Type(Enum):
UNKNOWN = "unknown"
PROJECT = "project"
TARGET = "target"
LIB = "lib"
EXE = "exe"
@ -54,6 +55,59 @@ class Manifest:
return os.path.dirname(self.path)
class Extern:
git: str = ""
tag: str = ""
def __init__(self, json: Json = None, strict=True, **kwargs):
if json is not None:
if not "git" in json and strict:
raise ValueError("Missing git")
self.git = json["git"]
if not "tag" in json and strict:
raise ValueError("Missing tag")
self.tag = json["tag"]
elif strict:
raise ValueError("Missing json")
for key in kwargs:
setattr(self, key, kwargs[key])
def __str__(self):
return f"Extern(git={self.git}, tag={self.tag})"
def __repr__(self):
return f"Extern({self.git})"
class ProjectManifest(Manifest):
description: str = ""
extern: dict[str, Extern] = {}
def __init__(self, json: Json = None, path: str = "", strict=True, **kwargs):
if json is not None:
if not "description" in json and strict:
raise ValueError("Missing description")
self.description = json["description"]
self.extern = {k: Extern(v)
for k, v in json.get("extern", {}).items()}
elif strict:
raise ValueError("Missing json")
super().__init__(json, path, strict, **kwargs)
def __str__(self):
return f"ProjectManifest(id={self.id}, type={self.type}, path={self.path}, description={self.description}, extern={self.extern})"
def __repr__(self):
return f"ProjectManifest({self.id})"
class Tool:
cmd: str = ""
args: list[str] = []

View file

@ -1,4 +1,5 @@
import os
import sys
import hashlib
import errno
import subprocess
@ -140,7 +141,7 @@ def popen(*args: str) -> str:
logger.log(f"Executing {args}")
try:
proc = subprocess.run(args, stdout=subprocess.PIPE)
proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=sys.stderr)
except FileNotFoundError:
raise Exception(f"Command not found")