From d85535bb6ea7d04ef208ce39f8dc167d24bd2ba9 Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Sun, 22 Dec 2024 01:25:02 +0100 Subject: [PATCH] std: Add 'getError' --- cli/packages.lock.json | 21 +++++++++++++++++++++ generators/packages.lock.json | 3 ++- language-server/packages.lock.json | 3 ++- readline/packages.lock.json | 3 ++- src/Std/Environment/Environment.cs | 12 ++---------- src/Std/Pipe.cs | 26 +++++++++++++++++++++++--- src/Vm/ProcessContext.cs | 16 +++++++++------- src/packages.lock.json | 3 ++- 8 files changed, 63 insertions(+), 24 deletions(-) diff --git a/cli/packages.lock.json b/cli/packages.lock.json index 688e0bd0..ab05d30c 100644 --- a/cli/packages.lock.json +++ b/cli/packages.lock.json @@ -334,6 +334,27 @@ "Wcwidth": "[1.0.0, )" } } + }, + "net9.0/linux-arm64": { + "Microsoft.DotNet.ILCompiler": { + "type": "Direct", + "requested": "[9.0.0, )", + "resolved": "9.0.0", + "contentHash": "bbnlV2PbUmCQ8Ndpx0kJaicLyV28IU+4IzyctQLL57+DxrHurYr2qsJrC8+yD44Q0DyPfv2oM168c1Tk6Bxbmg==", + "dependencies": { + "runtime.linux-arm64.Microsoft.DotNet.ILCompiler": "9.0.0" + } + }, + "runtime.linux-arm64.Microsoft.DotNet.ILCompiler": { + "type": "Transitive", + "resolved": "9.0.0", + "contentHash": "7RVXw+bLJK+7wMeAXUQoAWj/V9ucm5ry3dop2DHjA/7w/mzP96KEjy7y1eM4WxhHU4xJPZftGHY6Ude3Jh+kOg==" + }, + "SQLitePCLRaw.lib.e_sqlite3": { + "type": "Transitive", + "resolved": "2.1.10", + "contentHash": "mAr69tDbnf3QJpRy2nJz8Qdpebdil00fvycyByR58Cn9eARvR+UiG2Vzsp+4q1tV3ikwiYIjlXCQFc12GfebbA==" + } } } } \ No newline at end of file diff --git a/generators/packages.lock.json b/generators/packages.lock.json index c21ce082..ab6f8c89 100644 --- a/generators/packages.lock.json +++ b/generators/packages.lock.json @@ -46,6 +46,7 @@ "resolved": "6.0.0", "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" } - } + }, + "net9.0/linux-arm64": {} } } \ No newline at end of file diff --git a/language-server/packages.lock.json b/language-server/packages.lock.json index 45e9a5b6..8affeae7 100644 --- a/language-server/packages.lock.json +++ b/language-server/packages.lock.json @@ -261,6 +261,7 @@ "Wcwidth": "[1.0.0, )" } } - } + }, + "net9.0/linux-arm64": {} } } \ No newline at end of file diff --git a/readline/packages.lock.json b/readline/packages.lock.json index 0c6b6e3e..adc90c6a 100644 --- a/readline/packages.lock.json +++ b/readline/packages.lock.json @@ -8,6 +8,7 @@ "resolved": "1.0.0", "contentHash": "aekut5BeF4c1Jr2qab3aXcttcgPEfPb2ok2L8911EIzn3RnDBYnUWgx/1OVlqrSXCdwAkBpNgYWXb6b5t4cBng==" } - } + }, + "net9.0/linux-arm64": {} } } \ No newline at end of file diff --git a/src/Std/Environment/Environment.cs b/src/Std/Environment/Environment.cs index 5a1c600b..24ef024b 100644 --- a/src/Std/Environment/Environment.cs +++ b/src/Std/Environment/Environment.cs @@ -11,6 +11,7 @@ using Elk.Std.Attributes; using Elk.Std.DataTypes; using Elk.Vm; +using Microsoft.VisualBasic.FileIO; #endregion @@ -127,15 +128,6 @@ public static RuntimeObject ExitCode() : new RuntimeInteger(int.Parse(exitCode)); } - /// The glob pattern to expand - /// Expands a glob string, eg. "**/*.elk" - [ElkFunction("expand")] - public static RuntimeGenerator Expand(RuntimeString pattern) - => new( - Globbing.Glob(ShellEnvironment.WorkingDirectory, pattern.Value) - .Select(x => new RuntimeString(x)) - ); - /// The index of the argument to get /// The list of command line arguments passed to the program, or a specific one if an index was specified [ElkFunction("getArgv", Reachability.Everywhere)] @@ -343,4 +335,4 @@ public static List GetDirectoryNames(string path) return directoryNames; } -} \ No newline at end of file +} diff --git a/src/Std/Pipe.cs b/src/Std/Pipe.cs index 30f220c9..54ee2bbb 100644 --- a/src/Std/Pipe.cs +++ b/src/Std/Pipe.cs @@ -58,6 +58,7 @@ public static RuntimePipe DisposeAll(RuntimePipe pipe) { pipe.EnableDisposeOutput(); pipe.EnableDisposeError(); + pipe.AllowNonZeroExit(); pipe.Start(); return pipe; @@ -78,15 +79,34 @@ public static RuntimePipe DisposeErr(RuntimePipe pipe) return pipe; } + /// + /// Configures the given pipe to only redirect stderr. + /// + /// The given pipe. + [ElkFunction("getErr", Reachability.Everywhere, StartsPipeManually = true)] + public static RuntimePipe Err(RuntimePipe pipe) + { + pipe.EnableDisposeOutput(); + pipe.AllowNonZeroExit(); + pipe.Start(); + + return pipe; + } + /// /// The exit code of the process belonging to the given pipe, or nil if it has not terminated yet. /// Note: Only works on pipes that run in the background (eg. where the `background` function has been used). /// - [ElkFunction("exitCode")] + [ElkFunction("exitCode", Reachability.Everywhere, StartsPipeManually = true)] public static RuntimeObject ExitCode(RuntimePipe pipe) - => pipe.ExitCode == null + { + pipe.AllowNonZeroExit(); + pipe.Start(); + + return pipe.ExitCode == null ? RuntimeNil.Value : new RuntimeInteger(pipe.ExitCode.Value); + } /// /// Waits for a pipe that was started in the background. @@ -106,4 +126,4 @@ public static void WaitAll(RuntimeList pipes) foreach (var pipe in pipes) pipe.As().Wait(); } -} \ No newline at end of file +} diff --git a/src/Vm/ProcessContext.cs b/src/Vm/ProcessContext.cs index 0c1730a3..5481f80a 100644 --- a/src/Vm/ProcessContext.cs +++ b/src/Vm/ProcessContext.cs @@ -96,8 +96,8 @@ public void StartWithRedirect() if (_disposeError) _process!.StartInfo.RedirectStandardError = true; - _allowNonZeroExit = _process!.StartInfo.RedirectStandardError; - _process.EnableRaisingEvents = true; + _allowNonZeroExit = _allowNonZeroExit || _process!.StartInfo.RedirectStandardError; + _process!.EnableRaisingEvents = true; try { @@ -180,7 +180,11 @@ private void Read(RuntimeObject value) while (runtimePipe.StreamEnumerator.MoveNext()) streamWriter.WriteLine(runtimePipe.StreamEnumerator.Current); } - else if (value is RuntimeList runtimeList) + else if (value is RuntimeString) + { + streamWriter.Write(value); + } + else if (value is IEnumerable runtimeList) { foreach (var item in runtimeList) streamWriter.WriteLine(item); @@ -210,9 +214,6 @@ private void CloseProcess(bool messageOnError) _process.WaitForExit(); - //if (_process == null) - //return; - ExitCode = _process.ExitCode; _process.Dispose(); _process = null; @@ -225,6 +226,7 @@ private void CloseProcess(bool messageOnError) RuntimeObject message = messageOnError ? new RuntimeString("Program returned a non-zero exit code.") : RuntimeNil.Value; + // TODO: Somehow get the actual signal rather than relying on exit codes if (ExitCode >= 128 && ExitCode <= 128 + SignalHelper.SignalNames.Length - 1) { @@ -236,4 +238,4 @@ private void CloseProcess(bool messageOnError) throw new RuntimeUserException(new RuntimeError(message)); } } -} \ No newline at end of file +} diff --git a/src/packages.lock.json b/src/packages.lock.json index 4a88c8b9..9f4aa6c1 100644 --- a/src/packages.lock.json +++ b/src/packages.lock.json @@ -25,6 +25,7 @@ "Wcwidth": "[1.0.0, )" } } - } + }, + "net9.0/linux-arm64": {} } } \ No newline at end of file