home = "0.3"
ignore = "0.3"
jobserver = "0.1.9"
+lazycell = "0.6"
libc = "0.2"
libgit2-sys = "0.6"
log = "0.4"
use semver::Version;
use serde::ser;
use toml;
+use lazycell::LazyCell;
use core::{Dependency, Manifest, PackageId, SourceId, Target};
use core::{Summary, SourceMap};
use ops;
-use util::{Config, LazyCell, internal, lev_distance};
+use util::{Config, internal, lev_distance};
use util::errors::{CargoResult, CargoResultExt};
/// Information about a package that is available somewhere in the file system.
extern crate home;
extern crate ignore;
extern crate jobserver;
+extern crate lazycell;
extern crate libc;
extern crate libgit2_sys;
extern crate num_cpus;
use std::collections::{HashMap, HashSet, BTreeSet};
use std::ffi::OsStr;
use std::path::PathBuf;
+
use semver::Version;
+use lazycell::LazyCell;
use core::{PackageId, Package, Target, TargetKind};
-use util::{self, CargoResult, Config, LazyCell, ProcessBuilder, process, join_paths};
+use util::{self, CargoResult, Config, ProcessBuilder, process, join_paths};
/// A structure returning the result of a compilation.
pub struct Compilation<'cfg> {
}
fn target_runner(&self) -> CargoResult<&Option<(PathBuf, Vec<String>)>> {
- self.target_runner.get_or_try_init(|| {
+ self.target_runner.try_borrow_with(|| {
let key = format!("target.{}.runner", self.target);
Ok(self.config.get_path_and_args(&key)?.map(|v| v.val))
})
use git2;
use hex;
use serde_json;
+use lazycell::LazyCell;
use core::{PackageId, SourceId};
use sources::git;
use sources::registry::{RegistryData, RegistryConfig, INDEX_LOCK, CRATE_TEMPLATE, VERSION_TEMPLATE};
use util::network;
-use util::{FileLock, Filesystem, LazyCell};
+use util::{FileLock, Filesystem};
use util::{Config, Sha256, ToUrl, Progress};
use util::errors::{CargoResult, CargoResultExt, HttpNot200};
}
fn repo(&self) -> CargoResult<&git2::Repository> {
- self.repo.get_or_try_init(|| {
+ self.repo.try_borrow_with(|| {
let path = self.index_path.clone().into_path_unlocked();
// Fast path without a lock
use jobserver;
use serde::{Serialize, Serializer};
use toml;
+use lazycell::LazyCell;
use core::shell::Verbosity;
use core::{Shell, CliUnstable};
use util::errors::{CargoResult, CargoResultExt, CargoError, internal};
use util::paths;
use util::toml as cargo_toml;
-use util::{Filesystem, LazyCell};
+use util::Filesystem;
use self::ConfigValue as CV;
/// Get the path to the `rustdoc` executable
pub fn rustdoc(&self) -> CargoResult<&Path> {
- self.rustdoc.get_or_try_init(|| self.get_tool("rustdoc")).map(AsRef::as_ref)
+ self.rustdoc.try_borrow_with(|| self.get_tool("rustdoc")).map(AsRef::as_ref)
}
/// Get the path to the `rustc` executable
pub fn rustc(&self) -> CargoResult<&Rustc> {
- self.rustc.get_or_try_init(|| Rustc::new(self.get_tool("rustc")?,
+ self.rustc.try_borrow_with(|| Rustc::new(self.get_tool("rustc")?,
self.maybe_get_tool("rustc_wrapper")?))
}
/// Get the path to the `cargo` executable
pub fn cargo_exe(&self) -> CargoResult<&Path> {
- self.cargo_exe.get_or_try_init(|| {
+ self.cargo_exe.try_borrow_with(|| {
fn from_current_exe() -> CargoResult<PathBuf> {
// Try fetching the path to `cargo` using env::current_exe().
// The method varies per operating system and might fail; in particular,
}
pub fn values(&self) -> CargoResult<&HashMap<String, ConfigValue>> {
- self.values.get_or_try_init(|| self.load_values())
+ self.values.try_borrow_with(|| self.load_values())
}
pub fn set_values(&self, values: HashMap<String, ConfigValue>) -> CargoResult<()> {
}
pub fn http(&self) -> CargoResult<&RefCell<Easy>> {
- let http = self.easy.get_or_try_init(|| {
+ let http = self.easy.try_borrow_with(|| {
ops::http_handle(self).map(RefCell::new)
})?;
{
+++ /dev/null
-//! A lazily fill Cell, but with frozen contents.
-//!
-//! With a `RefCell`, the inner contents cannot be borrowed for the lifetime of
-//! the entire object, but only of the borrows returned. A `LazyCell` is a
-//! variation on `RefCell` which allows borrows tied to the lifetime of the
-//! outer object.
-//!
-//! The limitation of a `LazyCell` is that after initialized, it can never be
-//! modified unless you've otherwise got a `&mut` reference
-
-use std::cell::UnsafeCell;
-
-#[derive(Debug)]
-pub struct LazyCell<T> {
- inner: UnsafeCell<Option<T>>,
-}
-
-impl<T> LazyCell<T> {
- /// Creates a new empty lazy cell.
- pub fn new() -> LazyCell<T> {
- LazyCell { inner: UnsafeCell::new(None) }
- }
-
- /// Put a value into this cell.
- ///
- /// This function will fail if the cell has already been filled.
- pub fn fill(&self, t: T) -> Result<(), T> {
- unsafe {
- let slot = self.inner.get();
- if (*slot).is_none() {
- *slot = Some(t);
- Ok(())
- } else {
- Err(t)
- }
- }
- }
-
- /// Borrows the contents of this lazy cell for the duration of the cell
- /// itself.
- ///
- /// This function will return `Some` if the cell has been previously
- /// initialized, and `None` if it has not yet been initialized.
- pub fn borrow(&self) -> Option<&T> {
- unsafe {
- (*self.inner.get()).as_ref()
- }
- }
-
- /// Same as `borrow`, but the mutable version
- pub fn borrow_mut(&mut self) -> Option<&mut T> {
- unsafe {
- (*self.inner.get()).as_mut()
- }
- }
-
- /// Consumes this `LazyCell`, returning the underlying value.
- #[allow(unused_unsafe)]
- pub fn into_inner(self) -> Option<T> {
- unsafe {
- self.inner.into_inner()
- }
- }
-
- /// Borrows the contents of this lazy cell, initializing it if necessary.
- pub fn get_or_try_init<Error, F>(&self, init: F) -> Result<&T, Error>
- where F: FnOnce() -> Result<T, Error>
- {
- if self.borrow().is_none() && self.fill(init()?).is_err() {
- unreachable!();
- }
- Ok(self.borrow().unwrap())
- }
-}
pub use self::flock::{FileLock, Filesystem};
pub use self::graph::Graph;
pub use self::hex::{to_hex, short_hash, hash_u64};
-pub use self::lazy_cell::LazyCell;
pub use self::lev_distance::{lev_distance};
pub use self::paths::{join_paths, path2bytes, bytes2path, dylib_path};
pub use self::paths::{normalize_path, dylib_path_envvar, without_prefix};
mod rustc;
mod sha256;
mod vcs;
-mod lazy_cell;
mod flock;
mod read2;
mod progress;