Fix a bunch of warnings

This commit is contained in:
Yehuda Katz 2014-05-05 14:33:28 -07:00
parent ff85524210
commit 76623a01d4
7 changed files with 44 additions and 101 deletions

View File

@ -7,7 +7,7 @@ extern crate serialize;
use cargo::ops::cargo_compile::compile;
use cargo::{CargoResult,ToCargoError};
use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError};
use hammer::{FlagDecoder,FlagConfig,HammerError};
use serialize::Decodable;
#[deriving(Eq,Clone,Decodable,Encodable)]

View File

@ -2,10 +2,28 @@
#![allow(deprecated_owned_vector)]
extern crate cargo;
extern crate serialize;
extern crate hammer;
use cargo::execute_main_without_stdin;
use cargo::ops::cargo_read_manifest::execute;
use cargo::{CargoResult,execute_main_without_stdin};
use cargo::ops::cargo_read_manifest::read_manifest;
use cargo::core::Manifest;
use hammer::FlagConfig;
#[deriving(Decodable,Eq,Clone,Ord)]
pub struct ReadManifestFlags {
manifest_path: ~str
}
impl FlagConfig for ReadManifestFlags {}
fn main() {
execute_main_without_stdin(execute);
}
fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
match read_manifest(flags.manifest_path) {
Ok(manifest) => Ok(Some(manifest)),
Err(e) => Err(e)
}
}

View File

@ -1,4 +1,3 @@
use std::fmt;
use core::{NameVer,Package};
use CargoResult;

View File

