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

Conventions #4259

Merged
merged 33 commits into from
Jul 11, 2017
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9671c68
Make `Layout` a private implementation detail of toml
matklad Jul 2, 2017
3753129
Simplify
matklad Jul 2, 2017
6c8eedd
Simplify
matklad Jul 2, 2017
199dec8
Refactor: virtual manifest does not need layout
matklad Jul 2, 2017
17e33e9
Fix typo
matklad Jul 2, 2017
498a8b4
Move code for inferring build targets to a separate file
matklad Jul 8, 2017
d05e0d4
Make layout private to targets
matklad Jul 8, 2017
5738920
Restructure code
matklad Jul 8, 2017
91889a3
Superfluous pub
matklad Jul 8, 2017
6aeed24
Unify naming for `package_root`
matklad Jul 8, 2017
3193db6
Don't store root in the layout
matklad Jul 8, 2017
1be4139
Extract clean_library function
matklad Jul 8, 2017
7c9ca7c
Extract clean_bins function
matklad Jul 8, 2017
c932a34
Extract clean_examples function
matklad Jul 8, 2017
9e1d600
Extract clean_tests function
matklad Jul 8, 2017
d4befbb
Extract clean_benches function
matklad Jul 8, 2017
c81fdf2
Jettison normalize function and its closures!
matklad Jul 8, 2017
847a8d8
Reduce code duplication & fix error messages
matklad Jul 8, 2017
7f64a9e
Unify parameter order
matklad Jul 8, 2017
31d64e1
Unify error message formatting
matklad Jul 8, 2017
aee9c7b
Reduce code duplication in validation
matklad Jul 8, 2017
ed64333
Infer benches, tests and examples without layout
matklad Jul 9, 2017
5c088f6
Specify conventions for benches, examples and tests only once
matklad Jul 9, 2017
bfec42f
Warn about legacy library paths
matklad Jul 9, 2017
0d6c9a9
Merge duplicate tests
matklad Jul 9, 2017
cce5b3d
Fix tests
matklad Jul 9, 2017
c161ee1
Remove Layout structure
matklad Jul 9, 2017
0ae2b97
Warn about obsolete conventions for binary names
matklad Jul 9, 2017
4e9bf06
Use the same logic for benches
matklad Jul 9, 2017
d80f574
Fix more tests
matklad Jul 9, 2017
e2bc862
Use Path::join instead of `/`
matklad Jul 9, 2017
a1e1dcb
Simplify
matklad Jul 9, 2017
71e6629
Rearrange code
matklad Jul 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make Layout a private implementation detail of toml
matklad committed Jul 8, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9671c682011cf0635ae0effb40abc4633fbed4de
7 changes: 3 additions & 4 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@ use glob::glob;

use core::{Package, VirtualManifest, EitherManifest, SourceId};
use core::{PackageIdSpec, Dependency, Profile, Profiles};
use ops;
use util::{Config, Filesystem};
use util::errors::{CargoResult, CargoResultExt};
use util::paths;
use util::toml::read_manifest;

/// The core abstraction in Cargo for working with a workspace of crates.
///
@@ -594,9 +594,8 @@ impl<'cfg> Packages<'cfg> {
Entry::Occupied(e) => Ok(e.into_mut()),
Entry::Vacant(v) => {
let source_id = SourceId::for_path(key)?;
let pair = ops::read_manifest(&manifest_path, &source_id,
self.config)?;
let (manifest, _nested_paths) = pair;
let (manifest, _nested_paths) =
read_manifest(&manifest_path, &source_id, self.config)?;
Ok(v.insert(match manifest {
EitherManifest::Real(manifest) => {
MaybePackage::Package(Package::new(manifest,
17 changes: 2 additions & 15 deletions src/cargo/ops/cargo_read_manifest.rs
Original file line number Diff line number Diff line change
@@ -4,23 +4,10 @@ use std::io;
use std::path::{Path, PathBuf};

use core::{Package, SourceId, PackageId, EitherManifest};
use util::{self, paths, Config};
use util::{self, Config};
use util::errors::{CargoResult, CargoResultExt};
use util::important_paths::find_project_manifest_exact;
use util::toml::Layout;

pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
trace!("read_package; path={}; source-id={}", path.display(), source_id);
let contents = paths::read(path)?;

let layout = Layout::from_project_path(path.parent().unwrap());
let root = layout.root.clone();
util::toml::to_manifest(&contents, source_id, layout, config).chain_err(|| {
format!("failed to parse manifest at `{}`",
root.join("Cargo.toml").display())
})
}
use util::toml::read_manifest;

pub fn read_package(path: &Path, source_id: &SourceId, config: &Config)
-> CargoResult<(Package, Vec<PathBuf>)> {
2 changes: 1 addition & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use self::cargo_clean::{clean, CleanOptions};
pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions};
pub use self::cargo_compile::{CompileFilter, CompileMode, MessageFormat, Packages};
pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
pub use self::cargo_read_manifest::{read_package, read_packages};
pub use self::cargo_rustc::{compile_targets, Compilation, Kind, Unit};
pub use self::cargo_rustc::{Context, is_bad_artifact_name};
pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
36 changes: 23 additions & 13 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
@@ -18,16 +18,13 @@ use core::dependency::{Kind, Platform};
use core::manifest::{LibKind, Profile, ManifestMetadata};
use ops::is_bad_artifact_name;
use sources::CRATES_IO;
use util::paths;
use util::{self, ToUrl, Config};
use util::errors::{CargoError, CargoResult, CargoResultExt};

/// Representation of the projects file layout.
///
/// This structure is used to hold references to all project files that are relevant to cargo.

#[derive(Clone)]
pub struct Layout {
pub root: PathBuf,
/// Implicit Cargo targets, defined by conventions.
struct Layout {
root: PathBuf,
lib: Option<PathBuf>,
bins: Vec<PathBuf>,
examples: Vec<PathBuf>,
@@ -38,7 +35,7 @@ pub struct Layout {
impl Layout {
/// Returns a new `Layout` for a given root path.
/// The `root_path` represents the directory that contains the `Cargo.toml` file.
pub fn from_project_path(root_path: &Path) -> Layout {
fn from_project_path(root_path: &Path) -> Layout {
let mut lib = None;
let mut bins = vec![];
let mut examples = vec![];
@@ -114,11 +111,24 @@ fn try_add_files(files: &mut Vec<PathBuf>, root: PathBuf) {
/* else just don't add anything if the directory doesn't exist, etc. */
}

pub fn to_manifest(contents: &str,
source_id: &SourceId,
layout: Layout,
config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
trace!("read_manifest; path={}; source-id={}", path.display(), source_id);
let contents = paths::read(path)?;

let layout = Layout::from_project_path(path.parent().unwrap());
let root = layout.root.clone();
to_manifest(&contents, source_id, layout, config).chain_err(|| {
format!("failed to parse manifest at `{}`",
root.join("Cargo.toml").display())
})
}

fn to_manifest(contents: &str,
source_id: &SourceId,
layout: Layout,
config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
let manifest = layout.root.join("Cargo.toml");
let manifest = match util::without_prefix(&manifest, config.cwd()) {
Some(path) => path.to_path_buf(),