re-implement by adding a few from_cwd args
authorDale Wijnand <dale.wijnand@gmail.com>
Tue, 10 Apr 2018 12:32:40 +0000 (13:32 +0100)
committerDale Wijnand <dale.wijnand@gmail.com>
Tue, 10 Apr 2018 12:32:40 +0000 (13:32 +0100)
src/bin/commands/install.rs
src/cargo/core/source/source_id.rs
src/cargo/ops/cargo_install.rs

index ae4e4bda26a4bae4f701dcf388e690021685b438..0acdd0269f90486a142a9205da6c97f1752c7e6a 100644 (file)
@@ -79,6 +79,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
         .unwrap_or_default()
         .collect::<Vec<_>>();
 
+    let mut from_cwd = false;
+
     let source = if let Some(url) = args.value_of("git") {
         let url = url.to_url()?;
         let gitref = if let Some(branch) = args.value_of("branch") {
@@ -94,7 +96,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
     } else if let Some(path) = args.value_of_path("path", config) {
         SourceId::for_path(&path)?
     } else if krates.is_empty() {
-        SourceId::from_cwd(config.cwd())?
+        from_cwd = true;
+        SourceId::for_path(config.cwd())?
     } else {
         SourceId::crates_io(config)?
     };
@@ -109,6 +112,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
             root,
             krates,
             &source,
+            from_cwd,
             version,
             &compile_opts,
             args.is_present("force"),
index 784107c213bdda607c92cc3c8452c3cdc776eb39..174a3653113ede50c3df4c24eef10be1e09cc5c6 100644 (file)
@@ -34,7 +34,6 @@ struct SourceIdInner {
     precise: Option<String>,
     /// Name of the registry source for alternative registries
     name: Option<String>,
-    from_cwd: bool,
 }
 
 /// The possible kinds of code source. Along with SourceIdInner this fully defines the
@@ -76,7 +75,6 @@ impl SourceId {
                 url,
                 precise: None,
                 name: None,
-                from_cwd: false,
             }),
         };
         Ok(source_id)
@@ -167,21 +165,6 @@ impl SourceId {
         SourceId::new(Kind::Directory, url)
     }
 
-    /// Create a SourceId from the current working directory filesystem path.
-    ///
-    /// Pass absolute path
-    pub fn from_cwd(path: &Path) -> CargoResult<SourceId> {
-        let source_id = SourceId::for_path(path)?;
-        let source_id = Arc::try_unwrap(source_id.inner)
-            .map_err(|_| format_err!("failed to create SourceId from cwd `{}`", path.display()))?;
-        Ok(SourceId {
-            inner: Arc::new(SourceIdInner {
-                from_cwd: true,
-                ..source_id
-            }),
-        })
-    }
-
     /// Returns the `SourceId` corresponding to the main repository.
     ///
     /// This is the main cargo registry by default, but it can be overridden in
@@ -217,7 +200,6 @@ impl SourceId {
                 url,
                 precise: None,
                 name: Some(key.to_string()),
-                from_cwd: false,
             }),
         })
     }
@@ -257,11 +239,6 @@ impl SourceId {
         }
     }
 
-    /// Is this source from the current working directory
-    pub fn is_from_cwd(&self) -> bool {
-        self.inner.from_cwd
-    }
-
     /// Creates an implementation of `Source` corresponding to this ID.
     pub fn load<'a>(&self, config: &'a Config) -> CargoResult<Box<super::Source + 'a>> {
         trace!("loading SourceId; {}", self);
index 2cd7feb32ea4ef44eb06a551bdaac3e77cb02ef4..9984c3952e162c512a0fcdbde4116f0772d1a718 100644 (file)
@@ -57,6 +57,7 @@ pub fn install(
     root: Option<&str>,
     krates: Vec<&str>,
     source_id: &SourceId,
+    from_cwd: bool,
     vers: Option<&str>,
     opts: &ops::CompileOptions,
     force: bool,
@@ -70,6 +71,7 @@ pub fn install(
             &map,
             krates.into_iter().next(),
             source_id,
+            from_cwd,
             vers,
             opts,
             force,
@@ -88,6 +90,7 @@ pub fn install(
                 &map,
                 Some(krate),
                 source_id,
+                from_cwd,
                 vers,
                 opts,
                 force,
@@ -149,6 +152,7 @@ fn install_one(
     map: &SourceConfigMap,
     krate: Option<&str>,
     source_id: &SourceId,
+    from_cwd: bool,
     vers: Option<&str>,
     opts: &ops::CompileOptions,
     force: bool,
@@ -229,7 +233,7 @@ fn install_one(
     };
     let pkg = ws.current()?;
 
-    if source_id.is_from_cwd() {
+    if from_cwd {
         match pkg.manifest().edition() {
             Edition::Edition2015 => (),
             Edition::Edition2018 => {