assorted_debian_utils/
buildinfo.rs

1// Copyright 2022 Sebastian Ramacher
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4//! # Representation of buildinfos
5//!
6//! This module provides `Buildinfo` to represent some fields of a `.buildinfo` file.
7
8use std::io::BufRead;
9
10use serde::{Deserialize, Deserializer};
11
12use crate::{architectures::Architecture, utils::WhitespaceListVisitor, version::PackageVersion};
13
14fn deserialize_architecture<'de, D>(deserializer: D) -> Result<Vec<Architecture>, D::Error>
15where
16    D: Deserializer<'de>,
17{
18    deserializer.deserialize_str(WhitespaceListVisitor::<Architecture>::new())
19}
20
21/// A build info
22#[derive(Debug, PartialEq, Eq, Deserialize, Hash)]
23#[serde(rename_all = "PascalCase")]
24pub struct Buildinfo {
25    /// Source package
26    pub source: String,
27    /// Version of the package
28    pub version: PackageVersion,
29    /// Architectures of the build
30    #[serde(deserialize_with = "deserialize_architecture")]
31    pub architecture: Vec<Architecture>,
32}
33
34/// Read buildinfo from a reader
35pub fn from_reader(reader: impl BufRead) -> Result<Buildinfo, rfc822_like::de::Error> {
36    rfc822_like::from_reader(reader)
37}
38
39/// Read buildinfo from a string
40pub fn from_str(data: &str) -> Result<Buildinfo, rfc822_like::de::Error> {
41    rfc822_like::from_str(data)
42}
43
44#[cfg(test)]
45mod test {
46    use crate::{architectures::Architecture, buildinfo::Buildinfo, version::PackageVersion};
47
48    #[test]
49    fn deserialize() {
50        let data = r#"Format: 1.0
51Source: picnic
52Binary: libpicnic-dev libpicnic3 libpicnic3-dbgsym
53Architecture: i386 source
54Version: 3.0.11-1
55Checksums-Md5:
56 4b7826495233d2d3147ccaabead13a36 951 picnic_3.0.11-1.dsc
57 1610e5affd53cf17b64b5727a32a6db9 10180 libpicnic-dev_3.0.11-1_i386.deb
58 8229544cbadbe421e713fc247429b744 727956 libpicnic3-dbgsym_3.0.11-1_i386.deb
59 924c58e34c3ff074850201984493a44d 619732 libpicnic3_3.0.11-1_i386.deb
60Checksums-Sha1:
61 e6cd8381339635aea7f4850105dbbdb5ac33e248 951 picnic_3.0.11-1.dsc
62 d916aa5940e7c88fbe0fa420234c0a78db569c43 10180 libpicnic-dev_3.0.11-1_i386.deb
63 383843942719b1a5fa8cdf2d768a4b1566c80f4d 727956 libpicnic3-dbgsym_3.0.11-1_i386.deb
64 5fabd52dfee1258d2e9ac43f5d8c2f7ba61ca8cb 619732 libpicnic3_3.0.11-1_i386.deb
65Checksums-Sha256:
66 8b2a1969501be49fe11e8e8005bf9a3aac0e073d4c7fd97dcb8bfb6f8c9a222a 951 picnic_3.0.11-1.dsc
67 96ab1c37ca12b0fb28169b79cf4a850ede58ab269abcc36eb6e36a6e66906b47 10180 libpicnic-dev_3.0.11-1_i386.deb
68 d114fe20288c31fd2ac7644e1059fcc145788abff11325e84b0ad982ca486ed6 727956 libpicnic3-dbgsym_3.0.11-1_i386.deb
69 012f9a5a27dabfc72c4d7010406e9635a747b9c4c42bc9554aaecc4c9edd0fee 619732 libpicnic3_3.0.11-1_i386.deb
70Build-Origin: Debian
71Build-Architecture: i386
72Build-Date: Tue, 25 Jan 2022 21:54:55 +0000
73Build-Path: /build/picnic-SQCH61/picnic-3.0.11
74Installed-Build-Depends:
75 autoconf (= 2.71-2),
76 automake (= 1:1.16.5-1.1),
77 autopoint (= 0.21-4),
78 autotools-dev (= 20180224.1+nmu1),
79 base-files (= 12.2),
80 base-passwd (= 3.5.52),
81 bash (= 5.1-6),
82 binutils (= 2.37.90.20220123-1),
83 binutils-common (= 2.37.90.20220123-1),
84 binutils-i686-linux-gnu (= 2.37.90.20220123-1),
85 bsdextrautils (= 2.37.3-1),
86 bsdutils (= 1:2.37.3-1),
87 build-essential (= 12.9),
88 bzip2 (= 1.0.8-5),
89 cmake (= 3.22.1-1+b1),
90 cmake-data (= 3.22.1-1),
91 coreutils (= 8.32-4.1),
92 cpp (= 4:11.2.0-2),
93 cpp-11 (= 11.2.0-14),
94 dash (= 0.5.11+git20210903+057cd650a4ed-3),
95 debconf (= 1.5.79),
96 debhelper (= 13.6),
97 debianutils (= 5.7-0.1),
98 dh-autoreconf (= 20),
99 dh-elpa-helper (= 2.0.10),
100 dh-strip-nondeterminism (= 1.13.0-1),
101 diffutils (= 1:3.7-5),
102 dpkg (= 1.21.1),
103 dpkg-dev (= 1.21.1),
104 dwz (= 0.14-1),
105 emacsen-common (= 3.0.4),
106 file (= 1:5.41-2),
107 findutils (= 4.8.0-1),
108 g++ (= 4:11.2.0-2),
109 g++-11 (= 11.2.0-14),
110 gcc (= 4:11.2.0-2),
111 gcc-11 (= 11.2.0-14),
112 gcc-11-base (= 11.2.0-14),
113 gettext (= 0.21-4),
114 gettext-base (= 0.21-4),
115 grep (= 3.7-1),
116 groff-base (= 1.22.4-8),
117 gzip (= 1.10-4),
118 hostname (= 3.23),
119 init-system-helpers (= 1.61),
120 intltool-debian (= 0.35.0+20060710.5),
121 libacl1 (= 2.3.1-1),
122 libarchive-zip-perl (= 1.68-1),
123 libarchive13 (= 3.5.2-1),
124 libasan6 (= 11.2.0-14),
125 libatomic1 (= 11.2.0-14),
126 libattr1 (= 1:2.5.1-1),
127 libaudit-common (= 1:3.0.6-1),
128 libaudit1 (= 1:3.0.6-1+b1),
129 libbinutils (= 2.37.90.20220123-1),
130 libblkid1 (= 2.37.3-1),
131 libboost-test-dev (= 1.74.0.3),
132 libboost-test1.74-dev (= 1.74.0-14),
133 libboost-test1.74.0 (= 1.74.0-14),
134 libboost1.74-dev (= 1.74.0-14),
135 libbrotli1 (= 1.0.9-2+b3),
136 libbz2-1.0 (= 1.0.8-5),
137 libc-bin (= 2.33-4),
138 libc-dev-bin (= 2.33-4),
139 libc6 (= 2.33-4),
140 libc6-dev (= 2.33-4),
141 libcap-ng0 (= 0.7.9-2.2+b1),
142 libcap2 (= 1:2.44-1),
143 libcc1-0 (= 11.2.0-14),
144 libcom-err2 (= 1.46.5-2),
145 libcrypt-dev (= 1:4.4.27-1.1),
146 libcrypt1 (= 1:4.4.27-1.1),
147 libctf-nobfd0 (= 2.37.90.20220123-1),
148 libctf0 (= 2.37.90.20220123-1),
149 libcurl4 (= 7.81.0-1),
150 libdb5.3 (= 5.3.28+dfsg1-0.8),
151 libdebconfclient0 (= 0.261),
152 libdebhelper-perl (= 13.6),
153 libdpkg-perl (= 1.21.1),
154 libelf1 (= 0.186-1),
155 libexpat1 (= 2.4.3-2),
156 libffi8 (= 3.4.2-4),
157 libfile-stripnondeterminism-perl (= 1.13.0-1),
158 libgcc-11-dev (= 11.2.0-14),
159 libgcc-s1 (= 11.2.0-14),
160 libgcrypt20 (= 1.9.4-5),
161 libgdbm-compat4 (= 1.22-1),
162 libgdbm6 (= 1.22-1),
163 libglib2.0-0 (= 2.70.2-1),
164 libgmp10 (= 2:6.2.1+dfsg-3),
165 libgnutls30 (= 3.7.3-4),
166 libgomp1 (= 11.2.0-14),
167 libgpg-error0 (= 1.43-3),
168 libgssapi-krb5-2 (= 1.18.3-7),
169 libhogweed6 (= 3.7.3-1),
170 libicu67 (= 67.1-7),
171 libidn2-0 (= 2.3.2-2),
172 libisl23 (= 0.24-2),
173 libitm1 (= 11.2.0-14),
174 libjsoncpp25 (= 1.9.5-2),
175 libk5crypto3 (= 1.18.3-7),
176 libkeyutils1 (= 1.6.1-2),
177 libkrb5-3 (= 1.18.3-7),
178 libkrb5support0 (= 1.18.3-7),
179 libldap-2.4-2 (= 2.4.59+dfsg-1),
180 liblz4-1 (= 1.9.3-2),
181 liblzma5 (= 5.2.5-2),
182 libm4ri-0.0.20200125 (= 20200125-1+b1),
183 libm4ri-dev (= 20200125-1+b1),
184 libmagic-mgc (= 1:5.41-2),
185 libmagic1 (= 1:5.41-2),
186 libmount1 (= 2.37.3-1),
187 libmpc3 (= 1.2.1-1),
188 libmpfr6 (= 4.1.0-3),
189 libncurses6 (= 6.3-2),
190 libncursesw6 (= 6.3-2),
191 libnettle8 (= 3.7.3-1),
192 libnghttp2-14 (= 1.43.0-1),
193 libnsl-dev (= 1.3.0-2),
194 libnsl2 (= 1.3.0-2),
195 libp11-kit0 (= 0.24.0-6),
196 libpam-modules (= 1.4.0-11),
197 libpam-modules-bin (= 1.4.0-11),
198 libpam-runtime (= 1.4.0-11),
199 libpam0g (= 1.4.0-11),
200 libpcre2-8-0 (= 10.39-3),
201 libpcre3 (= 2:8.39-13),
202 libperl5.32 (= 5.32.1-6),
203 libpipeline1 (= 1.5.5-1),
204 libpng16-16 (= 1.6.37-3),
205 libprocps8 (= 2:3.3.17-6),
206 libpsl5 (= 0.21.0-1.2),
207 libquadmath0 (= 11.2.0-14),
208 librhash0 (= 1.4.2-1),
209 librtmp1 (= 2.4+20151223.gitfa8646d.1-2+b2),
210 libsasl2-2 (= 2.1.27+dfsg2-3),
211 libsasl2-modules-db (= 2.1.27+dfsg2-3),
212 libseccomp2 (= 2.5.3-2),
213 libselinux1 (= 3.3-1+b1),
214 libsigsegv2 (= 2.13-1),
215 libsmartcols1 (= 2.37.3-1),
216 libssh2-1 (= 1.10.0-2),
217 libssl1.1 (= 1.1.1m-1),
218 libstdc++-11-dev (= 11.2.0-14),
219 libstdc++6 (= 11.2.0-14),
220 libsub-override-perl (= 0.09-2),
221 libsystemd0 (= 250.3-1),
222 libtasn1-6 (= 4.18.0-4),
223 libtinfo6 (= 6.3-2),
224 libtirpc-common (= 1.3.2-2),
225 libtirpc-dev (= 1.3.2-2),
226 libtirpc3 (= 1.3.2-2),
227 libtool (= 2.4.6-15),
228 libubsan1 (= 11.2.0-14),
229 libuchardet0 (= 0.0.7-1),
230 libudev1 (= 250.3-1),
231 libunistring2 (= 0.9.10-6),
232 libuuid1 (= 2.37.3-1),
233 libuv1 (= 1.43.0-1),
234 libxml2 (= 2.9.12+dfsg-5+b1),
235 libzstd1 (= 1.4.8+dfsg-3),
236 linux-libc-dev (= 5.15.15-1),
237 login (= 1:4.8.1-2),
238 lsb-base (= 11.1.0),
239 m4 (= 1.4.18-5),
240 make (= 4.3-4.1),
241 man-db (= 2.9.4-4),
242 mawk (= 1.3.4.20200120-3),
243 ncurses-base (= 6.3-2),
244 ncurses-bin (= 6.3-2),
245 patch (= 2.7.6-7),
246 perl (= 5.32.1-6),
247 perl-base (= 5.32.1-6),
248 perl-modules-5.32 (= 5.32.1-6),
249 pkg-config (= 0.29.2-1),
250 po-debconf (= 1.0.21+nmu1),
251 procps (= 2:3.3.17-6),
252 rpcsvc-proto (= 1.4.2-4),
253 sed (= 4.8-1),
254 sensible-utils (= 0.0.17),
255 sysvinit-utils (= 3.01-1),
256 tar (= 1.34+dfsg-1),
257 util-linux (= 2.37.3-1),
258 xz-utils (= 5.2.5-2),
259 zlib1g (= 1:1.2.11.dfsg-2)
260Environment:
261 DEB_BUILD_OPTIONS="parallel=5"
262 SOURCE_DATE_EPOCH="1643116722""#;
263        let buildinfo: Buildinfo = super::from_str(data).unwrap();
264        assert_eq!(buildinfo.source, "picnic");
265        assert_eq!(
266            buildinfo.version,
267            PackageVersion::try_from("3.0.11-1").unwrap()
268        );
269        assert_eq!(
270            buildinfo.architecture,
271            vec![Architecture::I386, Architecture::Source]
272        );
273    }
274}