build.bqn: proper rule object

This commit is contained in:
dzaima 2023-01-25 05:47:34 +02:00
parent 6baa96c1e3
commit f637fa7746

View File

@ -315,42 +315,36 @@ updateSubmodule ← {
# gets/creates a directory of cacheable objects; key is the unique identifier of when it can be reused
GetCache { 𝕊 basenamedesckey:
hash Hash key
folder allObjDir•file.At basename"-"hash
folderHash Hash key
folder allObjDir•file.At basename"-"folderHash
MkDir AtRoot folder
File folder•file.At
{𝕊: desc": "AtRoot𝕩} _verboseLog folder
dataPath AtRoot File "data"
prevKsprevVs •file.Exists, {Deserialize 8'c',8•bit._cast •FBytes 𝕩} dataPath
dataVersion 0
prevKsprevVs {ab: adataVersion? b; } •file.Exists@, {Deserialize 8'c',8•bit._cast •FBytes 𝕩} dataPath
IsUpToDate { 𝕊:
i prevKs<𝕩
i prevKs<𝕩.cacheKey
i<prevKs?
{@:0; ´ AtRootIsFileTheSame´¨𝕩} iprevVs;
0
}
newKsnewVs
Update {key𝕊data: newKs <key newVs <data} # data≡@ means failed to build
onExitList {{ 𝕊:
finalNewData @
FinalData { 𝕊:
finalNewData@?finalNewData;
jKs newKsprevKs
jVs newVsprevVs
dataPath •FBytes 8,8'c'•bit._cast Serialize (<jKs) /¨ jKsjVs
}{𝕊: 0newKs}}
finalNewData Serialize dataVersion (<jKs) /¨ jKsjVs
}
Update {key𝕊data: !finalNewData@ newKs <key newVs <data} # data≡@ means failed to build
onExitList {{𝕊: dataPath •FBytes 8,8'c'•bit._cast FinalData@}{𝕊: 0newKs}}
}
ruleKsruleVs
AddRule { 𝕊 cachecacheKeydstGetCMDdispcustomDeps:
ruleKs <dst
ruleVs {
cache cache
cacheKey cacheKey
disp disp
CMD GetCMD
ruleDeps customDeps
}
}
# dependency resolution & thread management
Run { 𝕊:
@ -370,7 +364,7 @@ Run ← { 𝕊:
chr Require¨ chi
rebuild ´ chr
# rebuild↩ ¬•file.Exists AtRoot 𝕩⊑ruleKs # not really needed unless someone deletes a specific file without deleting the data file
rebuild ¬v.cache.IsUpToDate v.cacheKey
rebuild ¬v.cache.IsUpToDate v
{
ruleN (+´chr)+(𝕩)
ruleP 𝕩¨((chr/chi))
@ -471,33 +465,45 @@ Run ← { 𝕊:
}
AddRule { 𝕊 cachecacheKeydstGetCMDdispdeps:
ruleKs <dst
res {
dst dst
cache cache
cacheKey cacheKey
disp disp
CMD GetCMD
ruleDeps {𝕩.dst}¨ deps
}
ruleVs res
res
}
MakeCCInv { 𝕊 GetArgsInitcacheidsrccustomDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths
key id
dst cache.File key".o"
dst cache.File id".o"
GetCMD { 𝕊:
Init @
dep AtRoot cache.File id".d"
"sh", rootDir, (GetArgs@)"-MT", "o", "-MMD", "-MF", dep, "-o", AtRoot dst, "-c", src, dep
}
AddRule cache, key, dst, GetCMD, •file.Name src, customDeps
AddRule cache, id, dst, GetCMD, •file.Name src, customDeps
}
MakeSingeliInv { 𝕊 argsInitcacheidsrccustomDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths
key id
dst cache.File key".c"
dst cache.File id".c"
GetCMD { 𝕊:
Init @
dep AtRoot cache.File id".d"
"singeli", rootDir, AtRoot dst, AtRoot po.singeliDir, args, AtRoot src, dep
}
AddRule cache, key, dst, GetCMD, •file.Name src, customDeps
AddRule cache, id, dst, GetCMD, •file.Name src, customDeps
}
MakeLinkerInv { 𝕊 GetArgscachenamesrcs:
dst cache.File name
dst cache.File name
GetCMD { 𝕊:
args GetArgs@
"sh", rootDir, args, "-o", dstsrcs1args, @
"sh", rootDir, args, "-o", dst({𝕩.dst}¨ srcs)1args, @
}
AddRule cache, name, dst, GetCMD, "link", srcs
}
@ -530,7 +536,7 @@ cachedBin‿linkerCache ← {
replxxCache GetCache "replxx", "REPLXX object file location", po.REPLXXc@
replxxSrc (po.replxxDir•file.At"src")•file.At¨"ConvertUTF.cpp", "wcwidth.cpp", "conversion.cxx", "escape.cxx", "history.cxx", "prompt.cxx", "replxx.cxx", "replxx_impl.cxx", "terminal.cxx", "util.cxx", "windows.cxx"
objs {𝕩.dst}¨ (Shorten replxxSrc) {MakeCCInv po.REPLXXc, , replxxCache, 𝕨, 𝕩, }¨ replxxSrc
objs (Shorten replxxSrc) {MakeCCInv po.REPLXXc, , replxxCache, 𝕨, 𝕩, }¨ replxxSrc
replxxCache
}
@ -544,7 +550,7 @@ cachedBin‿linkerCache ← {
ga "src/singeli/src/genArithTables.bqn"
gaDefs singeliCache.File "arDefs.singeli"
gaTables singeliCache.File "arTables.c"
AddRule
gaRule AddRule
singeliCache, "genArithTables",
gaDefs, # am cheating and only using arDefs.singeli as destination; ¯\_(ツ)_/¯
{𝕊: "runbqn", rootdir, AtRoot ga, AtRoot¨ gaDefsgaTables, ga},
@ -555,31 +561,26 @@ cachedBin‿linkerCache ← {
po.native? ;
"-a" {"x86-64":"X86_64"; "aarch64":"AARCH64"} po.arch
}
singeliObjs {𝕩.dst}¨ {MakeSingeliInv singeliArgs, {𝕊:UpdateSubmodule po.singeliDir}, singeliCache, 𝕩, "src/singeli/src/"•file.At 𝕩".singeli", (𝕩"dyarith")/gaDefs}¨ 1¨singeliMap
singeliObjs {MakeSingeliInv singeliArgs, {𝕊:UpdateSubmodule po.singeliDir}, singeliCache, 𝕩, "src/singeli/src/"•file.At 𝕩".singeli", (𝕩"dyarith")/gaRule}¨ 1¨singeliMap
singeliCache
}
cbqnCache {
cbqnCache GetCache "cbqn", "CBQN object file location", po.CBQNc@, {po.singeli? singeliCache.hash; @}
cbqnCache GetCache "cbqn", "CBQN object file location", po.CBQNc@, {po.singeli? singeliCache.folderHash; @}
ruleDeps {
¬po.singeli? ¨ cbqnSrc;
((cbqnSrc) ˜ cbqnSrc¨singeliMap) singeliObjs
}
singeliArgs {po.singeli? "-DSINGELI_DIR="•file.Name singeliCache.folder; }
objs {𝕩.dst}¨ {abc: MakeCCInv po.CBQNcsingeliArgs˙, {𝕊:UpdateSubmodule po.bytecodeDir UpdateSubmodule po.replxxDir}, cbqnCache, a, b, c}¨ <˘[Shorten cbqnSrc, cbqnSrc, ruleDeps] # updates replxx because needs replxx.h
objs {abc: MakeCCInv po.CBQNcsingeliArgs˙, {𝕊:UpdateSubmodule po.bytecodeDir UpdateSubmodule po.replxxDir}, cbqnCache, a, b, c}¨ <˘[Shorten cbqnSrc, cbqnSrc, ruleDeps] # updates replxx because needs replxx.h
cbqnCache
}
linkerCache GetCache "linker", "linker cached result location",
po.Linker@,
cbqnCache.hash,
{po.replxx? replxxCache.hash; @}
{po.singeli? singeliCache.hash; @}
linkerDeps @¨/ cbqnCache, replxxCache, singeliCache
linkerCache GetCache "linker", "linker cached result location", po.Linker@, {𝕩.folderHash}¨ linkerDeps
{
po.versionName@? @;
srcFile linkerCache.File "versionInfo.c"
@ -592,7 +593,7 @@ cachedBin‿linkerCache ← {
•file.Exists AtRoot srcFile? src•FChars AtRoot srcFile? @; # don't update
(AtRoot srcFile) •FChars src
}
objs (MakeCCInv po.CBQNc, , linkerCache, "versionInfo", srcFile, ).dst
objs MakeCCInv po.CBQNc, , linkerCache, "versionInfo", srcFile,
}
res MakeLinkerInv po.Linker, linkerCache, {po.emcc? "BQN.js"; "windows"po.os? "res.exe"; "res"}, objs