diff options
author | Ross Burton <ross.burton@arm.com> | 2024-11-14 16:33:03 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-11-18 22:09:03 +0000 |
commit | c6b9484fb384df9ef5fd7edbc4f0794f09cbaeb8 (patch) | |
tree | 69abd2524cc1a1ed69aa77efbcccb0759587d36c | |
parent | 906e8291ebe4d4b774b1dcace0c8e71037e0f54b (diff) | |
download | poky-c6b9484fb384df9ef5fd7edbc4f0794f09cbaeb8.tar.gz |
sstate: rewrite sstate_archive_package in python
As sstate_archive_package just calls tar, writing the function in shell
is actually more complex and opaque than the equivalent python.
Don't check for zstd vs pzstd, we have pzstd in HOSTTOOLS so it will
always be available.
(From OE-Core rev: c9ac5d9d94f254292cf3cafdf273dd6b61d3baa7)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes-global/sstate.bbclass | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/meta/classes-global/sstate.bbclass b/meta/classes-global/sstate.bbclass index 8e0391c666..decfb5adef 100644 --- a/meta/classes-global/sstate.bbclass +++ b/meta/classes-global/sstate.bbclass | |||
@@ -844,8 +844,7 @@ python sstate_create_and_sign_package () { | |||
844 | from tempfile import TemporaryDirectory | 844 | from tempfile import TemporaryDirectory |
845 | with TemporaryDirectory(dir=sstate_pkg.parent) as tmp_dir: | 845 | with TemporaryDirectory(dir=sstate_pkg.parent) as tmp_dir: |
846 | tmp_pkg = Path(tmp_dir) / sstate_pkg.name | 846 | tmp_pkg = Path(tmp_dir) / sstate_pkg.name |
847 | d.setVar("TMP_SSTATE_PKG", str(tmp_pkg)) | 847 | sstate_archive_package(tmp_pkg, d) |
848 | bb.build.exec_func('sstate_archive_package', d) | ||
849 | 848 | ||
850 | from oe.gpg_sign import get_signer | 849 | from oe.gpg_sign import get_signer |
851 | signer = get_signer(d, 'local') | 850 | signer = get_signer(d, 'local') |
@@ -865,8 +864,7 @@ python sstate_create_and_sign_package () { | |||
865 | from tempfile import NamedTemporaryFile | 864 | from tempfile import NamedTemporaryFile |
866 | with NamedTemporaryFile(prefix=sstate_pkg.name, dir=sstate_pkg.parent) as tmp_pkg_fd: | 865 | with NamedTemporaryFile(prefix=sstate_pkg.name, dir=sstate_pkg.parent) as tmp_pkg_fd: |
867 | tmp_pkg = tmp_pkg_fd.name | 866 | tmp_pkg = tmp_pkg_fd.name |
868 | d.setVar("TMP_SSTATE_PKG", str(tmp_pkg)) | 867 | sstate_archive_package(tmp_pkg, d) |
869 | bb.build.exec_func('sstate_archive_package',d) | ||
870 | update_file(tmp_pkg, sstate_pkg) | 868 | update_file(tmp_pkg, sstate_pkg) |
871 | # update_file() may have renamed tmp_pkg, which must exist when the | 869 | # update_file() may have renamed tmp_pkg, which must exist when the |
872 | # NamedTemporaryFile() context handler ends. | 870 | # NamedTemporaryFile() context handler ends. |
@@ -874,32 +872,33 @@ python sstate_create_and_sign_package () { | |||
874 | 872 | ||
875 | } | 873 | } |
876 | 874 | ||
877 | # Shell function to generate a sstate package from a directory | 875 | # Function to generate a sstate package from the current directory. |
878 | # set as SSTATE_BUILDDIR. Will be run from within SSTATE_BUILDDIR. | ||
879 | # The calling function handles moving the sstate package into the final | 876 | # The calling function handles moving the sstate package into the final |
880 | # destination. | 877 | # destination. |
881 | sstate_archive_package () { | 878 | def sstate_archive_package(sstate_pkg, d): |
882 | OPT="-cS" | 879 | import subprocess |
883 | ZSTD="zstd -${SSTATE_ZSTD_CLEVEL} -T${ZSTD_THREADS}" | ||
884 | # Use pzstd if available | ||
885 | if [ -x "$(command -v pzstd)" ]; then | ||
886 | ZSTD="pzstd -${SSTATE_ZSTD_CLEVEL} -p ${ZSTD_THREADS}" | ||
887 | fi | ||
888 | 880 | ||
889 | # Need to handle empty directories | 881 | cmd = [ |
890 | if [ "$(ls -A)" ]; then | 882 | "tar", |
891 | set +e | 883 | "-I", d.expand("pzstd -${SSTATE_ZSTD_CLEVEL} -p${ZSTD_THREADS}"), |
892 | tar -I "$ZSTD" $OPT -f ${TMP_SSTATE_PKG} * | 884 | "-cS", |
893 | ret=$? | 885 | "-f", sstate_pkg, |
894 | if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then | 886 | ] |
895 | exit 1 | 887 | |
896 | fi | 888 | # tar refuses to create an empty archive unless told explicitly |
897 | set -e | 889 | files = sorted(os.listdir(".")) |
898 | else | 890 | if not files: |
899 | tar -I "$ZSTD" $OPT --file=${TMP_SSTATE_PKG} --files-from=/dev/null | 891 | files = ["--files-from=/dev/null"] |
900 | fi | 892 | |
901 | chmod 0664 ${TMP_SSTATE_PKG} | 893 | try: |
902 | } | 894 | subprocess.run(cmd + files, check=True) |
895 | except subprocess.CalledProcessError as e: | ||
896 | # Ignore error 1 as this is caused by files changing | ||
897 | # (link count increasing from hardlinks being created). | ||
898 | if e.returncode != 1: | ||
899 | raise | ||
900 | |||
901 | os.chmod(sstate_pkg, 0o664) | ||
903 | 902 | ||
904 | 903 | ||
905 | python sstate_report_unihash() { | 904 | python sstate_report_unihash() { |