Skip to content

Commit

Permalink
Implement features
Browse files Browse the repository at this point in the history
This feature was outlined in rust-lang#385 [1], and documentation has been included as
part of this commit.

[1]: rust-lang#385 (comment)
  • Loading branch information
alexcrichton committed Sep 23, 2014
1 parent a54cb70 commit 2b46d03
Show file tree
Hide file tree
Showing 23 changed files with 1,039 additions and 201 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ $(TARGET_ROOT)/snapshot/bin/cargo$(X): src/snapshots.txt

# === Tests

test: test-unit style no-exes $(foreach target,$(CFG_TARGET),test-unit-$(target))
test: style no-exes $(foreach target,$(CFG_TARGET),test-unit-$(target))

style:
sh tests/check-style.sh
Expand Down
6 changes: 5 additions & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Options:
-h, --help Print this message
--no-run Compile, but don't run benchmarks
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose Use verbose output
Expand All @@ -24,7 +26,7 @@ All of the trailing arguments are passed to the benchmark binaries generated
for filtering benchmarks and generally providing options configuring how they
run.
", flag_jobs: Option<uint>, flag_target: Option<String>,
flag_manifest_path: Option<String>)
flag_manifest_path: Option<String>, flag_features: Vec<String>)

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
Expand All @@ -39,6 +41,8 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| s.as_slice()),
dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ Options:
-h, --help Print this message
-j N, --jobs N The number of jobs to run in parallel
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
-u, --update-remotes Deprecated option, use `cargo update` instead
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
", flag_jobs: Option<uint>, flag_target: Option<String>,
flag_manifest_path: Option<String>)
flag_manifest_path: Option<String>, flag_features: Vec<String>)

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-build; args={}", os::args());
Expand All @@ -43,6 +45,8 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| t.as_slice()),
dev_deps: false,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
};

ops::compile(&root, &mut opts).map(|_| None).map_err(|err| {
Expand Down
7 changes: 6 additions & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ Options:
-h, --help Print this message
--no-deps Don't build documentation for dependencies
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
-u, --update-remotes Deprecated option, use `cargo update` instead
--manifest-path PATH Path to the manifest to document
-v, --verbose Use verbose output
By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
", flag_jobs: Option<uint>,
flag_manifest_path: Option<String>)
flag_manifest_path: Option<String>,
flag_features: Vec<String>)

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
shell.set_verbose(options.flag_verbose);
Expand All @@ -38,6 +41,8 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
jobs: options.flag_jobs,
target: None,
dev_deps: false,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ Options:
-h, --help Print this message
-j N, --jobs N The number of jobs to run in parallel
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
-u, --update-remotes Deprecated option, use `cargo update` instead
--manifest-path PATH Path to the manifest to execute
-v, --verbose Use verbose output
All of the trailing arguments are passed as to the binary to run.
", flag_jobs: Option<uint>, flag_target: Option<String>,
flag_manifest_path: Option<String>)
flag_manifest_path: Option<String>, flag_features: Vec<String>)

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
shell.set_verbose(options.flag_verbose);
Expand All @@ -36,6 +38,8 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| t.as_slice()),
dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
};

let err = try!(ops::run(&root, &mut compile_opts,
Expand Down
6 changes: 5 additions & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Options:
-h, --help Print this message
--no-run Compile, but don't run tests
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
-u, --update-remotes Deprecated option, use `cargo update` instead
--manifest-path PATH Path to the manifest to build tests for
Expand All @@ -24,7 +26,7 @@ Options:
All of the trailing arguments are passed to the test binaries generated for
filtering tests and generally providing options configuring how they run.
", flag_jobs: Option<uint>, flag_target: Option<String>,
flag_manifest_path: Option<String>)
flag_manifest_path: Option<String>, flag_features: Vec<String>)

pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
Expand All @@ -39,6 +41,8 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| s.as_slice()),
dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
},
};

Expand Down
43 changes: 32 additions & 11 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ pub struct Dependency {
req: VersionReq,
transitive: bool,
only_match_name: bool,

optional: bool,
default_features: bool,
features: Vec<String>,
}

impl Dependency {
pub fn parse(name: &str, version: Option<&str>,
pub fn parse(name: &str,
version: Option<&str>,
source_id: &SourceId) -> CargoResult<Dependency> {
let version = match version {
Some(v) => try!(VersionReq::parse(v)),
None => VersionReq::any()
};

Ok(Dependency {
name: name.to_string(),
source_id: source_id.clone(),
req: version,
transitive: true,
only_match_name: false,
req: version,
.. Dependency::new_override(name, source_id)
})
}

Expand All @@ -35,6 +38,9 @@ impl Dependency {
req: VersionReq::any(),
transitive: true,
only_match_name: true,
optional: false,
features: Vec::new(),
default_features: true,
}
}

Expand All @@ -50,16 +56,31 @@ impl Dependency {
&self.source_id
}

pub fn as_dev(&self) -> Dependency {
let mut dep = self.clone();
dep.transitive = false;
dep
pub fn transitive(mut self, transitive: bool) -> Dependency {
self.transitive = transitive;
self
}

pub fn is_transitive(&self) -> bool {
self.transitive
pub fn features(mut self, features: Vec<String>) -> Dependency {
self.features = features;
self
}

pub fn default_features(mut self, default_features: bool) -> Dependency {
self.default_features = default_features;
self
}

pub fn optional(mut self, optional: bool) -> Dependency {
self.optional = optional;
self
}

pub fn is_transitive(&self) -> bool { self.transitive }
pub fn is_optional(&self) -> bool { self.optional }
pub fn uses_default_features(&self) -> bool { self.default_features }
pub fn get_features(&self) -> &[String] { self.features.as_slice() }

pub fn matches(&self, sum: &Summary) -> bool {
debug!("matches; self={}; summary={}", self, sum);
debug!(" a={}; b={}", self.source_id, sum.get_source_id());
Expand Down
14 changes: 8 additions & 6 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::hash;
use std::fmt::{mod, Show, Formatter};

use semver::Version;
use serialize::{Encoder,Encodable};

use core::source::SourceId;
use core::{
Dependency,
Expand Down Expand Up @@ -333,15 +335,15 @@ impl Show for Target {


impl Manifest {
pub fn new(summary: &Summary, targets: &[Target],
target_dir: &Path, doc_dir: &Path, sources: Vec<SourceId>,
pub fn new(summary: Summary, targets: Vec<Target>,
target_dir: Path, doc_dir: Path, sources: Vec<SourceId>,
build: Vec<String>, exclude: Vec<String>) -> Manifest {
Manifest {
summary: summary.clone(),
summary: summary,
authors: Vec::new(),
targets: targets.to_vec(),
target_dir: target_dir.clone(),
doc_dir: doc_dir.clone(),
targets: targets,
target_dir: target_dir,
doc_dir: doc_dir,
sources: sources,
build: build,
warnings: Vec::new(),
Expand Down
Loading

1 comment on commit 2b46d03

@alexcrichton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=wycats

Please sign in to comment.