commit: b4ced98b9dd28062a7990592b7723b8916448679
parent 677859db25f2b0e3dd88d7636219dc0dd9a43ac0
Author: Michael Forney <mforney@mforney.org>
Date: Mon, 22 Jun 2020 11:57:42 -0700
Generate root.perms from fspec
Diffstat:
5 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/gen.lua b/gen.lua
@@ -18,6 +18,9 @@ subgen 'probe'
subgen 'pkg'
subgen 'src'
+build('awk', '$outdir/root.perms', {'$outdir/root.fspec', '|', '$basedir/scripts/perms.awk'}, {
+ expr='-f $basedir/scripts/perms.awk',
+})
gitfile('.perms', '644', '$outdir/root.perms')
build('gitinit', '$builddir/root.stamp')
diff --git a/ninja.lua b/ninja.lua
@@ -435,9 +435,6 @@ function gitfile(path, mode, src)
args=perm,
})
table.insert(pkg.inputs.index, out)
- if mode ~= '0644' and mode ~= '0755' then
- table.insert(pkg.perms, perm)
- end
end
function file(path, mode, src)
@@ -458,12 +455,10 @@ function dir(path, mode)
if pkg.gendir:hasprefix('pkg/') and not fs(pkg.name, path) then
return
end
- mode = ('%04o'):format(tonumber(mode, 8))
pkg.fspec[path] = {
type='dir',
- mode=mode,
+ mode=('%04o'):format(tonumber(mode, 8)),
}
- table.insert(pkg.perms, ('04%s %s'):format(mode, path))
end
function sym(path, target)
diff --git a/rules.ninja b/rules.ninja
@@ -72,10 +72,6 @@ rule copy
rule cat
command = cat $in >$out
-rule mergeperms
- command = sort -k 2 -m $in >$out
- description = PERMS $out
-
rule gzip
command = gzip -c -9 -n <$in >$out
description = GZIP $out
diff --git a/scripts/perms.awk b/scripts/perms.awk
@@ -0,0 +1,23 @@
+BEGIN {
+ RS = ""
+ sort = "sort -k 2"
+}
+
+function mode() {
+ for (i = 2; i <= NF; ++i) {
+ if ($i ~ /^mode=/)
+ return substr($i, 6)
+ }
+ printf "file '%s' is missing mode attribute\n", $1 >"/proc/self/fd/2"
+ exit(1)
+}
+
+/type=dir/ {
+ printf "04%s %s\n", mode(), substr($1, 2) |sort
+}
+
+/type=reg/ {
+ m = mode()
+ if (m != "0644" && m != "0755")
+ printf "10%s %s\n", m, substr($1, 2) |sort
+}
diff --git a/setup.lua b/setup.lua
@@ -33,7 +33,6 @@ local function gen(gendir)
srcdir=dir..'/src',
outdir=outdir,
inputs={
- perms={},
index={},
fspec={implicit={}},
gen={
@@ -45,7 +44,6 @@ local function gen(gendir)
ninja={'$gendir/local.ninja'},
fetch={},
},
- perms={},
fspec={},
}
assert(os.execute(('exec mkdir -p %s %s'):format(gendir, outdir)))
@@ -76,16 +74,6 @@ local function gen(gendir)
phony('deps', pkg.deps)
end
- if next(pkg.perms) then
- table.sort(pkg.perms, function(s1, s2)
- return s1:sub(8) < s2:sub(8)
- end)
- local f = assert(io.open(outdir..'/local.perms', 'w'))
- f:write(table.concat(pkg.perms, '\n'))
- f:write('\n')
- table.insert(pkg.inputs.perms, '$outdir/local.perms')
- f:close()
- end
if next(pkg.fspec) then
local out = outdir..'/local.fspec'
local tmp = out..'.tmp'
@@ -109,11 +97,6 @@ local function gen(gendir)
end
table.insert(pkg.inputs.fspec, '$outdir/local.fspec')
end
- if next(pkg.inputs.perms) then
- build('mergeperms', '$outdir/root.perms', pkg.inputs.perms)
- else
- build('empty', '$outdir/root.perms')
- end
if next(pkg.inputs.index) then
build('cat', '$outdir/root.index', pkg.inputs.index, {
description=' INDEX $outdir/root.index',
@@ -144,7 +127,6 @@ function subgen(dir)
subninja(file)
table.insert(pkg.inputs.ninja, '$gendir/'..dir..'/ninja')
table.insert(pkg.inputs.index, '$outdir/'..dir..'/root.index')
- table.insert(pkg.inputs.perms, '$outdir/'..dir..'/root.perms')
table.insert(pkg.inputs.fspec, '$outdir/'..dir..'/root.fspec')
local cmd = ('exec test -f %s/%s/local.ninja'):format(pkg.gendir, dir)
if recurse or not os.execute(cmd) then