@ -14,29 +14,19 @@
* b. Compile each dependency in order, passing in the -L's pointing at each previously compiled dependency
*/
use std;
use std::vec::Vec;
use serialize::{Decodable};
use std::io;
use std::io::BufReader;
use std::io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
use std::os;
use util::config;
use util::config::{all_configs,ConfigValue};
use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
use core::resolver::resolve;
use core::package::PackageSet;
use core::Package;
use core::source::Source;
use core::dependency::Dependency;
use sources::path::PathSource;
use ops::cargo_rustc;
use {CargoError,ToCargoError,CargoResult};
use {CargoError,CargoResult};
pub fn compile(manifest_path: &str) -> CargoResult<()> {
let manifest = try!(cargo_read_manifest(manifest_path));
let configs = try!(all_configs(os::getcwd()));
let config_paths = configs.find(&("paths".to_owned())).map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
@ -58,46 +48,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
let resolved = try!(resolve(deps.as_slice(), &registry));
cargo_rustc::compile(&resolved);
try!(cargo_rustc::compile(&resolved));
Ok(())
//call_rustc(~BufReader::new(manifest_bytes.as_slice()))
}
fn read_manifest(manifest_path: &str) -> CargoResult<Vec<u8>> {
Ok((try!(exec_with_output("cargo-read-manifest", ["--manifest-path".to_owned(), manifest_path.to_owned()], None))).output)
}
fn call_rustc(mut manifest_data: ~Reader:) -> CargoResult<()> {
let data: &mut Reader = manifest_data;
try!(exec_tty("cargo-rustc", [], Some(data)));
Ok(())
}
fn exec_with_output(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessOutput> {
Ok((try!(exec(program, args, input, |_| {}))).wait_with_output())
}
fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessExit> {
Ok((try!(exec(program, args, input, |config| {
config.stdout = InheritFd(1);
config.stderr = InheritFd(2);
}))).wait())
}
fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> CargoResult<Process> {
let mut config = ProcessConfig::new();
config.program = program;
config.args = args;
configurator(&mut config);
println!("Executing {} {}", program, args);
let mut process = try!(Process::configure(config).to_cargo_error(|e: io::IoError| format!("Could not configure process: {}", e), 1));
input.map(|mut reader| io::util::copy(&mut reader, process.stdin.get_mut_ref()));
Ok(process)
}

View File

@ -1,32 +1,11 @@
use toml;
use hammer::FlagConfig;
use serialize::Decoder;
use toml::from_toml;
use {CargoResult,ToCargoError,core};
use core::manifest::{SerializedManifest,Manifest};
use {CargoResult,ToCargoError};
#[deriving(Decodable,Eq,Clone,Ord)]
pub struct ReadManifestFlags {
manifest_path: ~str
}
impl FlagConfig for ReadManifestFlags {}
pub fn read_manifest(manifest_path: &str) -> CargoResult<core::Manifest> {
match execute(ReadManifestFlags { manifest_path: manifest_path.to_owned() }) {
Ok(manifest) => Ok(manifest.unwrap()),
Err(e) => Err(e)
}
}
pub fn execute(flags: ReadManifestFlags) -> CargoResult<Option<core::Manifest>> {
let manifest_path = flags.manifest_path;
pub fn read_manifest(manifest_path: &str) -> CargoResult<Manifest> {
let root = try!(toml::parse_from_file(manifest_path.clone()).to_cargo_error(format!("Couldn't parse Toml file: {}", manifest_path), 1));
let toml_manifest = try!(from_toml::<SerializedManifest>(root.clone()).to_cargo_error(|e: toml::Error| format!("Couldn't parse Toml file: {:?}", e), 1));
Manifest::from_serialized(manifest_path.as_slice(), &toml_manifest).map(|manifest| {
Some(manifest)
})
Manifest::from_serialized(manifest_path.as_slice(), &toml_manifest)
}

View File

@ -3,50 +3,56 @@ use std::os::args;
use std::io;
use std::io::process::{Process,ProcessConfig,InheritFd};
use std::path::Path;
use {CargoResult,CargoError,ToCargoError,NoFlags,core};
use {CargoResult,CargoError,ToCargoError,NoFlags};
use core;
use util;
type Args = Vec<~str>;
pub fn compile(pkgs: &core::PackageSet) {
pub fn compile(pkgs: &core::PackageSet) -> CargoResult<()> {
let sorted = match pkgs.sort() {
Some(pkgs) => pkgs,
None => fail!("Could not perform topsort on PackageSet")
None => return Err(CargoError::new("Circular dependency detected".to_owned(), 1))
};
for pkg in sorted.iter() {
compile_pkg(pkg, pkgs);
try!(compile_pkg(pkg, pkgs));
}
Ok(())
}
fn compile_pkg(pkg: &core::Package, pkgs: &core::PackageSet) {
fn compile_pkg(pkg: &core::Package, pkgs: &core::PackageSet) -> CargoResult<()> {
// Build up the destination
let src = pkg.get_root().join(Path::new(pkg.get_source().path.as_slice()));
let target = pkg.get_root().join(Path::new(pkg.get_target()));
// First ensure that the directory exists
mk_target(&target);
try!(mk_target(&target).to_cargo_error(format!("Could not create the target directory {}", target.display()), 1));
// compile
rustc(pkg.get_root(), &src, &target, deps(pkg, pkgs));
try!(rustc(pkg.get_root(), &src, &target, deps(pkg, pkgs)));
Ok(())
}
fn mk_target(target: &Path) -> io::IoResult<()> {
io::fs::mkdir_recursive(target, io::UserRWX)
}
fn rustc(root: &Path, src: &Path, target: &Path, deps: &[core::Package]) {
fn rustc(root: &Path, src: &Path, target: &Path, deps: &[core::Package]) -> CargoResult<()> {
let mut args = Vec::new();
build_base_args(&mut args, src, target);
build_deps_args(&mut args, deps);
util::process("rustc")
try!(util::process("rustc")
.cwd(root.clone())
.args(args.as_slice())
.exec();
.exec().to_cargo_error(format!("Couldn't execute rustc {}", args.connect(" ")), 1));
Ok(())
}
fn build_base_args(dst: &mut Args, src: &Path, target: &Path) {

View File

@ -12,16 +12,6 @@ impl PathSource {
pub fn new(paths: Vec<Path>) -> PathSource {
PathSource { paths: paths }
}
fn map<T>(&self, callback: |&Path| -> CargoResult<T>) -> CargoResult<Vec<T>> {
let mut ret = Vec::with_capacity(self.paths.len());
for path in self.paths.iter() {
ret.push(try!(callback(path)));
}
Ok(ret)
}
}
impl Source for PathSource {
@ -36,11 +26,11 @@ impl Source for PathSource {
}).collect())
}
fn download(&self, name_ver: &[NameVer]) -> CargoResult<()>{
fn download(&self, _: &[NameVer]) -> CargoResult<()>{
Ok(())
}
fn get(&self, packages: &[NameVer]) -> CargoResult<Vec<Package>> {
fn get(&self, _: &[NameVer]) -> CargoResult<Vec<Package>> {
Ok(self.paths.iter().filter_map(|path| {
match read_manifest(path) {
Ok(ref manifest) => Some(Package::from_manifest(manifest)),