Skip to content

Commit d466b61

Browse files
committed
linter: extend license and x_exec
1 parent ee28ff6 commit d466b61

4 files changed

Lines changed: 592 additions & 9 deletions

File tree

sbuild-linter/src/build_config/mod.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ use serde::Deserialize;
88
use serde_yml::Value;
99

1010
use crate::{
11-
comments::Comments, description::Description, distro_pkg::DistroPkg, get_pkg_id,
12-
resource::Resource, xexec::XExec, BuildAsset,
11+
comments::Comments,
12+
description::Description,
13+
distro_pkg::DistroPkg,
14+
get_pkg_id,
15+
license::{License, LicenseComplex},
16+
resource::Resource,
17+
xexec::XExec,
18+
BuildAsset,
1319
};
1420

1521
pub mod visitor;
@@ -32,7 +38,7 @@ pub struct BuildConfig {
3238
pub maintainer: Option<Vec<String>>,
3339
pub icon: Option<Resource>,
3440
pub desktop: Option<Resource>,
35-
pub license: Option<Vec<String>>,
41+
pub license: Option<Vec<License>>,
3642
pub note: Option<Vec<String>>,
3743
pub provides: Option<Vec<String>>,
3844
pub repology: Option<Vec<String>>,
@@ -140,7 +146,33 @@ impl BuildConfig {
140146
config.desktop = to_resource(val);
141147
}
142148
if let Some(val) = values.get("license") {
143-
config.license = to_string_vec(val);
149+
config.license = val.as_sequence().map(|seq| {
150+
seq.iter()
151+
.filter_map(|lc| {
152+
if let Some(lc) = lc.as_str() {
153+
Some(License::Simple(lc.to_string()))
154+
} else {
155+
lc.as_mapping().map(|map| {
156+
License::Complex(LicenseComplex {
157+
id: map
158+
.get(Value::String("id".to_string()))
159+
.and_then(|v| v.as_str())
160+
.map(String::from)
161+
.unwrap_or_default(),
162+
file: map
163+
.get(Value::String("file".to_string()))
164+
.and_then(|v| v.as_str())
165+
.map(String::from),
166+
url: map
167+
.get(Value::String("url".to_string()))
168+
.and_then(|v| v.as_str())
169+
.map(String::from),
170+
})
171+
})
172+
}
173+
})
174+
.collect()
175+
});
144176
}
145177
if let Some(val) = values.get("maintainer") {
146178
config.maintainer = to_string_vec(val);
@@ -279,8 +311,16 @@ impl BuildConfig {
279311
write_field_comments(writer, "license")?;
280312
if let Some(ref license) = self.license {
281313
writeln!(writer, "{}license:", indent_str)?;
282-
for l in license {
283-
writeln!(writer, "{} - \"{}\"", indent_str, l)?;
314+
for lc in license {
315+
lc.write_yaml(writer, indent)?;
316+
}
317+
}
318+
319+
if let Some(ref build_asset) = self.build_asset {
320+
writeln!(writer, "{}build_asset:", indent_str)?;
321+
for asset in build_asset {
322+
writeln!(writer, "{} - url: \"{}\"", indent_str, asset.url)?;
323+
writeln!(writer, "{} out: \"{}\"", indent_str, asset.out)?;
284324
}
285325
}
286326

sbuild-linter/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod comments;
2222
pub mod description;
2323
pub mod distro_pkg;
2424
pub mod error;
25+
pub mod license;
2526
pub mod logger;
2627
pub mod resource;
2728
pub mod semaphore;
@@ -40,6 +41,8 @@ pub const VALID_PKG_TYPES: [&str; 9] = [
4041
"static",
4142
];
4243
pub const VALID_CATEGORIES: &str = include_str!("categories");
44+
pub const VALID_ARCH: [&str; 4] = ["aarch64", "loongarch64", "riscv64", "x86_64"];
45+
pub const VALID_OS: [&str; 6] = ["freebsd", "illumos", "linux", "netbsd", "openbsd", "redox"];
4346

4447
#[derive(Debug, Deserialize, Clone)]
4548
pub struct BuildAsset {

sbuild-linter/src/license.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::{
2+
fs::File,
3+
io::{self, BufWriter, Write},
4+
};
5+
6+
use serde::Deserialize;
7+
8+
#[derive(Debug, Deserialize, Clone)]
9+
pub struct LicenseComplex {
10+
pub id: String,
11+
pub file: Option<String>,
12+
pub url: Option<String>,
13+
}
14+
15+
#[derive(Debug, Deserialize, Clone)]
16+
pub enum License {
17+
Simple(String),
18+
Complex(LicenseComplex),
19+
}
20+
21+
impl License {
22+
pub fn write_yaml(&self, writer: &mut BufWriter<File>, indent: usize) -> io::Result<()> {
23+
let indent_str = " ".repeat(indent);
24+
25+
match self {
26+
License::Simple(item) => {
27+
writeln!(writer, "{} - \"{}\"", indent_str, item)?;
28+
}
29+
License::Complex(item) => {
30+
writeln!(writer, "{} - id: \"{}\"", indent_str, item.id)?;
31+
if let Some(ref file) = item.file {
32+
writeln!(writer, "{} file: \"{}\"", indent_str, file)?;
33+
}
34+
if let Some(ref url) = item.url {
35+
writeln!(writer, "{} url: \"{}\"", indent_str, url)?;
36+
}
37+
}
38+
}
39+
40+
Ok(())
41+
}
42+
}

0 commit comments

Comments
 (0)