Use relative path when possible

This commit is contained in:
Sleepy Monax 2023-11-21 14:38:02 +01:00
parent 69aa190d9e
commit 8838340e7d
2 changed files with 13 additions and 13 deletions

View file

@ -203,8 +203,10 @@ def build(
all = False all = False
shell.mkdir(target.builddir) shell.mkdir(target.builddir)
ninjaPath = os.path.join(target.builddir, "build.ninja") ninjaPath = os.path.join(target.builddir, "build.ninja")
with open(ninjaPath, "w") as f:
gen(f, target, registry) if not os.path.exists(ninjaPath):
with open(ninjaPath, "w") as f:
gen(f, target, registry)
if components is None: if components is None:
all = True all = True
@ -228,10 +230,9 @@ def build(
) )
outs = list(map(lambda p: str(p.path), products)) outs = list(map(lambda p: str(p.path), products))
if all:
shell.exec("ninja", "-f", ninjaPath) shell.exec("ninja", "-f", ninjaPath, *(outs if not all else []))
else:
shell.exec("ninja", "-f", ninjaPath, *outs)
return products return products

View file

@ -71,7 +71,7 @@ class Manifest(DataClassJsonMixin):
""" """
Return the directory of the manifest Return the directory of the manifest
""" """
return os.path.dirname(self.path) return os.path.relpath(os.path.dirname(self.path), Path.cwd())
def subpath(self, path) -> Path: def subpath(self, path) -> Path:
return Path(self.dirname()) / path return Path(self.dirname()) / path
@ -121,19 +121,18 @@ class Project(Manifest):
@staticmethod @staticmethod
def ensure() -> "Project": def ensure() -> "Project":
"""
Ensure that a project exists in the current directory or any parent directory
and chdir to the root of the project.
"""
project = Project.topmost() project = Project.topmost()
if project is None: if project is None:
raise RuntimeError( raise RuntimeError(
"No project found in this directory or any parent directory" "No project found in this directory or any parent directory"
) )
os.chdir(project.dirname())
return project return project
def chdir(self):
"""
Change the current working directory to the root of the project
"""
os.chdir(self.dirname())
@staticmethod @staticmethod
def at(path: Path) -> Optional["Project"]: def at(path: Path) -> Optional["Project"]:
projectManifest = Manifest.tryLoad(path / "project") projectManifest = Manifest.tryLoad(path / "project")