summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Sharshakov <sh7dm@outlook.com>2019-02-15 19:22:02 +0300
committerRyan Dahl <ry@tinyclouds.org>2019-02-15 11:22:02 -0500
commit4dc4329e270f617697154ca62a828cce3b46b348 (patch)
tree54edb5a9d3374fa6470fdc9ab5c50b9738dd4a35
parent1d7c74e9b5c416c58b66246a6bbc907399fe9083 (diff)
Add execPath function (#1743)
-rw-r--r--js/deno.ts2
-rw-r--r--js/os.ts12
-rw-r--r--src/msg.fbs3
-rw-r--r--src/ops.rs4
-rw-r--r--tests/exec_path.ts1
-rwxr-xr-xtools/test.py8
6 files changed, 26 insertions, 4 deletions
diff --git a/js/deno.ts b/js/deno.ts
index 45e16e52d..2e69a5bbd 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Public deno module.
-export { noColor, pid, env, exit, isTTY } from "./os";
+export { noColor, pid, env, exit, isTTY, execPath } from "./os";
export { chdir, cwd } from "./dir";
export {
File,
diff --git a/js/os.ts b/js/os.ts
index bb9ecc99a..fbcb23a7f 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -12,11 +12,19 @@ export let pid: number;
/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
export let noColor: boolean;
+/** Path to the current deno process's executable file. */
+export let execPath: string;
+
/** @internal */
-export function setGlobals(pid_: number, noColor_: boolean): void {
+export function setGlobals(
+ pid_: number,
+ noColor_: boolean,
+ execPath_: string
+): void {
assert(!pid);
pid = pid_;
noColor = noColor_;
+ execPath = execPath_;
}
interface CodeInfo {
@@ -190,7 +198,7 @@ export function start(source?: string): msg.StartRes {
util.setLogDebug(startResMsg.debugFlag(), source);
- setGlobals(startResMsg.pid(), startResMsg.noColor());
+ setGlobals(startResMsg.pid(), startResMsg.noColor(), startResMsg.execPath()!);
return startResMsg;
}
diff --git a/src/msg.fbs b/src/msg.fbs
index f3c47faf6..81345d156 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -65,7 +65,7 @@ union Any {
Now,
NowRes,
IsTTY,
- IsTTYRes
+ IsTTYRes,
}
enum ErrorKind: byte {
@@ -156,6 +156,7 @@ table StartRes {
cwd: string;
pid: uint32;
argv: [string];
+ exec_path: string;
debug_flag: bool;
deps_flag: bool;
types_flag: bool;
diff --git a/src/ops.rs b/src/ops.rs
index a968ae6e1..e303196ca 100644
--- a/src/ops.rs
+++ b/src/ops.rs
@@ -252,6 +252,9 @@ fn op_start(
let cwd_off =
builder.create_string(deno_fs::normalize_path(cwd_path.as_ref()).as_ref());
+ let exec_path =
+ builder.create_string(std::env::current_exe().unwrap().to_str().unwrap());
+
let v8_version = version::v8();
let v8_version_off = builder.create_string(v8_version);
@@ -270,6 +273,7 @@ fn op_start(
v8_version: Some(v8_version_off),
deno_version: Some(deno_version_off),
no_color: !ansi::use_color(),
+ exec_path: Some(exec_path),
..Default::default()
},
);
diff --git a/tests/exec_path.ts b/tests/exec_path.ts
new file mode 100644
index 000000000..f09663d7e
--- /dev/null
+++ b/tests/exec_path.ts
@@ -0,0 +1 @@
+console.log(Deno.execPath);
diff --git a/tools/test.py b/tools/test.py
index 9e43dca3e..5d08e59d1 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -38,6 +38,12 @@ def test_no_color(deno_exe):
print green_ok()
+def exec_path_test(deno_exe):
+ cmd = [deno_exe, "tests/exec_path.ts"]
+ output = run_output(cmd)
+ assert deno_exe in output.strip()
+
+
def main(argv):
if len(argv) == 2:
build_dir = sys.argv[1]
@@ -59,6 +65,8 @@ def main(argv):
deno_exe = os.path.join(build_dir, "deno" + executable_suffix)
check_exists(deno_exe)
+ exec_path_test(deno_exe)
+
# Internal tools testing
run([
"node", "./node_modules/.bin/ts-node", "--project",