Skip to content

Commit 59e1438

Browse files
committed
tatt: pass configuration to specific package and not all env
Resolves: #149 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 02919e1 commit 59e1438

2 files changed

Lines changed: 67 additions & 33 deletions

File tree

src/pkgdev/scripts/pkgdev_tatt.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@
173173
""",
174174
)
175175

176-
accept_keywords = Path("/etc/portage/package.accept_keywords")
176+
portage_config = Path("/etc/portage")
177+
portage_accept_keywords = portage_config / "package.accept_keywords"
178+
portage_package_use = portage_config / "package.use"
179+
portage_package_env = portage_config / "package.env"
180+
portage_env = portage_config / "env"
177181

178182

179183
@tatt.bind_final_check
@@ -232,8 +236,9 @@ def _groupby_use_expand(
232236
use_expand_prefixes: tuple[str, ...],
233237
domain_enabled: frozenset[str],
234238
iuse: frozenset[str],
235-
) -> dict[str, set[str]]:
236-
use_expand_dict = defaultdict(set)
239+
):
240+
use_expand_dict: dict[str, set[str]] = defaultdict(set)
241+
use_flags: set[str] = set()
237242
for var, state in assignment.items():
238243
if var not in iuse:
239244
continue
@@ -245,8 +250,8 @@ def _groupby_use_expand(
245250
use_expand_dict[use_expand[:-1]].add(var.removeprefix(use_expand))
246251
break
247252
else:
248-
use_expand_dict["USE"].add(("" if state else "-") + var)
249-
return use_expand_dict
253+
use_flags.add(("" if state else "-") + var)
254+
return use_flags, use_expand_dict
250255

251256

252257
def _build_job(namespace, pkg, is_test):
@@ -286,11 +291,9 @@ def _build_job(namespace, pkg, is_test):
286291
frozenset(prefer_true),
287292
)
288293
for solution in solutions:
289-
yield " ".join(
290-
f'{var.upper()}="{" ".join(vals)}"'
291-
for var, vals in _groupby_use_expand(
292-
solution, use_expand_prefixes, enabled, iuse
293-
).items()
294+
use_flags, use_expand = _groupby_use_expand(solution, use_expand_prefixes, enabled, iuse)
295+
yield " ".join(use_flags) + " " + " ".join(
296+
f'{var.upper()}: {" ".join(vals)}' for var, vals in use_expand.items()
294297
)
295298

296299

@@ -303,16 +306,37 @@ def _build_jobs(namespace, pkgs):
303306
yield pkg.versioned_atom, False, flags
304307

305308

309+
def _create_config_dir(directory: Path):
310+
if not directory.exists():
311+
directory.mkdir(parents=True)
312+
elif not directory.is_dir():
313+
raise NotADirectoryError(f"{directory} is not a directory")
314+
315+
306316
def _create_config_files(pkgs, job_name, is_keywording):
307-
if not accept_keywords.exists():
308-
accept_keywords.mkdir(parents=True)
309-
elif not accept_keywords.is_dir():
310-
raise NotADirectoryError(f"{accept_keywords} is not a directory")
311-
with (res := accept_keywords / f"pkgdev_tatt_{job_name}.keywords").open("w") as f:
317+
_create_config_dir(portage_accept_keywords)
318+
with (res := portage_accept_keywords / f"pkgdev_tatt_{job_name}.keywords").open("w") as f:
312319
f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
313320
for pkg in pkgs:
314321
f.write(f'{pkg.versioned_atom} {"**" if is_keywording else ""}\n')
315-
return str(res)
322+
yield str(res)
323+
324+
_create_config_dir(portage_env)
325+
with (res := portage_env / f"pkgdev_tatt_{job_name}_no_test").open("w") as f:
326+
f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
327+
f.write('FEATURES="qa-unresolved-soname-deps multilib-strict"\n')
328+
yield str(res)
329+
with (res := portage_env / f"pkgdev_tatt_{job_name}_test").open("w") as f:
330+
f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
331+
f.write('FEATURES="qa-unresolved-soname-deps multilib-strict test"\n')
332+
yield str(res)
333+
334+
_create_config_dir(portage_package_use)
335+
(res := portage_package_use / f"pkgdev_tatt_{job_name}").mkdir(exist_ok=True)
336+
yield str(res)
337+
_create_config_dir(portage_package_env)
338+
(res := portage_package_env / f"pkgdev_tatt_{job_name}").mkdir(exist_ok=True)
339+
yield str(res)
316340

317341

318342
@tatt.bind_main_func
@@ -329,9 +353,9 @@ def main(options, out, err):
329353
cleanup_files = []
330354

331355
try:
332-
config_file = _create_config_files(pkgs, job_name, options.keywording)
333-
out.write("created config ", out.fg("green"), config_file, out.reset)
334-
cleanup_files.append(config_file)
356+
for config_file in _create_config_files(pkgs, job_name, options.keywording):
357+
out.write("created config ", out.fg("green"), config_file, out.reset)
358+
cleanup_files.append(config_file)
335359
except Exception as exc:
336360
err.error(f"failed to create config files: {exc}")
337361

@@ -346,6 +370,7 @@ def main(options, out, err):
346370
script = Template(template, trim_blocks=True, lstrip_blocks=True).render(
347371
jobs=list(_build_jobs(options, pkgs)),
348372
report_file=job_name + ".report",
373+
job_name=job_name,
349374
log_dir=options.logs_dir,
350375
emerge_opts=options.emerge_opts,
351376
cleanup_files=cleanup_files,

src/pkgdev/tatt/template.sh.jinja

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ main() {
2222

2323
{% for atom, is_test, use_flags in jobs %}
2424
{% if is_test %}
25-
{{ use_flags }} tatt_test_pkg --test '{{ atom }}' || test_ret=1
25+
TUSE="{{ use_flags }}" tatt_test_pkg '{{ atom }}' --test || test_ret=1
2626
{% else %}
27-
{{ use_flags }} tatt_test_pkg '{{ atom }}' || test_ret=1
27+
TUSE="{{ use_flags }}" tatt_test_pkg '{{ atom }}' || test_ret=1
2828
{% endif %}
2929
{% endfor %}
3030

@@ -34,7 +34,7 @@ main() {
3434
cleanup() {
3535
echo "Cleaning up"
3636
{% for file in cleanup_files %}
37-
rm -v -f '{{ file }}'
37+
rm -v -f -r '{{ file }}'
3838
{% endfor %}
3939
rm -v -f $0
4040
}
@@ -44,8 +44,8 @@ tatt_pkg_error() {
4444

4545
echo "${eout}"
4646

47-
if [[ -n ${USE} ]]; then
48-
echo -n "USE='${USE}'" >> "{{ report_file }}"
47+
if [[ -n ${TUSE} ]]; then
48+
echo -n "USE='${TUSE}'" >> "{{ report_file }}"
4949
fi
5050
if [[ -n ${FEATURES} ]]; then
5151
echo -n " FEATURES='${FEATURES}'" >> "{{ report_file }}"
@@ -71,7 +71,7 @@ tatt_pkg_error() {
7171
if [[ -s ${BUILDLOG} ]]; then
7272
mkdir -p {{ log_dir }}
7373
local LOGNAME=$(mktemp -p {{ log_dir }} "${CP/\//_}_use_XXXXX")
74-
mv "${BUILDLOG}" "${LOGNAME}"
74+
cp "${BUILDLOG}" "${LOGNAME}"
7575
echo " log has been saved as ${LOGNAME}" >> "{{ report_file }}"
7676
TESTLOGS=($(find ${BUILDDIR}/work -iname '*test*log*'))
7777
{% raw %}
@@ -84,32 +84,41 @@ tatt_pkg_error() {
8484
}
8585
8686
tatt_test_pkg() {
87-
if [[ ${1:?} == "--test" ]]; then
88-
shift
87+
local CP=${1#=}
88+
CP=${CP/\//_}
8989
90+
if [[ ${2} == "--test" ]]; then
9091
# Do a first pass to avoid circular dependencies
9192
# --onlydeps should mean we're avoiding (too much) duplicate work
92-
USE="${USE} minimal -doc" emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"
93+
USE="minimal -doc" emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"
9394
9495
if ! emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"; then
9596
echo "merging test dependencies of ${1} failed" >> "{{ report_file }}"
9697
return 1
9798
fi
98-
TFEATURES="${FEATURES} test"
99+
printf "%s pkgdev_tatt_{{ job_name }}_test\n" "${1:?}"> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
100+
local TFEATURES="${FEATURES} test"
99101
else
100-
TFEATURES="${FEATURES}"
102+
printf "%s pkgdev_tatt_{{ job_name }}_no_test\n" "${1:?}" > "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
103+
local TFEATURES="${FEATURES}"
101104
fi
102105
106+
printf "%s %s\n" "${1:?}" "${TUSE}" > "/etc/portage/package.use/pkgdev_tatt_{{ job_name }}/${CP}"
107+
103108
# --usepkg-exclude needs the package name, so let's extract it
104109
# from the atom we have
105110
local name=$(portageq pquery "${1:?}" -n)
106111
107-
eout=$( FEATURES="${TFEATURES}" emerge -1 --getbinpkg=n --usepkg-exclude="${name}" {{ emerge_opts }} "${1:?}" 2>&1 1>/dev/tty )
108-
if [[ $? == 0 ]] ; then
112+
eout=$( emerge -1 --getbinpkg=n --usepkg-exclude="${name}" {{ emerge_opts }} "${1:?}" 2>&1 1>/dev/tty )
113+
local RES=$?
114+
115+
rm -v -f /etc/portage/package.{env,use}/pkgdev_tatt_{{ job_name }}/${CP}
116+
117+
if [[ ${RES} == 0 ]] ; then
109118
if [[ -n ${TFEATURES} ]]; then
110119
echo -n "FEATURES='${TFEATURES}' " >> "{{ report_file }}"
111120
fi
112-
echo "USE='${USE}' succeeded for ${1:?}" >> "{{ report_file }}"
121+
echo "USE='${TUSE}' succeeded for ${1:?}" >> "{{ report_file }}"
113122
else
114123
FEATURES="${TFEATURES}" tatt_pkg_error "${1:?}" "${eout}"
115124
return 1

0 commit comments

Comments
 (0)