Skip to content

Commit 386f0b1

Browse files
committed
tatt: add support for extra env files
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 59e1438 commit 386f0b1

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

data/share/bash-completion/completions/pkgdev

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ _pkgdev() {
214214
--template-file
215215
--logs-dir
216216
--emerge-opts
217+
--extra-env-file
217218
"
218219

219220
case "${prev}" in
@@ -226,6 +227,16 @@ _pkgdev() {
226227
--logs-dir)
227228
COMPREPLY=($(compgen -d -- "${cur}"))
228229
;;
230+
--extra-env-file)
231+
if [[ -d /etc/portage/env/ ]]; then
232+
pushd /etc/portage/env/ >& /dev/null
233+
local SETS=( * )
234+
COMPREPLY=($(compgen -W "${SETS[*]}" -- "${cur}" ))
235+
popd >& /dev/null
236+
else
237+
COMPREPLY=()
238+
fi
239+
;;
229240
*)
230241
COMPREPLY+=($(compgen -W "${subcmd_options}" -- "${cur}"))
231242
;;

src/pkgdev/scripts/pkgdev_tatt.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@
150150
Options to be passed to emerge invocations. Taken from
151151
``--emerge-opts``.
152152
153+
``extra_env_files``
154+
A list of extra /etc/portage/env/ file names, to be added to
155+
``package.env`` entry when testing the package. Taken from
156+
``--extra-env-file``.
157+
153158
``log_dir``
154159
irectory to save build logs for failing tasks. Taken from
155160
``--logs-dir``.
@@ -172,6 +177,17 @@
172177
to ``emerge`` invocations.
173178
""",
174179
)
180+
template_opts.add_argument(
181+
"--extra-env-file",
182+
default=[],
183+
metavar="ENV_FILE",
184+
action=arghparse.CommaSeparatedValuesAppend,
185+
help="Extra /etc/portage/env/ file names, to be used while testing packages. Can be passed multiple times.",
186+
docs="""
187+
Comma separated filenames under /etc/portage/env/, which will all be
188+
included in the package.env entry when testing the package.
189+
""",
190+
)
175191

176192
portage_config = Path("/etc/portage")
177193
portage_accept_keywords = portage_config / "package.accept_keywords"
@@ -180,6 +196,13 @@
180196
portage_env = portage_config / "env"
181197

182198

199+
@tatt.bind_final_check
200+
def _tatt_validate(parser, namespace):
201+
for filename in namespace.extra_env_file:
202+
if not (env_file := portage_env / filename).exists():
203+
parser.error(f"extra env file '{env_file}' doesn't exist")
204+
205+
183206
@tatt.bind_final_check
184207
def _validate_args(parser, namespace):
185208
if namespace.bug is not None:
@@ -254,7 +277,7 @@ def _groupby_use_expand(
254277
return use_flags, use_expand_dict
255278

256279

257-
def _build_job(namespace, pkg, is_test):
280+
def _build_job(namespace, pkg, is_test: bool):
258281
use_expand_prefixes = tuple(s.lower() + "_" for s in namespace.domain.profile.use_expand)
259282
default_on_iuse = tuple(use[1:] for use in pkg.iuse if use.startswith("+"))
260283
immutable, enabled, _disabled = namespace.domain.get_package_use_unconfigured(pkg)
@@ -373,6 +396,7 @@ def main(options, out, err):
373396
job_name=job_name,
374397
log_dir=options.logs_dir,
375398
emerge_opts=options.emerge_opts,
399+
extra_env_files=options.extra_env_file,
376400
cleanup_files=cleanup_files,
377401
)
378402
with open(script_name := job_name + ".sh", "w") as output:

src/pkgdev/tatt/template.sh.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ tatt_test_pkg() {
102102
printf "%s pkgdev_tatt_{{ job_name }}_no_test\n" "${1:?}" > "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
103103
local TFEATURES="${FEATURES}"
104104
fi
105+
{% for env in extra_env_files %}
106+
printf "%s {{env}}\n" "${1}" >> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
107+
{% endfor %}
105108
106109
printf "%s %s\n" "${1:?}" "${TUSE}" > "/etc/portage/package.use/pkgdev_tatt_{{ job_name }}/${CP}"
107110

0 commit comments

Comments
 (0)