Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

WIP Pacbuild Parser #94

Draft
wants to merge 3 commits into
base: oxidation
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name = "libpacstall"
version = "0.1.0"
edition = "2021"
authors = [
"Sourajyoti Basak <[email protected]>",
"David Brochero <[email protected]>",
"Paul Cosma <[email protected]>"
"Sourajyoti Basak <[email protected]>",
"David Brochero <[email protected]>",
"Paul Cosma <[email protected]>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Paul Cosma <[email protected]>",
"Paul Cosma <[email protected]>",
"Henry Wenger-Stickel <hwengerstickel@protonmail,com>",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use your crates.io name and email

]
description = "Backend API library for Pacstall"
repository = "https://github.com/pacstall/libpacstall"
Expand All @@ -14,9 +14,28 @@ keywords = ["aur", "pacstall", "package-manager", "linux", "apt"]
categories = ["caching", "config", "parsing", "os::linux-apis"]

[dependencies]
figment = { version = "0.10.6", features = ["env", "test", "toml" ] }
figment = { version = "0.10.6", features = ["env", "test", "toml"] }
miette = "5.5.0"
num_cpus = "1.13.1"
regex = "1.7.0"
semver = "1.0.14"
serde = { version = "1.0.144", features = ["derive"] }
spdx = "0.10.0"
strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.37"
tree-sitter = "0.19"
tree-sitter-bash = "0.19.0"

[dev-dependencies]
rstest = "0.15.0"
miette = { version = "5.5.0", features = ["fancy"] }
criterion = { version = "0.4.0", features = ["html_reports"] }
rstest = "0.16.0"
proptest = "1.0.0"


[[example]]
name = "parser"

