Skip to content

Commit

Permalink
Rename process to subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 13, 2018
1 parent 5977789 commit f12b112
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ts_sources = [
"js/blob.ts",
"js/buffer.ts",
"js/chmod.ts",
"js/run.ts",
"js/compiler.ts",
"js/console.ts",
"js/copy_file.ts",
Expand All @@ -91,13 +90,13 @@ ts_sources = [
"js/errors.ts",
"js/fetch.ts",
"js/file.ts",
"js/headers.ts",
"js/file_info.ts",
"js/files.ts",
"js/flatbuffers.ts",
"js/form_data.ts",
"js/global_eval.ts",
"js/globals.ts",
"js/headers.ts",
"js/io.ts",
"js/libdeno.ts",
"js/main.ts",
Expand All @@ -115,9 +114,10 @@ ts_sources = [
"js/read_link.ts",
"js/remove.ts",
"js/rename.ts",
"js/resources.ts",
"js/repl.ts",
"js/resources.ts",
"js/stat.ts",
"js/subprocess.ts",
"js/symlink.ts",
"js/text_encoding.ts",
"js/timers.ts",
Expand Down
2 changes: 1 addition & 1 deletion js/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export { FileInfo } from "./file_info";
export { connect, dial, listen, Listener, Conn } from "./net";
export { metrics } from "./metrics";
export { resources } from "./resources";
export { run, RunOptions, Process, ProcessStatus } from "./run";
export { run, RunOptions, Subprocess, SubprocessStatus } from "./subprocess";
export const args: string[] = [];

// Provide the compiler API in an obfuscated way
Expand Down
32 changes: 16 additions & 16 deletions js/run.ts → js/subprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import { assert, unreachable } from "./util";
import { close, File } from "./files";
import { ReadCloser, WriteCloser } from "./io";

/** How to handle subprocess stdio.
/** How to handle subsubprocess stdio.
*
* "inherit" The default if unspecified. The child inherits from the
* corresponding parent descriptor.
*
* "piped" A new pipe should be arranged to connect the parent and child
* processes.
* subprocesses.
*
* "null" This stream will be ignored. This is the equivalent of attaching the
* stream to /dev/null.
*/
export type ProcessStdio = "inherit" | "piped" | "null";
export type SubprocessStdio = "inherit" | "piped" | "null";

// TODO Maybe extend VSCode's 'CommandOptions'?
// tslint:disable-next-line:max-line-length
// See https://code.visualstudio.com/docs/editor/tasks-appendix#_schema-for-tasksjson
export interface RunOptions {
args: string[];
cwd?: string;
stdout?: ProcessStdio;
stderr?: ProcessStdio;
stdin?: ProcessStdio;
stdout?: SubprocessStdio;
stderr?: SubprocessStdio;
stdin?: SubprocessStdio;
}

export class Process {
export class Subprocess {
readonly rid: number;
readonly pid: number;
readonly stdin?: WriteCloser;
Expand All @@ -55,7 +55,7 @@ export class Process {
}
}

async status(): Promise<ProcessStatus> {
async status(): Promise<SubprocessStatus> {
return await runStatus(this.rid);
}

Expand All @@ -64,26 +64,26 @@ export class Process {
}
}

export interface ProcessStatus {
export interface SubprocessStatus {
success: boolean;
code?: number;
signal?: number; // TODO: Make this a string, e.g. 'SIGTERM'.
}

function stdioMap(s: ProcessStdio): msg.ProcessStdio {
function stdioMap(s: SubprocessStdio): msg.SubprocessStdio {
switch (s) {
case "inherit":
return msg.ProcessStdio.Inherit;
return msg.SubprocessStdio.Inherit;
case "piped":
return msg.ProcessStdio.Piped;
return msg.SubprocessStdio.Piped;
case "null":
return msg.ProcessStdio.Null;
return msg.SubprocessStdio.Null;
default:
return unreachable();
}
}

export function run(opt: RunOptions): Process {
export function run(opt: RunOptions): Subprocess {
const builder = flatbuffers.createBuilder();
const argsOffset = msg.Run.createArgsVector(
builder,
Expand Down Expand Up @@ -111,10 +111,10 @@ export function run(opt: RunOptions): Process {
const res = new msg.RunRes();
assert(baseRes!.inner(res) != null);

return new Process(res);
return new Subprocess(res);
}

async function runStatus(rid: number): Promise<ProcessStatus> {
async function runStatus(rid: number): Promise<SubprocessStatus> {
const builder = flatbuffers.createBuilder();
msg.RunStatus.startRunStatus(builder);
msg.RunStatus.addRid(builder, rid);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion js/unit_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import "./read_file_test.ts";
import "./read_link_test.ts";
import "./rename_test.ts";
import "./resources_test.ts";
import "./run_test.ts";
import "./stat_test.ts";
import "./subprocess_test.ts";
import "./symlink_test.ts";
import "./text_encoding_test.ts";
import "./timers_test.ts";
Expand Down
8 changes: 4 additions & 4 deletions src/msg.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,14 @@ table MetricsRes {
bytes_received: uint64;
}

enum ProcessStdio: byte { Inherit, Piped, Null }
enum SubprocessStdio: byte { Inherit, Piped, Null }

table Run {
args: [string];
cwd: string;
stdin: ProcessStdio;
stdout: ProcessStdio;
stderr: ProcessStdio;
stdin: SubprocessStdio;
stdout: SubprocessStdio;
stderr: SubprocessStdio;
}

table RunRes {
Expand Down
14 changes: 7 additions & 7 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,11 +1383,11 @@ fn op_resources(
))
}

fn command_stdio_map(v: msg::ProcessStdio) -> std::process::Stdio {
fn subprocess_stdio_map(v: msg::SubprocessStdio) -> std::process::Stdio {
match v {
msg::ProcessStdio::Inherit => std::process::Stdio::inherit(),
msg::ProcessStdio::Piped => std::process::Stdio::piped(),
msg::ProcessStdio::Null => std::process::Stdio::null(),
msg::SubprocessStdio::Inherit => std::process::Stdio::inherit(),
msg::SubprocessStdio::Piped => std::process::Stdio::piped(),
msg::SubprocessStdio::Null => std::process::Stdio::null(),
}
}

Expand Down Expand Up @@ -1415,9 +1415,9 @@ fn op_run(
});
cwd.map(|d| cmd.current_dir(d));

cmd.stdin(command_stdio_map(inner.stdin()));
cmd.stdout(command_stdio_map(inner.stdout()));
cmd.stderr(command_stdio_map(inner.stderr()));
cmd.stdin(subprocess_stdio_map(inner.stdin()));
cmd.stdout(subprocess_stdio_map(inner.stdout()));
cmd.stderr(subprocess_stdio_map(inner.stderr()));

// Spawn the command.
let child = match cmd.spawn_async() {
Expand Down

0 comments on commit f12b112

Please sign in to comment.