Skip to content

Commit

Permalink
Merge branch 'master' into feat-unix-domain-socket
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouto18 committed Mar 22, 2020
2 parents 2c00f87 + c337d2c commit ddaa391
Show file tree
Hide file tree
Showing 119 changed files with 928 additions and 1,026 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -22,7 +22,8 @@
],
"@typescript-eslint/ban-ts-ignore": ["off"],
"@typescript-eslint/no-empty-function": ["off"],
"no-return-await": "error"
"no-return-await": "error",
"require-await": "error"
},
"overrides": [
{
Expand Down
107 changes: 35 additions & 72 deletions .github/workflows/ci.yml
Expand Up @@ -27,10 +27,15 @@ jobs:
- os: macOS-latest
kind: 'test_debug'

# Always run master branch builds to completion. This allows the cache to
# stay mostly up-to-date in situations where a single job fails due to
# e.g. a flaky test.
fail-fast:
${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
DENO_BUILD_MODE: release
RUSTC_WRAPPER: sccache
V8_BINARY: true

steps:
Expand All @@ -50,24 +55,7 @@ jobs:
if: startsWith(matrix.os, 'ubuntu') && matrix.kind == 'test_release' && startsWith(github.ref, 'refs/tags/') && github.repository == 'denoland/deno'
run: |
mkdir -p target/release
tar --exclude=".git*" --exclude=target --exclude=deno_typescript/typescript/tests --exclude=third_party/cpplint --exclude=third_party/node_modules --exclude=third_party/python_packages --exclude=third_party/prebuilt -czvf target/release/deno_src.tar.gz -C .. deno
# Cache https://github.com/actions/cache/blob/master/examples.md#rust---cargo
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
tar --exclude=.cargo --exclude=".git*" --exclude=target --exclude=deno_typescript/typescript/tests --exclude=third_party/cpplint --exclude=third_party/node_modules --exclude=third_party/python_packages --exclude=third_party/prebuilt -czvf target/release/deno_src.tar.gz -C .. deno
- name: Install rust
uses: hecrj/setup-rust-action@v1
Expand All @@ -94,54 +82,36 @@ jobs:
Select-Object -Skip 1 |
ForEach-Object { Move-Item "$_" "$_.disabled" }
- name: Environment (linux)
if: startsWith(matrix.os, 'ubuntu')
# In order to test the installer scripts in std we need a deno
# executable in the path. See
# https://github.com/denoland/deno/blob/27cd2c97f18c0392bc04c66b786717b2bc677315/std/installer/mod.ts#L185-L193
# TODO(ry) This path modification should rather be done in "cargo test".
run: |
echo ::add-path::`pwd`/third_party/prebuilt/linux64
echo ::add-path::`pwd`/target/release
- name: Environment (mac)
if: startsWith(matrix.os, 'macOS')
run: |
echo ::add-path::`pwd`/third_party/prebuilt/mac
echo ::add-path::`pwd`/target/release
- name: Environment (windows)
if: startsWith(matrix.os, 'windows')
run: |
echo ::add-path::$(pwd)\third_party\prebuilt\win
echo ::add-path::$(pwd)\target\release
- name: Log versions
run: |
node -v
python --version
rustc --version
cargo --version
- name: Start sccache (azure)
if: startsWith(matrix.os, 'windows') == false
env:
SCCACHE_AZURE_BLOB_CONTAINER: deno-sccache2
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING || 'DefaultEndpointsProtocol=https;AccountName=denosccache;EndpointSuffix=core.windows.net' }}
SCCACHE_IDLE_TIMEOUT: 0
run: sccache --start-server

# TODO(ry) We want to use Azure because it's cheaper. However sccache on
# Windows has a bug when using Azure. The bug manifests itself as a
# "multiple input files" error message.
- name: Start sccache (s3)
if: startsWith(matrix.os, 'windows')
env:
AWS_ACCESS_KEY_ID: AKIAIVRN52PLDBP55LBQ
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SCCACHE_BUCKET: deno-sccache
SCCACHE_IDLE_TIMEOUT: 0
run: sccache --start-server
- name: Configure cargo data directory
# After this point, all cargo registry and crate data is stored in
# $GITHUB_WORKSPACE/.cargo. This allows us to cache only the files that
# are needed during the build process. Additionally, this works around
# a bug in the 'cache' action that causes directories outside of the
# workspace dir to be saved/restored incorrectly.
run: echo "::set-env name=CARGO_HOME::$(pwd)/.cargo"

- name: Cache
uses: actions/cache@master
with:
# Note: crates from the denoland/deno git repo always get rebuilt,
# and their outputs ('deno', 'libdeno.rlib' etc.) are quite big,
# so we cache only those subdirectories of target/{debug|release} that
# contain the build output for crates that come from the registry.
path: |-
.cargo
target/*/.*
target/*/build
target/*/deps
target/*/gn_out
key:
${{ matrix.os }}-${{ matrix.kind }}-${{ hashFiles('Cargo.lock') }}

- name: lint.py
if: matrix.kind == 'lint'
Expand All @@ -157,31 +127,27 @@ jobs:

- name: Build debug
if: matrix.kind == 'test_debug'
run: |
echo ::set-env name=DENO_BUILD_MODE::debug
cargo build --locked --all-targets
run: cargo build --locked --all-targets

- name: Test release
if: matrix.kind == 'test_release'
run: cargo test --release --locked --all-targets

- name: Test debug
if: matrix.kind == 'test_debug'
run: |
echo ::set-env name=DENO_BUILD_MODE::debug
cargo test --locked --all-targets
run: cargo test --locked --all-targets

- name: Run Benchmarks
if: matrix.kind == 'bench'
run: python ./tools/benchmark.py target/release
run: python ./tools/benchmark.py --release

- name: Post Benchmarks
if: matrix.kind == 'bench' && github.ref == 'refs/heads/master' && github.repository == 'denoland/deno'
env:
DENOBOT_PAT: ${{ secrets.DENOBOT_PAT }}
run: |
git clone --depth 1 -b gh-pages https://${DENOBOT_PAT}@github.com/denoland/benchmark_data.git gh-pages
python ./tools/build_benchmark_jsons.py
python ./tools/build_benchmark_jsons.py --release
cd gh-pages
git config user.email "propelml@gmail.com"
git config user.name "denobot"
Expand Down Expand Up @@ -237,6 +203,3 @@ jobs:
cd ../cli
sleep 30
cargo publish
- name: Stop sccache
run: sccache --stop-server
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
*.pyc
*.swp

/.cargo/
/.idea/
/.vscode/
gclient_config.py_entries
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion cli/Cargo.toml
Expand Up @@ -44,7 +44,6 @@ log = "0.4.8"
notify = "5.0.0-pre.2"
rand = "0.7.3"
regex = "1.3.5"
remove_dir_all = "0.5.2"
reqwest = { version = "0.10.4", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli"] }
ring = "0.16.11"
rustyline = "6.0.0"
Expand Down
119 changes: 16 additions & 103 deletions cli/fs.rs
@@ -1,21 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use std;
use std::fs::{DirBuilder, File, OpenOptions};
use std::io::ErrorKind;
use std::env::current_dir;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::{Component, Path, PathBuf};

use deno_core::ErrBox;
use rand;
use rand::Rng;
use walkdir::WalkDir;

#[cfg(unix)]
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};

#[cfg(unix)]
use nix::unistd::{chown as unix_chown, Gid, Uid};

pub fn write_file<T: AsRef<[u8]>>(
filename: &Path,
data: T,
Expand All @@ -41,97 +32,19 @@ pub fn write_file_2<T: AsRef<[u8]>>(
.open(filename)?;

if update_mode {
set_permissions(&mut file, mode)?;
}

file.write_all(data.as_ref())
}

#[cfg(unix)]
fn set_permissions(file: &mut File, mode: u32) -> std::io::Result<()> {
debug!("set file mode to {}", mode);
file.set_permissions(PermissionsExt::from_mode(mode & 0o777))
}

#[cfg(not(unix))]
fn set_permissions(_file: &mut File, _mode: u32) -> std::io::Result<()> {
// NOOP on windows
Ok(())
}

pub fn make_temp(
dir: Option<&Path>,
prefix: Option<&str>,
suffix: Option<&str>,
is_dir: bool,
) -> std::io::Result<PathBuf> {
let prefix_ = prefix.unwrap_or("");
let suffix_ = suffix.unwrap_or("");
let mut buf: PathBuf = match dir {
Some(ref p) => p.to_path_buf(),
None => std::env::temp_dir(),
}
.join("_");
let mut rng = rand::thread_rng();
loop {
let unique = rng.gen::<u32>();
buf.set_file_name(format!("{}{:08x}{}", prefix_, unique, suffix_));
let r = if is_dir {
let mut builder = DirBuilder::new();
set_dir_permission(&mut builder, 0o700);
builder.create(buf.as_path())
} else {
let mut open_options = OpenOptions::new();
open_options.write(true).create_new(true);
#[cfg(unix)]
open_options.mode(0o600);
open_options.open(buf.as_path())?;
Ok(())
};
match r {
Err(ref e) if e.kind() == ErrorKind::AlreadyExists => continue,
Ok(_) => return Ok(buf),
Err(e) => return Err(e),
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mode = mode & 0o777;
debug!("set file mode to {:o}", mode);
let permissions = PermissionsExt::from_mode(mode);
file.set_permissions(permissions)?;
}
#[cfg(not(unix))]
let _ = mode;
}
}

pub fn mkdir(path: &Path, mode: u32, recursive: bool) -> std::io::Result<()> {
let mut builder = DirBuilder::new();
builder.recursive(recursive);
set_dir_permission(&mut builder, mode);
builder.create(path)
}

#[cfg(unix)]
fn set_dir_permission(builder: &mut DirBuilder, mode: u32) {
let mode = mode & 0o777;
debug!("set dir mode to {:o}", mode);
builder.mode(mode);
}

#[cfg(not(unix))]
fn set_dir_permission(_builder: &mut DirBuilder, _mode: u32) {
// NOOP on windows
}

#[cfg(unix)]
pub fn chown(path: &str, uid: u32, gid: u32) -> Result<(), ErrBox> {
let nix_uid = Uid::from_raw(uid);
let nix_gid = Gid::from_raw(gid);
unix_chown(path, Option::Some(nix_uid), Option::Some(nix_gid))
.map_err(ErrBox::from)
}

#[cfg(not(unix))]
pub fn chown(_path: &str, _uid: u32, _gid: u32) -> Result<(), ErrBox> {
// FAIL on Windows
// TODO: implement chown for Windows
let e = std::io::Error::new(
std::io::ErrorKind::Other,
"Not implemented".to_string(),
);
Err(ErrBox::from(e))
file.write_all(data.as_ref())
}

/// Normalize all itermediate components of the path (ie. remove "./" and "../" components).
Expand Down Expand Up @@ -171,7 +84,7 @@ pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, ErrBox> {
let resolved_path = if path.is_absolute() {
path.to_owned()
} else {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir().unwrap();
cwd.join(path)
};

Expand All @@ -184,19 +97,19 @@ mod tests {

#[test]
fn resolve_from_cwd_child() {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir().unwrap();
assert_eq!(resolve_from_cwd(Path::new("a")).unwrap(), cwd.join("a"));
}

#[test]
fn resolve_from_cwd_dot() {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir().unwrap();
assert_eq!(resolve_from_cwd(Path::new(".")).unwrap(), cwd);
}

#[test]
fn resolve_from_cwd_parent() {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir().unwrap();
assert_eq!(resolve_from_cwd(Path::new("a/..")).unwrap(), cwd);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/js/buffer.ts
Expand Up @@ -106,7 +106,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
return nread;
}

async read(p: Uint8Array): Promise<number | EOF> {
read(p: Uint8Array): Promise<number | EOF> {
const rr = this.readSync(p);
return Promise.resolve(rr);
}
Expand All @@ -116,7 +116,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
return copyBytes(this.buf, p, m);
}

async write(p: Uint8Array): Promise<number> {
write(p: Uint8Array): Promise<number> {
const n = this.writeSync(p);
return Promise.resolve(n);
}
Expand Down
4 changes: 2 additions & 2 deletions cli/js/compiler.ts
Expand Up @@ -302,7 +302,7 @@ async function runtimeCompile(
}
}

async function runtimeTranspile(
function runtimeTranspile(
request: CompilerRequestRuntimeTranspile
): Promise<Record<string, TranspileOnlyResult>> {
const result: Record<string, TranspileOnlyResult> = {};
Expand All @@ -325,7 +325,7 @@ async function runtimeTranspile(
);
result[fileName] = { source, map };
}
return result;
return Promise.resolve(result);
}

async function tsCompilerOnMessage({
Expand Down

0 comments on commit ddaa391

Please sign in to comment.