Skip to content

Commit

Permalink
chore: more description
Browse files Browse the repository at this point in the history
  • Loading branch information
wdv4758h committed Aug 19, 2016
1 parent 7e80e90 commit 0842f47
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 49 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cargo-arch will generate ``PKGBUILD`` from information in Cargo.toml.
You can add extra information in ``[package.metadata.arch]`` sections,
options can be found by ``man PKGBUILD``.

`Documentation <https://wdv4758h.github.io/cargo-arch/cargo_arch/>`_


.. contents:: Table of Contents

Expand Down Expand Up @@ -150,6 +152,12 @@ x86_64, Linux, musl (build on Arch Linux)
not a dynamic executable
Commands Dependency
------------------------------

* `makepkg <https://wiki.archlinux.org/index.php/makepkg>`_



Changelog
========================================
Expand Down Expand Up @@ -191,6 +199,7 @@ Special Thanks
========================================

* `cargo-deb <https://github.com/mmstick/cargo-deb>`_ for generates Debian packages
* `rust-everywhere <https://github.com/japaric/rust-everywhere/>`_ for CI integration
* `clap-rs <https://github.com/kbknapp/clap-rs>`_ for arguments parsing
* `Rust Team <https://www.rust-lang.org/team.html>`_
* and every project I've used
Expand Down
8 changes: 5 additions & 3 deletions src/config/arch.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Arch Linux's package config
use std::fs::File;
use std::io::prelude::*;

use toml;

use super::core::{Cargo, ToPackageConfig, GeneratePackage};
use super::core::{Cargo, ToPackageConfig, GeneratePackageConfig};
use super::meta::CargoMetadata;


/// data in [package.metadata.arch]
/// data in `[package.metadata.arch]` section
#[derive(Clone, Debug, Default, RustcDecodable)]
pub struct CargoArch {
/// The maintainers of the package
Expand Down Expand Up @@ -307,7 +309,7 @@ impl ToPackageConfig<ArchConfig> for Cargo {
}


impl GeneratePackage for ArchConfig {
impl GeneratePackageConfig for ArchConfig {
fn generate_package_config(&self) {
self.generate_pkgbuild();
}
Expand Down
8 changes: 6 additions & 2 deletions src/config/core.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Basic Rust package's config, modified from Cargo.
use super::meta::CargoMetadata;


Expand All @@ -7,7 +9,7 @@ pub struct Cargo {
pub package: CargoPackage,
}

/// data in [package]
/// data in `[package]` section
#[derive(Clone, Debug, RustcDecodable)]
pub struct CargoPackage {
pub name: String,
Expand All @@ -24,10 +26,12 @@ pub struct CargoPackage {
}


/// A trait for making specific platform package config's settings
pub trait ToPackageConfig<T> {
fn to_config(&self) -> T;
}

pub trait GeneratePackage {
/// A trait for generate specific platform package's config
pub trait GeneratePackageConfig {
fn generate_package_config(&self);
}
4 changes: 3 additions & 1 deletion src/config/meta.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Metadata for different platform's package
use super::arch::CargoArch;


/// data in [package.metadata]
/// data in `[package.metadata]` section
#[derive(Clone, Debug, Default, RustcDecodable)]
pub struct CargoMetadata {
pub arch: Option<CargoArch>,
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Config for specific platform's package.
pub mod core;
pub mod meta;
pub mod arch;
Expand Down
52 changes: 9 additions & 43 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! `cargo arch` is a Cargo plugin for making Arch Linux packages.
//! Packages' information is extract from `Cargo.toml`.
//! You can add additional information in `[package.metadata.arch]` section.
#![feature(custom_derive)]

#[macro_use]
Expand All @@ -7,13 +11,10 @@ extern crate rustc_serialize;

use clap::App;

use std::process::Command;
use std::fs::File;
use std::io::Write;

pub mod config;
pub mod utils;

use config::GeneratePackage;
pub use utils::*;


fn main() {
Expand All @@ -25,51 +26,16 @@ fn main() {
let yml = load_yaml!("arguments.yml");
let arguments = App::from_yaml(yml).get_matches();
let arguments = arguments.subcommand_matches("arch").unwrap();
let build = arguments.value_of("build").unwrap();
let build = arguments.value_of("build").unwrap().parse::<bool>().unwrap();
let install = arguments.is_present("install");
let syncdeps = arguments.is_present("syncdeps");
let force = arguments.is_present("force");
let mksrcinfo = arguments.is_present("mksrcinfo");

////////////////////
// Generate PKGBUILD
// Build Arch Package
////////////////////

config::ArchConfig::new()
.generate_package_config();

if mksrcinfo {
let output = Command::new("makepkg")
.args(&["--printsrcinfo"])
.output()
.expect("failed to generate .SRCINFO");

let mut file = File::create(".SRCINFO").unwrap();
file.write_all(&output.stdout).unwrap();
}

////////////////////
// Build Package
////////////////////

if build == "true" {
let mut args = vec![];

if install {
args.push("--install");
}
if syncdeps {
args.push("--syncdeps");
}
if force {
args.push("--force");
}
build_arch_package(mksrcinfo, build, install, syncdeps, force);

Command::new("makepkg")
.args(&args)
.spawn()
.unwrap()
.wait()
.expect("failed to build package");
}
}

0 comments on commit 0842f47

Please sign in to comment.