Skip to content

Commit

Permalink
Use system rustfmt instead of fixed binary (denoland#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 31, 2019
1 parent b3541c3 commit 3971dcf
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 235 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ install:
"$env:RUSTUP_HOME\tmp",
"$env:RUSTUP_HOME\toolchains\stable-x86_64-pc-windows-msvc\share\doc"
)
Exec { rustup component add clippy }
}
Exec { rustup component add clippy }
Exec { rustup component add rustfmt }
# Log installed Node.js version + processor architecture.
- node -p "`Node ${process.version} ${process.arch}`"
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ install:
curl -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain $RUST_VERSION
rustup default $RUST_VERSION
rustup component add clippy
fi
rustup component add clippy
rustup component add rustfmt
rustc --version
cargo --version
- |-
Expand Down
38 changes: 20 additions & 18 deletions cli/compilers/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ impl CompilerConfig {
DenoError::new(
ErrorKind::InvalidInput,
"Compiler config is not a valid JSON".to_string(),
).into(),
)
.into(),
),
}
}
Expand Down Expand Up @@ -153,15 +154,15 @@ fn req(
) -> Buf {
let j = match (compiler_config.path, compiler_config.content) {
(Some(config_path), Some(config_data)) => json!({
"rootNames": root_names,
"bundle": bundle,
"configPath": config_path,
"config": str::from_utf8(&config_data).unwrap(),
}),
"rootNames": root_names,
"bundle": bundle,
"configPath": config_path,
"config": str::from_utf8(&config_data).unwrap(),
}),
_ => json!({
"rootNames": root_names,
"bundle": bundle,
}),
"rootNames": root_names,
"bundle": bundle,
}),
};

j.to_string().into_boxed_str().into_boxed_bytes()
Expand Down Expand Up @@ -410,7 +411,8 @@ impl TsCompiler {
}

Ok(())
}).and_then(move |_| {
})
.and_then(move |_| {
// if we are this far it means compilation was successful and we can
// load compiled filed from disk
state_
Expand All @@ -420,12 +422,14 @@ impl TsCompiler {
// TODO: this situation shouldn't happen
panic!("Expected to find compiled file: {}", e)
})
}).and_then(move |compiled_module| {
})
.and_then(move |compiled_module| {
// Explicit drop to keep reference alive until future completes.
drop(compiling_job);

Ok(compiled_module)
}).then(move |r| {
})
.then(move |r| {
debug!(">>>>> compile_sync END");
// TODO(ry) do this in worker's destructor.
// resource.close();
Expand Down Expand Up @@ -685,12 +689,10 @@ mod tests {
.ts_compiler
.compile_sync(mock_state.clone(), &out)
.unwrap();
assert!(
compiled
.code
.as_bytes()
.starts_with("console.log(\"Hello World\");".as_bytes())
);
assert!(compiled
.code
.as_bytes()
.starts_with("console.log(\"Hello World\");".as_bytes()));
})
}

Expand Down
8 changes: 6 additions & 2 deletions cli/dispatch_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ mod ops {
debug!("read rid={}", rid);
let zero_copy = match zero_copy {
None => {
return Box::new(futures::future::err(deno_error::no_buffer_specified()))
return Box::new(
futures::future::err(deno_error::no_buffer_specified()),
)
}
Some(buf) => buf,
};
Expand All @@ -155,7 +157,9 @@ mod ops {
debug!("write rid={}", rid);
let zero_copy = match zero_copy {
None => {
return Box::new(futures::future::err(deno_error::no_buffer_specified()))
return Box::new(
futures::future::err(deno_error::no_buffer_specified()),
)
}
Some(buf) => buf,
};
Expand Down
29 changes: 17 additions & 12 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ impl SourceFileFetcher {
&module_url,
self.use_disk_cache,
self.no_remote_fetch,
).then(move |result| {
)
.then(move |result| {
let mut out = result.map_err(|err| {
if err.kind() == ErrorKind::NotFound {
// For NotFound, change the message to something better.
DenoError::new(
ErrorKind::NotFound,
format!("Cannot resolve module \"{}\"", module_url.to_string()),
).into()
)
.into()
} else {
err
}
Expand Down Expand Up @@ -329,7 +331,8 @@ impl SourceFileFetcher {
"cannot find remote file '{}' in cache",
module_url.to_string()
),
).into(),
)
.into(),
));
}

Expand All @@ -353,7 +356,8 @@ impl SourceFileFetcher {
&module_url,
None,
Some(new_module_url.to_string()),
).unwrap();
)
.unwrap();

