Added devShell to nix flake.

This commit is contained in:
Sleepy Monax 2024-01-28 00:19:19 +01:00
parent 86768ad452
commit 3dcca6591b
4 changed files with 36 additions and 16 deletions

View file

@ -55,7 +55,8 @@ def setupLogger(verbose: bool):
def main() -> int:
try:
shell.mkdir(const.GLOBAL_CK_DIR)
args = cli.parse(sys.argv[1:])
extraArgs = os.environ.get("CK_EXTRA_ARGS", None)
args = cli.parse((extraArgs.split(" ") if extraArgs else []) + sys.argv[1:])
setupLogger(args.consumeOpt("verbose", False) is True)
const.setup()

View file

@ -66,7 +66,7 @@ class ProductScope(ComponentScope):
# --- Variables -------------------------------------------------------------- #
Compute = Callable[[TargetScope], str]
Compute = Callable[[TargetScope], list[str]]
_vars: dict[str, Compute] = {}
@ -79,21 +79,21 @@ def var(name: str) -> Callable[[Compute], Compute]:
@var("builddir")
def _computeBuilddir(scope: TargetScope) -> str:
def _computeBuilddir(scope: TargetScope) -> list[str]:
"""
This variable is needed by ninja to know where to put
the .ninja_log file.
"""
return scope.target.builddir
return [scope.target.builddir]
@var("hashid")
def _computeHashid(scope: TargetScope) -> str:
return scope.target.hashid
def _computeHashid(scope: TargetScope) -> list[str]:
return [scope.target.hashid]
@var("cincs")
def _computeCinc(scope: TargetScope) -> str:
def _computeCinc(scope: TargetScope) -> list[str]:
res = set()
for c in scope.registry.iterEnabled(scope.target):
@ -104,11 +104,11 @@ def _computeCinc(scope: TargetScope) -> str:
elif c.type == model.Kind.LIB:
res.add(str(Path(c.dirname()).parent))
return " ".join(sorted(map(lambda i: f"-I{i}", res)))
return sorted(map(lambda i: f"-I{i}", res))
@var("cdefs")
def _computeCdef(scope: TargetScope) -> str:
def _computeCdef(scope: TargetScope) -> list[str]:
res = set()
def sanatize(s: str) -> str:
@ -125,7 +125,7 @@ def _computeCdef(scope: TargetScope) -> str:
res.add(f"-D__ck_{sanatize(k)}_{sanatize(str(v))}__")
res.add(f"-D__ck_{sanatize(k)}_value={str(v)}")
return " ".join(sorted(res))
return sorted(res)
def buildpath(scope: ComponentScope, path) -> Path:
@ -272,15 +272,27 @@ def all(w: ninja.Writer, scope: TargetScope) -> list[str]:
return all
def applyExtraProps(scope: TargetScope, name: str, var: list[str]) -> list[str]:
target: model.Target = scope.target
extra = target.props.get(f"ck-{name}-extra", None)
if extra:
var += extra.split(" ")
override = target.props.get(f"ck-{name}-override")
if override:
var = override.split(" ")
return var
def gen(out: TextIO, scope: TargetScope):
w = ninja.Writer(out)
target: model.Target = scope.target
w.comment("File generated by the build system, do not edit")
w.newline()
w.separator("Variables")
for name, compute in _vars.items():
w.variable(name, compute(scope))
w.variable(name, applyExtraProps(scope, name, compute(scope)))
w.newline()
w.separator("Tools")
@ -289,7 +301,10 @@ def gen(out: TextIO, scope: TargetScope):
tool = scope.target.tools[i]
rule = rules.rules[i]
w.variable(i, tool.cmd)
w.variable(i + "flags", " ".join(rule.args + tool.args))
w.variable(
i + "flags",
" ".join(applyExtraProps(scope, i + "flags", rule.args + tool.args)),
)
w.rule(
i,
f"{tool.cmd} {(tool.rule or rule.rule).replace('$flags',f'${i}flags')}",

View file

@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1705774713,
"narHash": "sha256-j6ADaDH9XiumUzkTPlFyCBcoWYhO83lfgiSqEJF2zcs=",
"lastModified": 1706098335,
"narHash": "sha256-r3dWjT8P9/Ah5m5ul4WqIWD8muj5F+/gbCdjiNVBKmU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1b64fc1287991a9cce717a01c1973ef86cb1af0b",
"rev": "a77ab169a83a4175169d78684ddd2e54486ac651",
"type": "github"
},
"original": {

View file

@ -25,8 +25,12 @@
graphviz
];
};
in {
in
{
package.ck = ck;
defaultPackage = self.package.${system}.ck;
devShell = pkgs.mkShell {
buildInputs = [ ck ];
};
});
}