diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2023-12-07 22:29:51 +0200 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-12-08 10:16:05 +0200 |
commit | 59e14388da6f62ce854a2335afaeffdc31c81e9c (patch) | |
tree | 70b30564a8c19d6fb90e36d291b3de3d7b5c5ade | |
parent | start work on 0.2.9 (diff) | |
download | pkgdev-59e14388da6f62ce854a2335afaeffdc31c81e9c.tar.gz pkgdev-59e14388da6f62ce854a2335afaeffdc31c81e9c.tar.bz2 pkgdev-59e14388da6f62ce854a2335afaeffdc31c81e9c.zip |
tatt: pass configuration to specific package and not all env
Resolves: https://github.com/pkgcore/pkgdev/issues/149
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | src/pkgdev/scripts/pkgdev_tatt.py | 63 | ||||
-rw-r--r-- | 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 |