Skip to content

Commit

Permalink
Add devel checks to tests
Browse files Browse the repository at this point in the history
And fix races
  • Loading branch information
Morganamilo committed Oct 15, 2023
1 parent 1c7d7e5 commit a4eaa3c
Show file tree
Hide file tree
Showing 38 changed files with 336 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
paru.tar.*
po/*.mo
locale/
testdata/pkg/*
2 changes: 2 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl Config {
Arg::Long("config") => self.pacman_conf = Some(value?.to_string()),

Arg::Long("builddir") | Arg::Long("clonedir") => self.build_dir = value?.into(),
Arg::Long("develfile") => self.devel_path = value?.into(),
Arg::Long("makepkgconf") => self.makepkg_conf = Some(value?.to_string()),
Arg::Long("mflags") => self.mflags.extend(split_whitespace(value?)),
Arg::Long("gitflags") => self.git_flags.extend(split_whitespace(value?)),
Expand Down Expand Up @@ -419,6 +420,7 @@ fn takes_value(arg: Arg) -> TakesValue {
Arg::Long("builddir") => TakesValue::Required,
Arg::Long("provides") => TakesValue::Optional,
Arg::Long("clonedir") => TakesValue::Required,
Arg::Long("develfile") => TakesValue::Required,
//pacman
Arg::Long("dbpath") | Arg::Short('b') => TakesValue::Required,
Arg::Long("root") | Arg::Short('r') => TakesValue::Required,
Expand Down
5 changes: 0 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,6 @@ impl Config {
..Self::default()
};

let mut fetch = config.fetch.clone();
fetch.clone_dir = config.build_dir.join("repo");
fetch.diff_dir = config.cache_dir.join("diff/repo");
config.pkgbuild_repos.fetch = fetch;

if let Some(old) = old {
if let Ok(devel) = OpenOptions::new().read(true).open(old) {
if let Ok(devel) = serde_json::from_reader(devel) {
Expand Down
7 changes: 6 additions & 1 deletion src/devel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ async fn ls_remote_intenral(
remote: &str,
branch: Option<&str>,
) -> Result<String> {
#[cfg(feature = "mock")]
let _ = git;
#[cfg(feature = "mock")]
let git = "git";

let mut command = AsyncCommand::new(git);
command
.args(flags)
Expand Down Expand Up @@ -472,7 +477,7 @@ pub async fn pkg_has_update<'pkg, 'info, 'cfg>(
async fn has_update(style: Style, git: &str, flags: &[String], url: &RepoInfo) -> Result<()> {
let sha = ls_remote(style, git, flags, url.url.clone(), url.branch.as_deref()).await?;
debug!(
"devel check {}: {} == {} different: {}",
"devel check {}: '{}' == '{}' different: {}",
url.url,
url.commit,
sha,
Expand Down
36 changes: 31 additions & 5 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,47 @@ pub fn pacman_output<S: AsRef<str> + Display + std::fmt::Debug>(
command_output(&mut cmd)
}

fn new_makepkg<S: AsRef<OsStr>>(config: &Config, dir: &Path, args: &[S]) -> Command {
fn new_makepkg<S: AsRef<OsStr>>(
config: &Config,
dir: &Path,
args: &[S],
pkgdest: Option<&str>,
) -> Command {
let mut cmd = Command::new(&config.makepkg_bin);
if let Some(mconf) = &config.makepkg_conf {
cmd.arg("--config").arg(mconf);
}
if let Some(dest) = pkgdest {
cmd.env("PKGDEST", dest);
}
cmd.args(&config.mflags).args(args).current_dir(dir);
cmd
}

pub fn makepkg<S: AsRef<OsStr>>(config: &Config, dir: &Path, args: &[S]) -> Result<Status> {
let mut cmd = new_makepkg(config, dir, args);
pub fn makepkg_dest<S: AsRef<OsStr>>(
config: &Config,
dir: &Path,
args: &[S],
pkgdest: Option<&str>,
) -> Result<Status> {
let mut cmd = new_makepkg(config, dir, args, pkgdest);
command_status(&mut cmd)
}

pub fn makepkg_output<S: AsRef<OsStr>>(config: &Config, dir: &Path, args: &[S]) -> Result<Output> {
let mut cmd = new_makepkg(config, dir, args);
pub fn makepkg<S: AsRef<OsStr>>(config: &Config, dir: &Path, args: &[S]) -> Result<Status> {
makepkg_dest(config, dir, args, None)
}

pub fn makepkg_output_dest<S: AsRef<OsStr>>(
config: &Config,
dir: &Path,
args: &[S],
pkgdest: Option<&str>,
) -> Result<Output> {
let mut cmd = new_makepkg(config, dir, args, pkgdest);
command_output(&mut cmd)
}

pub fn makepkg_output<S: AsRef<OsStr>>(config: &Config, dir: &Path, args: &[S]) -> Result<Output> {
makepkg_output_dest(config, dir, args, None)
}
44 changes: 26 additions & 18 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ impl Installer {
Ok(debug_paths)
}

// TODO: sort out args
fn build_pkgbuild(
&mut self,
config: &mut Config,
Expand All @@ -506,6 +507,9 @@ impl Installer {
dir: &Path,
) -> Result<(HashMap<String, String>, String)> {
let c = config.color;
let pkgdest = repo.map(|r| r.1);
let mut env = config.env.clone();
env.extend(pkgdest.map(|p| ("PKGDEST".to_string(), p.to_string())));

if config.chroot {
let mut extra = Vec::new();
Expand All @@ -514,7 +518,7 @@ impl Installer {
}
self.chroot
.build(dir, &extra, &["-cu"], &["-ofA"], &config.env)
.with_context(|| tr!("failed to download sources for '{}'", base))?;
.with_context(|| tr!("failed to download sources for '{}'"))?;
} else {
// download sources
let mut args = vec!["--verifysource", "-Af"];
Expand All @@ -536,15 +540,15 @@ impl Installer {
}

printtr!("{}: parsing pkg list...", base);
let (pkgdest, version) = parse_package_list(config, dir)?;
let (pkgdests, version) = parse_package_list(config, dir, pkgdest)?;

if !base.packages().all(|p| pkgdest.contains_key(p)) {
if !base.packages().all(|p| pkgdests.contains_key(p)) {
bail!(tr!("package list does not match srcinfo"));
}

let debug_paths = self.debug_paths(config, base, &pkgdest)?;
let debug_paths = self.debug_paths(config, base, &pkgdests)?;

let needs_build = needs_build(config, base, &pkgdest, &version);
let needs_build = needs_build(config, base, &pkgdests, &version);
if needs_build {
// actual build
if config.chroot {
Expand All @@ -558,15 +562,15 @@ impl Installer {
&extra,
&[],
&["-feA", "--noconfirm", "--noprepare", "--holdver"],
&config.env,
&env,
)
.with_context(|| tr!("failed to build '{}'", base))?;
} else {
let mut args = vec!["-feA", "--noconfirm", "--noprepare", "--holdver"];
if !config.keep_src {
args.push("-c");
}
exec::makepkg(config, dir, &args)?
exec::makepkg_dest(config, dir, &args, pkgdest)?
.success()
.with_context(|| tr!("failed to build '{}'", base))?;
}
Expand All @@ -582,9 +586,9 @@ impl Installer {
)
}

self.add_pkg(config, base, repo, &pkgdest, &debug_paths)?;
self.queue_install(base, &pkgdest, &debug_paths);
Ok((pkgdest, version))
self.add_pkg(config, base, repo, &pkgdests, &debug_paths)?;
self.queue_install(base, &pkgdests, &debug_paths);
Ok((pkgdests, version))
}

fn queue_install(
Expand Down Expand Up @@ -683,6 +687,7 @@ impl Installer {
.clone(),
};

let pkgdest = repo.map(|r| r.1);
let build = base.build();

if !config.chroot
Expand Down Expand Up @@ -749,11 +754,11 @@ impl Installer {
self.build_pkgbuild(config, base, repo, &dir)?
} else {
printtr!("{}: parsing pkg list...", base);
let (pkgdest, version) = parse_package_list(config, &dir)?;
let debug_paths = self.debug_paths(config, base, &pkgdest)?;
self.add_pkg(config, base, repo, &pkgdest, &debug_paths)?;
self.queue_install(base, &pkgdest, &debug_paths);
(pkgdest, version)
let (pkgdests, version) = parse_package_list(config, &dir, pkgdest)?;
let debug_paths = self.debug_paths(config, base, &pkgdests)?;
self.add_pkg(config, base, repo, &pkgdests, &debug_paths)?;
self.queue_install(base, &pkgdests, &debug_paths);
(pkgdests, version)
};

match &*base {
Expand Down Expand Up @@ -820,7 +825,6 @@ impl Installer {
if let Some(repo) = default_repo {
let file = repo::file(&repo).unwrap();
repo::init(config, file, repo.name())?;
std::env::set_var("PKGDEST", file);
}

if config.chroot {
Expand Down Expand Up @@ -1971,8 +1975,12 @@ pub fn copy_sync_args<'a>(config: &'a Config, args: &mut Args<&'a str>) {
}
}

fn parse_package_list(config: &Config, dir: &Path) -> Result<(HashMap<String, String>, String)> {
let output = exec::makepkg_output(config, dir, &["--packagelist"])?;
fn parse_package_list(
config: &Config,
dir: &Path,
pkgdest: Option<&str>,
) -> Result<(HashMap<String, String>, String)> {
let output = exec::makepkg_output_dest(config, dir, &["--packagelist"], pkgdest)?;
let output = String::from_utf8(output.stdout).context("pkgdest is not utf8")?;
let mut pkgdests = HashMap::new();
let mut version = String::new();
Expand Down
28 changes: 26 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,38 @@ async fn run2<S: AsRef<str>>(config: &mut Config, args: &[S]) -> Result<i32> {
config.parse(Some(name.as_str()), &file)?;
};

log::debug!("{:#?}", config);

if args.is_empty() {
config.parse_args(["-Syu"])?;
} else {
config.parse_args(args)?;
}

let aur_url = if config.ssh {
config
.aur_url
.to_string()
.replacen("https://", "ssh://aur@", 1)
.parse()
.expect("change AUR URL schema from HTTPS to SSH")
} else {
config.aur_url.clone()
};

config.fetch = aur_fetch::Fetch {
git: config.git_bin.clone().into(),
git_flags: config.git_flags.clone(),
clone_dir: config.build_dir.clone(),
diff_dir: config.cache_dir.join("diff"),
aur_url,
};

let mut fetch = config.fetch.clone();
fetch.clone_dir = config.build_dir.join("repo");
fetch.diff_dir = config.cache_dir.join("diff/repo");
config.pkgbuild_repos.fetch = fetch;

log::debug!("{:#?}", config);

handle_cmd(config).await
}

Expand Down
2 changes: 1 addition & 1 deletion src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub fn refresh<S: AsRef<OsStr>>(config: &mut Config, repos: &[S]) -> Result<i32>
);

if !dbs.is_empty() {
dbs.update(false)?;
dbs.update(cfg!(feature = "mock"))?;
} else {
printtr!(" nothing to do");
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/bin/makepkg.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
bash -x /usr/local/bin/local/makepkg "$@" | tee /dev/tty
2 changes: 1 addition & 1 deletion testdata/bin/pacman
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
/usr/bin/pacman --config "$PACMAN_CONF" --dbpath "$DBPATH" "$@"
/usr/local/bin/pacman --config "$PACMAN_CONF" --dbpath "$DBPATH" "$@"
3 changes: 3 additions & 0 deletions testdata/bin/pacman.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
#/usr/local/bin/pacman --config "$PACMAN_CONF" --dbpath "$DBPATH" "$@"
/usr/local/bin/pacman "$@"
Binary file not shown.
8 changes: 8 additions & 0 deletions testdata/clone/devel/.SRCINFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pkgbase = devel
pkgver = 1
pkgrel = 1
arch = any
source = git+file:////Users/morganamilo/git/paru/testdata/clone/devel/../../git-repo
sha256sums = SKIP

pkgname = devel
6 changes: 6 additions & 0 deletions testdata/clone/devel/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pkgname=devel
pkgver=2
pkgrel=1
arch=(any)
source=(git+file:///$PWD/../../git-repo)
sha256sums=(SKIP)
33 changes: 33 additions & 0 deletions testdata/db/local/devel-1-1/desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%NAME%
devel

%VERSION%
1-1

%BASE%
devel

%DESC%


%URL%


%ARCH%
any

%BUILDDATE%
1697290439

%INSTALLDATE%
1697290651

%PACKAGER%
Unknown Packager

%VALIDATION%
none

%XDATA%
pkgtype=pkg

Empty file.
Binary file added testdata/db/local/devel-1-1/mtree
Binary file not shown.
3 changes: 3 additions & 0 deletions testdata/devel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[devel]]
url = "file:////Users/morganamilo/git/paru/testdata/clone/devel/../../git-repo"
commit = "deadbeef"
1 change: 1 addition & 0 deletions testdata/git-repo/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/main
8 changes: 8 additions & 0 deletions testdata/git-repo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = /Users/morganamilo/a
1 change: 1 addition & 0 deletions testdata/git-repo/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
6 changes: 6 additions & 0 deletions testdata/git-repo/info/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x��A
�0E]��d&q"^e�Nm�i ���-���_=x��[�e�e:��
���)r9MQ0�zJ3O!:�9�RD2���u��?e�Z��xH��Z��}9�;���#y g��&����0�:f>�5>E
2 changes: 2 additions & 0 deletions testdata/git-repo/packed-refs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
62ba46861565a44a61b16968f9ef248f2828cb94 refs/heads/main
Loading

0 comments on commit a4eaa3c

Please sign in to comment.