Lines Matching +full:local +full:- +full:pid

1 --
2 -- Copyright (c) 2023 Kyle Evans <kevans@FreeBSD.org>
3 --
4 -- SPDX-License-Identifier: BSD-2-Clause
5 --
7 local libgen = require('posix.libgen')
8 local lfs = require('lfs')
9 local stdlib = require('posix.stdlib')
10 local unistd = require('posix.unistd')
11 local sys_wait = require('posix.sys.wait')
13 local curdate = os.date("%B %e, %Y")
15 local output_head <const> = ".\\\" DO NOT EDIT-- this file is @" .. [[generated by tools/build/opti…
55 may be necessary if the system-wide settings are not suitable
87 .Pa /etc/src-env.conf .
94 as they are environment-only variables.
111 .Bl -tag -width indent
114 local output_tail <const> = [[.El
116 .Bl -tag -compact -width Pa
118 .It Pa /etc/src-env.conf
136 local scriptdir <const> = libgen.dirname(stdlib.realpath(arg[0]))
137 local srcdir <const> = stdlib.realpath(scriptdir .. "/../../../")
138 local makesysdir <const> = srcdir .. "/share/mk"
140 local make_envvar = os.getenv("MAKE")
141 local make_cmd_override = {}
148 -- Lifted from bsdinstall/scripts/pkgbase.in (read_all)
149 local function read_pipe(pipe)
150 local ret = ""
152 local buffer = assert(unistd.read(pipe, 1024))
157 local function run_make(args)
158 local cmd_args = {"env", "-i", "make", "-C", srcdir, "-m", makesysdir,
164 local val = make_cmd_override[k]
166 table.insert(cmd_args, 3 + (k - 1), val)
173 local r, w = assert(unistd.pipe())
174 local pid = assert(unistd.fork())
175 if pid == 0 then
176 -- Child
184 -- Parent
187 local output = read_pipe(r)
190 local _, exit_type, exit_code = assert(sys_wait.wait(pid))
196 local function native_target()
197 local output = run_make({"MK_AUTO_OBJ=NO", "-V", "MACHINE",
198 "-V", "MACHINE_ARCH"})
200 local arch, machine_arch
212 local function src_targets()
213 local targets = {}
216 local output = run_make({"MK_AUTO_OBJ=no", "targets"})
217 local curline = 0
222 local arch = line:match("[^%s]+/[^%s]+")
224 -- Make sure we don't roll over our default arch
234 local function config_options(srcconf, env, take_dupes, linting)
238 local option_args = {".MAKE.MODE=normal", "showconfig",
245 local output = run_make(option_args)
247 local options = {}
248 local known_dupes = {}
250 local function warn_on_dupe(option, val)
264 local name = opt:match("MK_[%a%d_]+")
265 local val = opt:match("= .+"):sub(3)
267 -- Some settings, e.g., MK_INIT_ALL_ZERO, may end up
268 -- output twice for some reason that I haven't dug into;
269 -- take the first value. In some circumstances, though,
270 -- we do make an exception and actually want to take the
271 -- latest.
279 local name = opt:match("OPT_[%a%d_]+")
280 local val = opt:match("= .+"):sub(3)
282 -- Multi-value options will arbitrarily use a table here
283 -- to indicate the difference.
296 local function env_only_options()
297 local output = run_make({"MK_AUTO_OBJ=no", "-V", "__ENV_ONLY_OPTIONS"})
298 local options = {}
307 local function required_options()
308 local output = run_make({"-f", "share/mk/src.opts.mk", "-V",
310 local options = {}
319 local function config_description(option_name)
320 local fh = io.open(scriptdir .. "/" .. option_name)
321 local desc
337 local function config_descriptions(options)
338 local desc = {}
341 local basename = name:gsub("^MK_", "")
342 local with_name = "WITH_" .. basename
343 local without_name = "WITHOUT_" .. basename
348 local basename = name:gsub("^OPT_", "")
356 local function dependent_options(tmpdir, option_name, all_opts, omit_others)
357 local opt_sense = not not option_name:match("^WITH_")
358 local base_option_name = option_name:gsub("^[^_]+_", "")
359 local prefix = (opt_sense and "WITHOUT_") or "WITH_"
361 local srcconf = tmpdir .. "/src-" ..prefix .. "ALL_" ..
363 local fh = assert(io.open(srcconf, "w+"))
368 local base_opt = opt:gsub("^MK_", "")
371 local opt_prefix = (value and "WITH_") or "WITHOUT_"
378 local option_name_key = "MK_" .. base_option_name
379 local options = config_options(srcconf, nil, omit_others)
384 -- Strip out multi-option values at the moment, they do
385 -- not really make sense.
393 local function export_option_table(fd, name, options)
402 local function all_dependent_options(tmpdir, options, default_opts,
404 local all_enforced_options = {}
405 local all_effect_options = {}
406 local children = {}
409 local rfd, wfd = assert(unistd.pipe())
410 local pid = assert(unistd.fork())
412 if pid == 0 then
413 -- We need to pcall() this so that errors bubble up to
414 -- our _exit() call rather than the main exit.
415 local ret, errobj = pcall(function()
418 local compare_table
425 -- List of knobs forced on by this one
426 local enforced_options = dependent_options(tmpdir, name,
428 -- List of knobs implied by this by one (once additionally
429 -- filtered based on enforced_options values)
430 local effect_options = dependent_options(tmpdir, name,
450 children[pid] = {name, rfd}
455 local pid, status, exitcode = sys_wait.wait(-1)
461 local info = children[pid]
462 children[pid] = nil
464 local name = info[1]
465 local rfd = info[2]
466 local buf = ''
467 local rbuf, sz
469 -- Drain the pipe
479 error("Child " .. pid .. " failed, buf: " .. buf)
482 -- The child has written a pair of tables named enforced_options
483 -- and effect_options to the pipe. We'll load the pipe buffer
484 -- as a string and then yank these out of the clean environment
485 -- that we execute the chunk in.
486 local child_env = {}
487 local res, err = pcall(load(buf, "child", "t", child_env))
497 local function get_defaults(target_archs, native_default_opts)
498 local target_defaults = {}
499 -- Set of options with differing defaults in some archs
500 local different_defaults = {}
504 local native_copy = {}
512 local target = tgt:gsub("/.+$", "")
513 local target_arch = tgt:gsub("^.+/", "")
515 local target_opts = config_options(nil, {"TARGET=" .. target,
537 local val = opts["MK_ACPI"]
540 print(" - " .. tgt .. ": " .. ((val and "yes") or "no"))
547 local function option_comparator(lhs, rhs)
548 -- Convert both options to the base name, compare that instead unless
549 -- they're the same option. For the same option, we just want to get
550 -- ordering between WITH_/WITHOUT_ correct.
551 local base_lhs = lhs:gsub("^[^_]+_", "")
552 local base_rhs = rhs:gsub("^[^_]+_", "")
561 local function main(tmpdir)
565 local env_only_opts <const> = env_only_options()
566 local default_opts = config_options(nil, nil, nil, true)
567 local opt_descriptions = config_descriptions(default_opts)
568 local srcconf_all <const> = tmpdir .. "/src-all-enabled.conf"
569 local fh = io.open(srcconf_all, "w+")
570 local all_targets = src_targets()
571 local target_defaults, different_defaults = get_defaults(all_targets,
573 local options = {}
574 local without_all_opts = {}
578 local base_name = name:gsub("^MK_", "")
579 local with_name = "WITH_" .. base_name
580 local without_name = "WITHOUT_" .. base_name
581 -- If it's differently defaulted on some architectures,
582 -- we'll split it into WITH_/WITHOUT_ just to simplify
583 -- some later bits.
602 local with_all_opts = config_options(srcconf_all)
603 local all_enforced_options, all_effect_options
604 local all_required_options = required_options()
612 local value
618 local describe_option = name
622 -- Normalize name to MK_ for indexing into various other
623 -- arrays
634 local enforced_options = all_enforced_options[describe_option]
635 local effect_options = all_effect_options[describe_option]
641 local which_targets = {}
651 if idx < #which_targets - 1 then
653 elseif idx == #which_targets - 1 then
660 -- Unset any implied options that are actually required.
669 .Bl -item -compact]])
671 local sorted_dep_opt = {}
678 local dep_val = enforced_options[dep_opt]
679 local dep_prefix = (dep_val and "WITH_") or
681 local dep_name = dep_opt:gsub("^MK_",
692 -- Remove any options that were previously
693 -- noted as enforced...
700 -- ... and this could leave us with an empty
701 -- set.
711 .Bl -inset -compact]])
713 local sorted_dep_opt = {}
720 local dep_val = effect_options[dep_opt]
721 local dep_prefix = (dep_val and "WITH_") or
723 local not_dep_prefix = ((not dep_val) and "WITH_") or
725 local dep_name = dep_opt:gsub("^MK_",
727 local not_dep_name = dep_opt:gsub("^MK_",
743 .Pa /etc/src-env.conf ,
752 .Bl -tag -width indent]])
755 local desc = opt_descriptions[name]
769 local tmpdir = "/tmp/makeman." .. unistd.getpid()
775 -- Catch any errors so that we can properly clean up, then re-throw it.
776 local ret, errobj = pcall(main, tmpdir)