Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra Repos and Keys #39

Merged
merged 2 commits into from Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/config/mod.rs
@@ -1,7 +1,8 @@
use std::borrow::Cow;
use std::fs::File;
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::PathBuf;
use std::ffi::OsStr;

use toml::{self, de};
use misc;
Expand Down Expand Up @@ -54,6 +55,9 @@ pub struct Config {
pub repos: Option<Vec<Repo>>,
#[serde(default = "default_component")]
pub default_component: String,
pub extra_repos: Option<Vec<String>>,
#[serde(skip)]
pub extra_keys: Vec<PathBuf>,
}

impl Config {
Expand Down Expand Up @@ -196,5 +200,15 @@ pub fn parse(path: PathBuf) -> Result<Config, ParsingError> {
})?;

config.path = path;
if let Ok(key_dir) = fs::read_dir("keys") {
for key in key_dir.flat_map(|x| x.ok()) {
let path = key.path();
if path.extension().map_or(false, |e| e == OsStr::new("asc")) {
if let Ok(path) = path.canonicalize() {
config.extra_keys.push(path);
}
}
}
}
Ok(config)
}
1 change: 1 addition & 0 deletions src/config/source.rs
Expand Up @@ -31,6 +31,7 @@ pub struct Source {
pub starting_build: Option<Vec<String>>,
pub prebuild: Option<Vec<String>>,
pub build_on: Option<String>,
pub repos: Option<Vec<String>>,
#[serde(default = "default_build_source")]
pub keep_source: bool,
pub debian: Option<DebianPath>,
Expand Down
73 changes: 58 additions & 15 deletions src/repo/build/mod.rs
Expand Up @@ -3,23 +3,25 @@ mod extract;
mod metapackages;
mod rsync;

use super::super::SHARED_ASSETS;
use self::artifacts::{link_artifact, LinkedArtifact, LinkError};
use super::version::{changelog, git};
use self::rsync::rsync;
use command::Command;
use config::{Config, DebianPath, Direct, Source, SourceLocation};
use debian;
use deb_version;
use debarchive::Archive as DebArchive;
use debian;
use glob::glob;
use misc;
use super::pool::{mv_to_pool, KEEP_SOURCE};
use self::artifacts::{link_artifact, LinkedArtifact, LinkError};
use self::rsync::rsync;
use std::cmp::Ordering;
use std::env;
use std::fs::{self, OpenOptions};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::exit;
use subprocess::{self, Exec, Redirection};
use super::pool::{mv_to_pool, KEEP_SOURCE};
use super::super::SHARED_ASSETS;
use super::version::{changelog, git};
use walkdir::WalkDir;

pub fn all(config: &Config) {
Expand All @@ -31,7 +33,7 @@ pub fn all(config: &Config) {
migrate_to_pool(config, sources.iter());
let build_path = ["build/", &config.archive].concat();
for source in sources {
if let Err(why) = build(source, &pwd, suite, component, false) {
if let Err(why) = build(config, source, &pwd, suite, component, false) {
error!("package '{}' failed to build: {}", source.name, why);
exit(1);
}
Expand Down Expand Up @@ -72,7 +74,7 @@ pub fn packages(config: &Config, packages: &[&str], force: bool) {
migrate_to_pool(config, sources.iter().cloned());
let build_path = ["build/", &config.archive].concat();
for source in &sources {
if let Err(why) = build(source, &pwd, &config.archive, &config.default_component, force) {
if let Err(why) = build(config, source, &pwd, &config.archive, &config.default_component, force) {
error!("package '{}' failed to build: {}", source.name, why);
exit(1);
}
Expand Down Expand Up @@ -261,7 +263,7 @@ fn fetch_assets(
}

/// Attempts to build Debian packages from a given software repository.
pub fn build(item: &Source, pwd: &Path, suite: &str, component: &str, force: bool) -> Result<(), BuildError> {
pub fn build(config: &Config, item: &Source, pwd: &Path, suite: &str, component: &str, force: bool) -> Result<(), BuildError> {
info!("attempting to build {}", &item.name);
let project_directory = pwd.join(&["build/", suite, "/", &item.name].concat());

Expand Down Expand Up @@ -337,6 +339,7 @@ pub fn build(item: &Source, pwd: &Path, suite: &str, component: &str, force: boo
let _ = env::set_current_dir(&["build/", suite].concat());

pre_flight(
config,
item,
&pwd,
suite,
Expand All @@ -362,6 +365,7 @@ fn merge_branch(url: &str, branch: &str) -> io::Result<()> {
}

fn pre_flight(
config: &Config,
item: &Source,
pwd: &Path,
suite: &str,
Expand Down Expand Up @@ -454,7 +458,7 @@ fn pre_flight(
None => None,
};

sbuild(item, &pwd, suite, component, dir)?;
sbuild(config, item, &pwd, suite, component, dir)?;

let result = match record {
Some(Record::Changelog(version)) => {
Expand All @@ -476,6 +480,7 @@ fn pre_flight(
}

fn sbuild<P: AsRef<Path>>(
config: &Config,
item: &Source,
pwd: &Path,
suite: &str,
Expand All @@ -484,7 +489,11 @@ fn sbuild<P: AsRef<Path>>(
) -> Result<(), BuildError> {
let log_path = pwd.join(["logs/", suite, "/", &item.name].concat());
let mut command = Exec::cmd("sbuild")
.args(&["-v", "--log-external-command-output", "--log-external-command-error", "-d", suite])
.args(&[
"-v", "--log-external-command-output", "--log-external-command-error",
// "--dpkg-source-opt=-Zgzip", // Use this when testing
"-d", suite
])
.stdout(Redirection::Merge)
.stderr(Redirection::File(
fs::OpenOptions::new()
Expand All @@ -496,9 +505,33 @@ fn sbuild<P: AsRef<Path>>(
));

if let Some(ref depends) = item.depends {
let mut temp = misc::walk_debs(&pwd.join(&["repo/pool/", suite, "/", component].concat()), false)
.flat_map(|deb| misc::match_deb(&deb, depends))
.collect::<Vec<(String, usize)>>();
let pool = pwd.join(&["repo/pool/", suite, "/", component].concat());
let deb_iter = misc::walk_debs(&pool, false)
.flat_map(|deb| misc::match_deb(&deb, depends));

let mut temp: Vec<(String, usize, String, String)> = Vec::new();
for (deb, pos) in deb_iter {
let (name, version) = debian::get_debian_package_info(&Path::new(&deb))
.expect("failed to get debian name & version");

let mut found = false;
for stored_dep in &mut temp {
if stored_dep.2 == name {
found = true;
if deb_version::compare_versions(&stored_dep.3, &version) == Ordering::Less {
stored_dep.0 = deb.clone();
stored_dep.1 = pos.clone();
stored_dep.2 = name.clone();
stored_dep.3 = version.clone();
continue
}
}
}

if ! found {
temp.push((deb, pos, name, version));
}
}

if depends.len() != temp.len() {
for dependency in depends {
Expand All @@ -511,11 +544,21 @@ fn sbuild<P: AsRef<Path>>(
}

temp.sort_by(|a, b| a.1.cmp(&b.1));
for &(ref p, _) in &temp {
for &(ref p, _, _, _) in &temp {
command = command.arg(&["--extra-package=", &p].concat());
}
}

for key in &config.extra_keys {
command = command.arg(&format!("--extra-repository-key={}", key.display()));
}

if let Some(repos) = config.extra_repos.as_ref() {
for repo in repos {
command = command.arg(&["--extra-repository=", &repo].concat());
}
}

if let Some(commands) = item.prebuild.as_ref() {
for cmd in commands {
command = command.arg(&["--pre-build-commands=", &cmd].concat());
Expand Down