Skip to content

Commit

Permalink
Initial stab for async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed May 18, 2017
1 parent d426d7e commit 927fe00
Show file tree
Hide file tree
Showing 16 changed files with 759 additions and 731 deletions.
57 changes: 49 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ error-chain = { version = "0.7.2", default-features = false }
fern = "0.3.5"
filetime = "0.1"
futures = "0.1.11"
futures-await = { path = "../futures-await" }
futures-cpupool = "0.1"
hyper = { git = "https://github.com/hyperium/hyper", optional = true }
hyper-tls = { git = "https://github.com/hyperium/hyper-tls", optional = true }
Expand Down Expand Up @@ -72,4 +73,9 @@ unstable = []
[profile.release]
debug = true

[profile.dev]
debug = false
[profile.test]
debug = false

[workspace]
11 changes: 5 additions & 6 deletions src/cache/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use simples3::{
};
use std::env;
use std::io;
use std::rc::Rc;
use std::time::{Instant, Duration};
use tokio_core::reactor::Handle;

Expand All @@ -38,7 +37,7 @@ use errors::*;
/// A cache that stores entries in Amazon S3.
pub struct S3Cache {
/// The S3 bucket.
bucket: Rc<Bucket>,
bucket: Bucket,
/// Credentials provider.
provider: AutoRefreshingProvider<ChainProvider>,
}
Expand All @@ -56,7 +55,7 @@ impl S3Cache {
];
let provider = AutoRefreshingProvider::new(ChainProvider::with_profile_providers(profile_providers, handle));
//TODO: configurable SSL
let bucket = Rc::new(Bucket::new(bucket, endpoint, Ssl::No, handle));
let bucket = Bucket::new(bucket, endpoint, Ssl::No, handle);
Ok(S3Cache {
bucket: bucket,
provider: provider,
Expand All @@ -71,7 +70,7 @@ fn normalize_key(key: &str) -> String {
impl Storage for S3Cache {
fn get(&self, key: &str) -> SFuture<Cache> {
let key = normalize_key(key);
Box::new(self.bucket.get(&key).then(|result| {
Box::new(self.bucket.clone().get(key).then(|result| {
match result {
Ok(data) => {
let hit = CacheRead::from(io::Cursor::new(data))?;
Expand All @@ -92,13 +91,13 @@ impl Storage for S3Cache {
Ok(data) => data,
Err(e) => return future::err(e.into()).boxed(),
};
let credentials = self.provider.credentials().chain_err(|| {
let credentials = self.provider.clone().credentials().chain_err(|| {
"failed to get AWS credentials"
});

let bucket = self.bucket.clone();
let response = credentials.and_then(move |credentials| {
bucket.put(&key, data, &credentials).chain_err(|| {
bucket.put(key, data, credentials).chain_err(|| {
"failed to put cache entry in s3"
})
});
Expand Down
35 changes: 21 additions & 14 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use compiler::{Cacheable, Compiler, CompilerArguments, CompilerHasher, CompilerKind, Compilation, HashResult};
use futures::Future;
use futures::prelude::*;
use futures_cpupool::CpuPool;
use mock_command::CommandCreatorSync;
use std::borrow::Cow;
Expand Down Expand Up @@ -131,15 +131,17 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + 'static {
impl <I> CCompiler<I>
where I: CCompilerImpl,
{
pub fn new(compiler: I, executable: PathBuf, pool: &CpuPool) -> SFuture<CCompiler<I>>
#[async]
pub fn new(compiler: I,
executable: PathBuf,
pool: CpuPool) -> Result<CCompiler<I>>
{
Box::new(Digest::file(executable.clone(), &pool).map(move |digest| {
CCompiler {
executable: executable,
executable_digest: digest,
compiler: compiler,
}
}))
let digest = await!(Digest::file(executable.clone(), &pool))?;
Ok(CCompiler {
executable: executable,
executable_digest: digest,
compiler: compiler,
})
}
}

Expand Down Expand Up @@ -172,15 +174,20 @@ impl<T, I> CompilerHasher<T> for CCompilerHasher<I>
I: CCompilerImpl,
{
fn generate_hash_key(self: Box<Self>,
creator: &T,
cwd: &Path,
env_vars: &[(OsString, OsString)],
pool: &CpuPool)
creator: T,
cwd: PathBuf,
env_vars: Vec<(OsString, OsString)>,
pool: CpuPool)
-> SFuture<HashResult<T>>
{
let me = *self;
let CCompilerHasher { parsed_args, executable, executable_digest, compiler } = me;
let result = compiler.preprocess(creator, &executable, &parsed_args, cwd, env_vars, pool);
let result = compiler.preprocess(&creator,
&executable,
&parsed_args,
&cwd,
&env_vars,
&pool);
let out_pretty = parsed_args.output_pretty().into_owned();
let env_vars = env_vars.to_vec();
let result = result.map_err(move |e| {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn compile<T>(creator: &T,
Some(name) => name,
None => return future::err("missing input filename".into()).boxed(),
};
write_temp_file(pool, filename.as_ref(), preprocessor_result.stdout)
write_temp_file(pool.clone(), filename.into(), preprocessor_result.stdout)
};
let input = parsed_args.input.clone();
let out_file = match parsed_args.outputs.get("obj") {
Expand Down
Loading

0 comments on commit 927fe00

Please sign in to comment.