// Explicit drop to keep reference alive until future completes.
drop(download_job);
Expand All @@ -373,7 +377,8 @@ impl SourceFileFetcher {
&module_url,
maybe_content_type.clone(),
None,
).unwrap();
)
.unwrap();

dir.save_source_code(&module_url, &source).unwrap();

Expand Down Expand Up @@ -651,7 +656,8 @@ mod tests {
Progress::new(),
true,
false,
).expect("setup fail")
)
.expect("setup fail")
}

fn test_setup() -> (TempDir, SourceFileFetcher) {
Expand Down Expand Up @@ -771,11 +777,9 @@ mod tests {
// If get_source_file does not call remote, this should be JavaScript
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
assert_eq!(&(r3.media_type), &msg::MediaType::Json);
assert!(
fs::read_to_string(&headers_file_name)
.unwrap()
.contains("application/json")
);
assert!(fs::read_to_string(&headers_file_name)
.unwrap()
.contains("application/json"));

// let's create fresh instance of DenoDir (simulating another freshh Deno process)
// and don't use cache
Expand Down Expand Up @@ -865,7 +869,8 @@ mod tests {
tokio_util::init(|| {
let specifier = ModuleSpecifier::resolve_url(
"http://localhost:4545/tests/subdir/mismatch_ext.ts",
).unwrap();
)
.unwrap();
let headers_file_name = fetcher.deps_cache.location.join(
fetcher.deps_cache.get_cache_filename_with_extension(
specifier.as_url(),
Expand Down
26 changes: 17 additions & 9 deletions cli/flags.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::fs as deno_fs;
use clap::App;
use clap::AppSettings;
use clap::Arg;
use clap::ArgMatches;
use clap::Shell;
use clap::SubCommand;
use crate::fs as deno_fs;
use deno::ModuleSpecifier;
use log::Level;
use std;
Expand Down Expand Up @@ -61,44 +61,52 @@ fn add_run_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.use_delimiter(true)
.require_equals(true)
.help("Allow file system read access"),
).arg(
)
.arg(
Arg::with_name("allow-write")
.long("allow-write")
.min_values(0)
.takes_value(true)
.use_delimiter(true)
.require_equals(true)
.help("Allow file system write access"),
).arg(
)
.arg(
Arg::with_name("allow-net")
.long("allow-net")
.min_values(0)
.takes_value(true)
.use_delimiter(true)
.require_equals(true)
.help("Allow network access"),
).arg(
)
.arg(
Arg::with_name("allow-env")
.long("allow-env")
.help("Allow environment access"),
).arg(
)
.arg(
Arg::with_name("allow-run")
.long("allow-run")
.help("Allow running subprocesses"),
).arg(
)
.arg(
Arg::with_name("allow-hrtime")
.long("allow-hrtime")
.help("Allow high resolution time measurement"),
).arg(
)
.arg(
Arg::with_name("allow-all")
.short("A")
.long("allow-all")
.help("Allow all permissions"),
).arg(
)
.arg(
Arg::with_name("no-prompt")
.long("no-prompt")
.help("Do not use prompts"),
).arg(
)
.arg(
Arg::with_name("no-fetch")
.long("no-fetch")
.help("Do not download remote modules"),
Expand Down
3 changes: 2 additions & 1 deletion cli/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ pub fn make_temp_dir(
let mut buf: PathBuf = match dir {
Some(ref p) => p.to_path_buf(),
None => std::env::temp_dir(),
}.join("_");
}
.join("_");
let mut rng = rand::thread_rng();
loop {
let unique = rng.gen::<u32>();
Expand Down
9 changes: 6 additions & 3 deletions cli/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ pub fn fetch_string(
DenoError::new(
deno_error::ErrorKind::NotFound,
"module not found".to_string(),
).into(),
)
.into(),
);
}
Ok(Loop::Break(response))
})
}).and_then(|response| {
})
.and_then(|response| {
let content_type = response
.headers()
.get(CONTENT_TYPE)
Expand All @@ -186,7 +188,8 @@ pub fn fetch_string(
.map(|body| String::from_utf8(body.to_vec()).unwrap())
.map_err(ErrBox::from);
body.join(future::ok(content_type))
}).and_then(|(body_string, maybe_content_type)| {
})
.and_then(|(body_string, maybe_content_type)| {
future::ok((body_string, maybe_content_type.unwrap()))
})
}
Expand Down
Loading

0 comments on commit 3971dcf

Please sign in to comment.