public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/tatt/, src/pkgdev/scripts/
@ 2023-12-08 10:01 Arthur Zamarin
  0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2023-12-08 10:01 UTC (permalink / raw
  To: gentoo-commits

commit:     59e14388da6f62ce854a2335afaeffdc31c81e9c
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Thu Dec  7 20:29:51 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Dec  8 08:16:05 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=59e14388

tatt: pass configuration to specific package and not all env

Resolves: https://github.com/pkgcore/pkgdev/issues/149
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgdev/scripts/pkgdev_tatt.py | 63 +++++++++++++++++++++++++++------------
 src/pkgdev/tatt/template.sh.jinja | 37 ++++++++++++++---------
 2 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/src/pkgdev/scripts/pkgdev_tatt.py b/src/pkgdev/scripts/pkgdev_tatt.py
index e3bec63..16b2bc6 100644
--- a/src/pkgdev/scripts/pkgdev_tatt.py
+++ b/src/pkgdev/scripts/pkgdev_tatt.py
@@ -173,7 +173,11 @@ template_opts.add_argument(
     """,
 )
 
-accept_keywords = Path("/etc/portage/package.accept_keywords")
+portage_config = Path("/etc/portage")
+portage_accept_keywords = portage_config / "package.accept_keywords"
+portage_package_use = portage_config / "package.use"
+portage_package_env = portage_config / "package.env"
+portage_env = portage_config / "env"
 
 
 @tatt.bind_final_check
@@ -232,8 +236,9 @@ def _groupby_use_expand(
     use_expand_prefixes: tuple[str, ...],
     domain_enabled: frozenset[str],
     iuse: frozenset[str],
-) -> dict[str, set[str]]:
-    use_expand_dict = defaultdict(set)
+):
+    use_expand_dict: dict[str, set[str]] = defaultdict(set)
+    use_flags: set[str] = set()
     for var, state in assignment.items():
         if var not in iuse:
             continue
@@ -245,8 +250,8 @@ def _groupby_use_expand(
                     use_expand_dict[use_expand[:-1]].add(var.removeprefix(use_expand))
                 break
         else:
-            use_expand_dict["USE"].add(("" if state else "-") + var)
-    return use_expand_dict
+            use_flags.add(("" if state else "-") + var)
+    return use_flags, use_expand_dict
 
 
 def _build_job(namespace, pkg, is_test):
@@ -286,11 +291,9 @@ def _build_job(namespace, pkg, is_test):
         frozenset(prefer_true),
     )
     for solution in solutions:
-        yield " ".join(
-            f'{var.upper()}="{" ".join(vals)}"'
-            for var, vals in _groupby_use_expand(
-                solution, use_expand_prefixes, enabled, iuse
-            ).items()
+        use_flags, use_expand = _groupby_use_expand(solution, use_expand_prefixes, enabled, iuse)
+        yield " ".join(use_flags) + " " + " ".join(
+            f'{var.upper()}: {" ".join(vals)}' for var, vals in use_expand.items()
         )
 
 
@@ -303,16 +306,37 @@ def _build_jobs(namespace, pkgs):
             yield pkg.versioned_atom, False, flags
 
 
+def _create_config_dir(directory: Path):
+    if not directory.exists():
+        directory.mkdir(parents=True)
+    elif not directory.is_dir():
+        raise NotADirectoryError(f"{directory} is not a directory")
+
+
 def _create_config_files(pkgs, job_name, is_keywording):
-    if not accept_keywords.exists():
-        accept_keywords.mkdir(parents=True)
-    elif not accept_keywords.is_dir():
-        raise NotADirectoryError(f"{accept_keywords} is not a directory")
-    with (res := accept_keywords / f"pkgdev_tatt_{job_name}.keywords").open("w") as f:
+    _create_config_dir(portage_accept_keywords)
+    with (res := portage_accept_keywords / f"pkgdev_tatt_{job_name}.keywords").open("w") as f:
         f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
         for pkg in pkgs:
             f.write(f'{pkg.versioned_atom} {"**" if is_keywording else ""}\n')
-    return str(res)
+    yield str(res)
+
+    _create_config_dir(portage_env)
+    with (res := portage_env / f"pkgdev_tatt_{job_name}_no_test").open("w") as f:
+        f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
+        f.write('FEATURES="qa-unresolved-soname-deps multilib-strict"\n')
+    yield str(res)
+    with (res := portage_env / f"pkgdev_tatt_{job_name}_test").open("w") as f:
+        f.write(f"# Job created by pkgdev tatt for {job_name!r}\n")
+        f.write('FEATURES="qa-unresolved-soname-deps multilib-strict test"\n')
+    yield str(res)
+
+    _create_config_dir(portage_package_use)
+    (res := portage_package_use / f"pkgdev_tatt_{job_name}").mkdir(exist_ok=True)
+    yield str(res)
+    _create_config_dir(portage_package_env)
+    (res := portage_package_env / f"pkgdev_tatt_{job_name}").mkdir(exist_ok=True)
+    yield str(res)
 
 
 @tatt.bind_main_func
@@ -329,9 +353,9 @@ def main(options, out, err):
     cleanup_files = []
 
     try:
-        config_file = _create_config_files(pkgs, job_name, options.keywording)
-        out.write("created config ", out.fg("green"), config_file, out.reset)
-        cleanup_files.append(config_file)
+        for config_file in _create_config_files(pkgs, job_name, options.keywording):
+            out.write("created config ", out.fg("green"), config_file, out.reset)
+            cleanup_files.append(config_file)
     except Exception as exc:
         err.error(f"failed to create config files: {exc}")
 
@@ -346,6 +370,7 @@ def main(options, out, err):
     script = Template(template, trim_blocks=True, lstrip_blocks=True).render(
         jobs=list(_build_jobs(options, pkgs)),
         report_file=job_name + ".report",
+        job_name=job_name,
         log_dir=options.logs_dir,
         emerge_opts=options.emerge_opts,
         cleanup_files=cleanup_files,

diff --git a/src/pkgdev/tatt/template.sh.jinja b/src/pkgdev/tatt/template.sh.jinja
index 7a43043..1123822 100644
--- a/src/pkgdev/tatt/template.sh.jinja
+++ b/src/pkgdev/tatt/template.sh.jinja
@@ -22,9 +22,9 @@ main() {
 
     {% for atom, is_test, use_flags in jobs %}
     {% if is_test %}
-    {{ use_flags }} tatt_test_pkg --test '{{ atom }}' || test_ret=1
+    TUSE="{{ use_flags }}" tatt_test_pkg '{{ atom }}' --test || test_ret=1
     {% else %}
-    {{ use_flags }} tatt_test_pkg '{{ atom }}' || test_ret=1
+    TUSE="{{ use_flags }}" tatt_test_pkg '{{ atom }}' || test_ret=1
     {% endif %}
     {% endfor %}
 
@@ -34,7 +34,7 @@ main() {
 cleanup() {
     echo "Cleaning up"
     {% for file in cleanup_files %}
-    rm -v -f '{{ file }}'
+    rm -v -f -r '{{ file }}'
     {% endfor %}
     rm -v -f $0
 }
@@ -44,8 +44,8 @@ tatt_pkg_error() {
 
     echo "${eout}"
 
-    if [[ -n ${USE} ]]; then
-        echo -n "USE='${USE}'" >> "{{ report_file }}"
+    if [[ -n ${TUSE} ]]; then
+        echo -n "USE='${TUSE}'" >> "{{ report_file }}"
     fi
     if [[ -n ${FEATURES} ]]; then
         echo -n " FEATURES='${FEATURES}'" >> "{{ report_file }}"
@@ -71,7 +71,7 @@ tatt_pkg_error() {
     if [[ -s ${BUILDLOG} ]]; then
         mkdir -p {{ log_dir }}
         local LOGNAME=$(mktemp -p {{ log_dir }} "${CP/\//_}_use_XXXXX")
-        mv "${BUILDLOG}" "${LOGNAME}"
+        cp "${BUILDLOG}" "${LOGNAME}"
         echo "    log has been saved as ${LOGNAME}" >> "{{ report_file }}"
         TESTLOGS=($(find ${BUILDDIR}/work -iname '*test*log*'))
 {% raw %}
@@ -84,32 +84,41 @@ tatt_pkg_error() {
 }
 
 tatt_test_pkg() {
-    if [[ ${1:?} == "--test" ]]; then
-        shift
+    local CP=${1#=}
+    CP=${CP/\//_}
 
+    if [[ ${2} == "--test" ]]; then
         # Do a first pass to avoid circular dependencies
         # --onlydeps should mean we're avoiding (too much) duplicate work
-        USE="${USE} minimal -doc" emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"
+        USE="minimal -doc" emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"
 
         if ! emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"; then
             echo "merging test dependencies of ${1} failed" >> "{{ report_file }}"
             return 1
         fi
-        TFEATURES="${FEATURES} test"
+        printf "%s pkgdev_tatt_{{ job_name }}_test\n" "${1:?}"> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
+        local TFEATURES="${FEATURES} test"
     else
-        TFEATURES="${FEATURES}"
+        printf "%s pkgdev_tatt_{{ job_name }}_no_test\n" "${1:?}" > "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
+        local TFEATURES="${FEATURES}"
     fi
 
+    printf "%s %s\n" "${1:?}" "${TUSE}" > "/etc/portage/package.use/pkgdev_tatt_{{ job_name }}/${CP}"
+
     # --usepkg-exclude needs the package name, so let's extract it
     # from the atom we have
     local name=$(portageq pquery "${1:?}" -n)
 
-    eout=$( FEATURES="${TFEATURES}" emerge -1 --getbinpkg=n --usepkg-exclude="${name}" {{ emerge_opts }} "${1:?}" 2>&1 1>/dev/tty )
-    if [[ $? == 0 ]] ; then
+    eout=$( emerge -1 --getbinpkg=n --usepkg-exclude="${name}" {{ emerge_opts }} "${1:?}" 2>&1 1>/dev/tty )
+    local RES=$?
+
+    rm -v -f /etc/portage/package.{env,use}/pkgdev_tatt_{{ job_name }}/${CP}
+
+    if [[ ${RES} == 0 ]] ; then
         if [[ -n ${TFEATURES} ]]; then
             echo -n "FEATURES='${TFEATURES}' " >> "{{ report_file }}"
         fi
-        echo "USE='${USE}' succeeded for ${1:?}" >> "{{ report_file }}"
+        echo "USE='${TUSE}' succeeded for ${1:?}" >> "{{ report_file }}"
     else
         FEATURES="${TFEATURES}" tatt_pkg_error "${1:?}" "${eout}"
         return 1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-08 10:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-08 10:01 [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/tatt/, src/pkgdev/scripts/ Arthur Zamarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox