add helper for includes

This commit is contained in:
Robin Appelman 2023-07-09 18:22:22 +02:00
commit 06c8e7370f
3 changed files with 30 additions and 11 deletions

View file

@ -40,5 +40,11 @@ buildSourcePawnScript {
};
```
By default the sourcemod includes are available.
By default, the sourcemod includes are available.
Additional includes can be added by setting the `includes` argument to an array of packages containing an `include` folder containing the `.inc` files.
A helper is provided to create include packages:
```nix
sourcepawn.buildInclude [./cURL.inc ./cURL_header.inc]
```

View file

@ -1,7 +1,6 @@
{
lib,
stdenv,
sourcemod-includes,
sourcepawn,
which,
}: {
@ -13,7 +12,7 @@
} @ args: let
inherit (lib) optionals;
inherit (builtins) removeAttrs;
allIncludes = includes ++ optionals defaultIncludes [sourcemod-includes];
allIncludes = includes ++ optionals defaultIncludes [sourcepawn.includes.sourcemod];
forwardAttrs = removeAttrs args ["defaultIncludes" "includes" "entrypoint"];
spEnv = sourcepawn.buildEnv allIncludes;
outPathRelative =

View file

@ -5,8 +5,11 @@
python3Packages,
buildEnv,
writeShellScriptBin,
symlinkJoin
symlinkJoin,
sourcemod-includes,
runCommand,
}: let
inherit (builtins) concatStringsSep substring stringLength;
self = stdenv.mkDerivation rec {
pname = "sourcepawn";
version = "1.11";
@ -41,7 +44,17 @@
cp spcomp/*/spcomp spshell/*/spshell verifier/*/verifier $out/bin
'';
passthru.buildEnv = imports: let
passthru = {
buildInclude = let
fileNameForStorePath = path: substring 44 (stringLength path -44) path;
in files: runCommand "sourcepawn-include" {} ''
mkdir -p $out/include
${concatStringsSep "\n" (map (file: "cp ${file} $out/include/${fileNameForStorePath file}") files)}
'';
includes = {
sourcemod = sourcemod-includes;
};
buildEnv = imports: let
unwrapped = symlinkJoin {
name = "sourcepawn-env-unwrapped";
paths = imports ++ [self];
@ -50,11 +63,12 @@
'';
};
wrapped = writeShellScriptBin "spcomp" "exec -a $0 ${unwrapped}/bin/spcomp.unwrapped $@";
in symlinkJoin {
in
symlinkJoin {
name = "sourcepawn-env";
paths = [unwrapped wrapped];
};
};
};
in
self