[[bench]]
name = "parser"
harness = false
138 changes: 138 additions & 0 deletions benches/parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use libpacstall::parser::pacbuild::PacBuild;

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("parser", |b| b.iter(|| PacBuild::from_source(black_box(r#"pkgname='potato' # can also be an array, probably shouldn't be though
pkgver='1.0.0' # this is the variable pkgver, can also be a function that will return dynamic version
epoch='0' # force package to be seen as newer no matter what
pkgdesc='Pretty obvious'
url='https://potato.com'
license="Apache-2.0 OR MIT"
arch=('any' 'x86_64')
maintainer=('Henryws <[email protected]>' 'Wizard-28 <[email protected]> <[email protected]>')
repology=("project: $pkgname")
source=(
"https://potato.com/$pkgver.tar.gz"
"potato.tar.gz::https://potato.com/$pkgver.tar.gz" # with a forced download name
"$pkgname::git+https://github.com/pacstall/pacstall" # git repo
"$pkgname::https://github.com/pacstall/pacstall/releases/download/2.0.1/pacstall-2.0.1.deb::repology" # use changelog with repology
"$pkgname::git+https://github.com/pacstall/pacstall#branch=master" # git repo with branch
"$pkgname::git+file://home/henry/pacstall/pacstall" # local git repo
"magnet://xt=urn:btih:c4769d7000244e4cae9c054a83e38f168bf4f69f&dn=archlinux-2022.09.03-x86_64.iso" # magnet link
"ftp://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.xz" # ftp
"patch-me-harder.patch::https://potato.com/patch-me.patch"
) # also source_x86_64=(), source_i386=()

noextract=(
"$pkgver.tar.gz"
)

sha256sums=(
'e69fcf51c211772d4f193f3dc59b1e91607bea7e53999f1d5e03ba401e5da969'
'SKIP'
'SKIP'
'etc'
) # can also do sha256sums_x86_64=(), repeat for sha384, sha512, and b2

optdepends=(
'same as pacstall: yes'
) # rince and repeat optdepends_$arch=()

depends=(
'hashbrowns>=1.8.0'
'mashed-potatos<=1.9.0'
'gravy=2.3.0'
'applesauce>3.0.0'
'chicken<2.0.0'
'libappleslices.so'
'libdeepfryer.so=3'
)

makedepends=(
'whisk'
'onions'
)

checkdepends=(
'customer_satisfaction'
)

ppa=('mcdonalds/ppa')

provides=(
'mashed-potatos'
'aaaaaaaaaaaaaaaaaaaaaaaaaa'
)

conflicts=(
'KFC'
'potato_rights'
) # can also do conflicts_$arch=()

replaces=(
'kidney_beans'
)

backup=(
'etc/potato/prepare.conf'
)

options=(
'!strip'
'!docs'
'etc'
)

groups=('potato-clan')

incompatible=('debian::jessy' 'ubuntu::20.04')

prepare() {
cd "$pkgname-$pkgver"
patch -p1 -i "$srcdir/patch-me-harder.patch"
}

build() {
cd "$pkgname-$pkgver"
./configure --prefix=/usr
make
}

check() {
cd "$pkgname-$pkgver"
make -k check
}

package() {
cd "$pkgname-$pkgver"
make DESTDIR="$pkgdir/" install
}

pre_install() {
echo "potato"
}

post_install() {
echo "potato"
}

pre_upgrade() {
echo "potato"
}

post_upgrade() {
echo "potato"
}

pre_remove() {
echo "potato"
}

post_remove() {
echo "potato"
}"#
))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
23 changes: 23 additions & 0 deletions examples/parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use libpacstall::parser::pacbuild::PacBuild;
use miette::Result;

fn main() -> Result<()> {
let k = 0;
dbg!(PacBuild::from_source(
r#"
pkgname='te'
pkgver="1.0"
epoch="21"
arch=("any")
#maintainer=("foo <" "bar <>" "biz <[email protected]> <[email protected]>")
license="MIT"
ppa=("lol/kol")
#depends=("foods" "bar: h")
#optdepends=("foo: ldsfadvnvbnvbnvnvnnvbnfds")
repology=("project: foo" "visiblename: distrotube")
sources=("git+file:///home/wizard/tmp/::repology")
"#
.trim(),
)?);
Ok(())
}
22 changes: 22 additions & 0 deletions proptest-regressions/parser/pacbuild.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc d852d8ab1865b7cd6cd0a169b0f9623924b087f06f45c37b71dd755c2905d17b # shrinks to version = "¡"
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc c0a8aeb72996e589b4531ff434ba0cf3a78d285d0d331e57fa01ec711cf65b74 # shrinks to name = "¡"
cc f1c3f577e82492bf2b437a5ea82df991eeff728a04009f6306f3f3bcfc5251d8 # shrinks to name = "-"
cc e5174aa9101b6422efc1327ce3176df895036712ab6d21082731d199cfeac9b2 # shrinks to name = ".a"
cc 4a837b559db189d9f3b4be4819eb293b163a433e3e9d50f476844096ff5e3c86 # shrinks to name = "z"
cc 3e96b46990a80964a0d69f13de029db178dab8dac811353ad973c5fee2b85ac3 # shrinks to name = ""
cc 6d1545dad9462e6e30fdf91f1a25462532b2e40327bb36a8c7a9bd152a37610e # shrinks to name = "0"
cc de06beeedfa5666db998956db96183abf32ffa4a551fe22b0826242bf7535ccb # shrinks to name = ":", version_req = "0"
cc b1b6390f4ec735609c5351febfee2a0d8a3b1b7895c3d03ace0e888a4b4efc53 # shrinks to name = "\t", email = "[email protected]"
cc 506f616e095e77967291c2782e927324b41cef3302f04809a2230c5c057e7ca4 # shrinks to value = ""
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ mod tests {
let selected_editor_path = &home.join(".selected_editor");

writeln!(
File::create(&selected_editor_path)?,
File::create(selected_editor_path)?,
r#"
# This is a mock file, if this persists on your system contact the Pacstall developers.
SELECTED_EDITOR="/usr/bin/nvim"
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
html_logo_url = "https://raw.githubusercontent.com/pacstall/website/master/client/public/pacstall.svg"
)]
#![allow(clippy::must_use_candidate)]

pub mod config;
pub mod parser;
42 changes: 42 additions & 0 deletions src/parser/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use miette::{Diagnostic, Report, SourceSpan};
use thiserror::Error;

#[derive(Debug, Diagnostic, Error)]
#[error("Parser error")]
pub struct ParseError {
/// Source code.
#[source_code]
pub input: String,

#[related]
pub related: Vec<Report>,
}

#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
#[error("Invalid field")]
pub struct FieldError {
/// States the issues with the field.
pub field_label: String,

/// Span of the field which has the error.
#[label("{field_label}")]
pub field_span: SourceSpan,

/// Span of the erroneous source code.
#[label("here")]
pub error_span: SourceSpan,

/// Suggestion for fixing the parser error.
#[help]
pub help: String,
}

#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
#[error("Missing field")]
pub struct MissingField {
pub label: &'static str,
}

#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
#[error("Bad syntax")]
pub struct BadSyntax;
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod errors;
pub mod pacbuild;
Loading