fn generate_targets<'a>(pkg: &'a Package,
                        profiles: &'a Profiles,
                        mode: CompileMode,
                        filter: &CompileFilter,
                        release: bool)
                        -> CargoResult<Vec<(&'a Target, &'a Profile)>> {
    let build = if release {&profiles.release} else {&profiles.dev};
    let test = if release {&profiles.bench} else {&profiles.test};
    let profile = match mode {
        CompileMode::Test => test,
        CompileMode::Bench => &profiles.bench,
        CompileMode::Build => build,
        CompileMode::Doc { .. } => &profiles.doc,
    };
    match *filter {
        CompileFilter::Everything => {
            match mode {
                CompileMode::Bench => {
                    Ok(pkg.targets().iter().filter(|t| t.benched()).map(|t| {
                        (t, profile)
                    }).collect::<Vec<_>>())
                }
                CompileMode::Test => {
                    let mut base = pkg.targets().iter().filter(|t| {
                        t.tested()
                    }).map(|t| {
                        (t, if t.is_example() {build} else {profile})
                    }).collect::<Vec<_>>();

                    // Always compile the library if we're testing everything as
                    // it'll be needed for doctests
                    if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
                        if t.doctested() {
                            base.push((t, build));
                        }
                    }
                    Ok(base)
                }
                CompileMode::Build => {
                    Ok(pkg.targets().iter().filter(|t| {
                        t.is_bin() || t.is_lib()
                    }).map(|t| (t, profile)).collect())
                }
                CompileMode::Doc { .. } => {
                    Ok(pkg.targets().iter().filter(|t| t.documented())
                          .map(|t| (t, profile)).collect())
                }
            }
        }
        CompileFilter::Only { lib, bins, examples, tests, benches } => {
            let mut targets = Vec::new();

            if lib {
                if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
                    targets.push((t, profile));
                } else {
                    bail!("no library targets found")
                }
            }

            {
                let mut find = |names: &[String], desc, kind, profile| {
                    for name in names {
                        let target = pkg.targets().iter().find(|t| {
                            t.name() == *name && *t.kind() == kind
                        });
                        let t = match target {
                            Some(t) => t,
                            None => bail!("no {} target named `{}`", desc, name),
                        };
                        debug!("found {} `{}`", desc, name);
                        targets.push((t, profile));
                    }
                    Ok(())
                };
                try!(find(bins, "bin", TargetKind::Bin, profile));
                try!(find(examples, "example", TargetKind::Example, build));
                try!(find(tests, "test", TargetKind::Test, test));
                try!(find(benches, "bench", TargetKind::Bench, &profiles.bench));
            }
            Ok(targets)
        }
    }
}
/// Given the configuration for a build, this function will generate all
/// target/profile combinations needed to be built.
Given the configuration for a build, this function will generate all
target/profile combinations needed to be built.
Given the configuration for a build this function will generate all target / profile combinations needed to be built .
fn generate_targets<'a>(pkg: &'a Package,
                        profiles: &'a Profiles,
                        mode: CompileMode,
                        filter: &CompileFilter,
                        release: bool)
                        -> CargoResult<Vec<(&'a Target, &'a Profile)>> {
    let build = if release {&profiles.release} else {&profiles.dev};
    let test = if release {&profiles.bench} else {&profiles.test};
    let profile = match mode {
        CompileMode::Test => test,
        CompileMode::Bench => &profiles.bench,
        CompileMode::Build => build,
        CompileMode::Doc { .. } => &profiles.doc,
    };
    match *filter {
        CompileFilter::Everything => {
            match mode {
                CompileMode::Bench => {
                    Ok(pkg.targets().iter().filter(|t| t.benched()).map(|t| {
                        (t, profile)
                    }).collect::<Vec<_>>())
                }
                CompileMode::Test => {
                    let mut base = pkg.targets().iter().filter(|t| {
                        t.tested()
                    }).map(|t| {
                        (t, if t.is_example() {build} else {profile})
                    }).collect::<Vec<_>>();
                    // Always compile the library if we're testing everything as
                    // it'll be needed for doctests
                    if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
                        if t.doctested() {
                            base.push((t, build));
                        }
                    }
                    Ok(base)
                }
                CompileMode::Build => {
                    Ok(pkg.targets().iter().filter(|t| {
                        t.is_bin() || t.is_lib()
                    }).map(|t| (t, profile)).collect())
                }
                CompileMode::Doc { .. } => {
                    Ok(pkg.targets().iter().filter(|t| t.documented())
                          .map(|t| (t, profile)).collect())
                }
            }
        }
        CompileFilter::Only { lib, bins, examples, tests, benches } => {
            let mut targets = Vec::new();
            if lib {
                if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
                    targets.push((t, profile));
                } else {
                    bail!("no library targets found")
                }
            }
            {
                let mut find = |names: &[String], desc, kind, profile| {
                    for name in names {
                        let target = pkg.targets().iter().find(|t| {
                            t.name() == *name && *t.kind() == kind
                        });
                        let t = match target {
                            Some(t) => t,
                            None => bail!("no {} target named `{}`", desc, name),
                        };
                        debug!("found {} `{}`", desc, name);
                        targets.push((t, profile));
                    }
                    Ok(())
                };
                try!(find(bins, "bin", TargetKind::Bin, profile));
                try!(find(examples, "example", TargetKind::Example, build));
                try!(find(tests, "test", TargetKind::Test, test));
                try!(find(benches, "bench", TargetKind::Bench, &profiles.bench));
            }
            Ok(targets)
        }
    }
}
fn generate_targets < ' a > ( pkg : & ' a Package , profiles : & ' a Profiles , mode : CompileMode , filter : & CompileFilter , release : bool ) -> CargoResult < Vec < ( & ' a Target , & ' a Profile ) > > { let build = if release { & profiles . release } else { & profiles . dev } ; let test = if release { & profiles . bench } else { & profiles . test } ; let profile = match mode { CompileMode :: Test => test , CompileMode :: Bench => & profiles . bench , CompileMode :: Build => build , CompileMode :: Doc { .. } => & profiles . doc , } ; match * filter { CompileFilter :: Everything => { match mode { CompileMode :: Bench => { Ok ( pkg . targets ( ) . iter ( ) . filter ( | t | t . benched ( ) ) . map ( | t | { ( t , profile ) } ) . collect :: < Vec < _ > > ( ) ) } CompileMode :: Test => { let mut base = pkg . targets ( ) . iter ( ) . filter ( | t | { t . tested ( ) } ) . map ( | t | { ( t , if t . is_example ( ) { build } else { profile } ) } ) . collect :: < Vec < _ > > ( ) ; // Always compile the library if we're testing everything as // it'll be needed for doctests if let Some ( t ) = pkg . targets ( ) . iter ( ) . find ( | t | t . is_lib ( ) ) { if t . doctested ( ) { base . push ( ( t , build ) ) ; } } Ok ( base ) } CompileMode :: Build => { Ok ( pkg . targets ( ) . iter ( ) . filter ( | t | { t . is_bin ( ) || t . is_lib ( ) } ) . map ( | t | ( t , profile ) ) . collect ( ) ) } CompileMode :: Doc { .. } => { Ok ( pkg . targets ( ) . iter ( ) . filter ( | t | t . documented ( ) ) . map ( | t | ( t , profile ) ) . collect ( ) ) } } } CompileFilter :: Only { lib , bins , examples , tests , benches } => { let mut targets = Vec :: new ( ) ; if lib { if let Some ( t ) = pkg . targets ( ) . iter ( ) . find ( | t | t . is_lib ( ) ) { targets . push ( ( t , profile ) ) ; } else { bail ! ( " " ) } } { let mut find = | names : & [ String ] , desc , kind , profile | { for name in names { let target = pkg . targets ( ) . iter ( ) . find ( | t | { t . name ( ) == * name && * t . kind ( ) == kind } ) ; let t = match target { Some ( t ) => t , None => bail ! ( " " desc name ) , } ; debug ! ( " " desc name ) ; targets . push ( ( t , profile ) ) ; } Ok ( ( ) ) } ; try ! ( find ( bins " " TargetKind Bin profile ) ) ; try ! ( find ( examples " " TargetKind Example build ) ) ; try ! ( find ( tests " " TargetKind Test test ) ) ; try ! ( find ( benches " " TargetKind Bench profiles bench ) ) ; } Ok ( targets ) } } }
Given the configuration for a build, this function will generate all
target/profile combinations needed to be built.
Given the configuration for a build this function will generate all target / profile combinations needed to be built .
pkg
&'a Package
profiles
&'a Profiles
mode
CompileMode
filter
&CompileFilter
release
bool
pkg
&'a Package
profiles
&'a Profiles
mode
CompileMode
filter
&CompileFilter
release
bool