From 6cdf41e56dd27ea124f3417dfbcf8fd90b6f04a4 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 22 Aug 2023 12:58:28 -0400 Subject: [PATCH] Work on issue #616 (not fixed yet). --- projects/minetest-rsync.code-workspace | 3 + projects/trolltest-rsync.code-workspace | 21 +++++ utilities/run-any | 113 ++++++++++++++++++++---- utilities/run-any.sh | 34 +++++++ 4 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 projects/trolltest-rsync.code-workspace create mode 100755 utilities/run-any.sh diff --git a/projects/minetest-rsync.code-workspace b/projects/minetest-rsync.code-workspace index c0f5815..ef0fd32 100644 --- a/projects/minetest-rsync.code-workspace +++ b/projects/minetest-rsync.code-workspace @@ -14,6 +14,9 @@ "name": "Launch minetest-rsync", "program": "../git/EnlivenMinetest/utilities/run-any", "args": ["./bin/minetest"], + "env": { + "LD_LIBRARY_PATH": "/usr/lib64", + }, } ] } diff --git a/projects/trolltest-rsync.code-workspace b/projects/trolltest-rsync.code-workspace new file mode 100644 index 0000000..b1ed21a --- /dev/null +++ b/projects/trolltest-rsync.code-workspace @@ -0,0 +1,21 @@ +{ + "folders": [ + { + "path": "../../../trolltest-rsync" + } + ], + "settings": {}, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "type": "python", + "request": "launch", + "name": "Launch trolltest-rsync", + "program": "../git/EnlivenMinetest/utilities/run-any", + "args": ["./bin/trolltest"], + "cwd": "./trolltest-rsync" + } + ] + } +} diff --git a/utilities/run-any b/utilities/run-any index 5e76486..2f6afc0 100755 --- a/utilities/run-any +++ b/utilities/run-any @@ -28,7 +28,10 @@ for try_dirname in ["outputinspector-python", "outputinspector"]: # If in same git dir as REPO_DIR rather than installed as a module sys.path.insert(0, try_path) break - +if platform.system() == "Windows": + HOME = os.environ['USERPROFILE'] +else: + HOME = os.environ['HOME'] if sys.version_info.major < 3: ModuleNotFoundError = ImportError FileNotFoundError = IOError @@ -115,45 +118,102 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False): else: if cmd.startswith(bin_rel): cmd = "./" + cmd[len(bin_rel):] + pre_bin = "export LD_LIBRARY_PATH=/usr/lib64 " # doesn't fix #616 force_shell = False - # ^ Either True/False succeeds in bash, either fails in vscode - # with https://github.com/Poikilos/EnlivenMinetest/issues/616 + # ^ Either True/False succeeds in bash, either way LD_LIBRARY_PATH + # fails in vscode: + # https://github.com/Poikilos/EnlivenMinetest/issues/616 if not shell and force_shell: # force_shell fails with shell=True (just hangs # near `meta['bytes'] = err['source'].read(1)`, # even if run-any is run from bash prompt manually) if platform.system() == "Linux": if isinstance(cmd, list): - cmd = ["bash", "-c", "cd '" + cwd + "'; " + shlex.join(cmd)] + pre_bin = "LD_LIBRARY_PATH=/usr/lib64; export LD_LIBRARY_PATH; " # doesn't fix #616 + # ^ adding "export " causes bad identifier error later in command + cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + shlex.join(cmd)] else: - cmd = ["bash", "-c", "cd '" + cwd + "'; " + cmd] - run_msg = "Running %s" % pformat(cmd) + cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + cmd] + run_msg = prefix+"Running %s" % pformat(cmd) run_msg += ' # shell=%s in "%s"' % (shell, cwd) echo0(run_msg) if cwd is not None: os.chdir(cwd) - enable_call = False out = { 'bytes': None, # current line bytes 'string': "", # current line string # ^ (same as bytes if Python 2 running) 'buffer': "", # cumulative buffer - 'lines': [], } + good_path = ( + "{HOME}/.rvm/gems/ruby-3.0.0/bin:" + "{HOME}/.rvm/gems/ruby-3.0.0@global/bin:" + "{HOME}/.rvm/rubies/ruby-3.0.0/bin:" + "{HOME}/.nvm/versions/node/v14.21.2/bin:" + "/usr/lib64/ccache:{HOME}/.cargo/bin:" + "/usr/local/bin:/usr/bin:/bin:" + "{HOME}/.local/bin:/usr/local/sbin:/usr/sbin:" + "{HOME}/.local/bin:" + "{HOME}/git/linux-preinstall/utilities:" + "{HOME}/git/linux-preinstall/utilities-developer:" + "{HOME}/git/linux-preinstall/utilities-server:" + "{HOME}/.rvm/bin:{HOME}/.local/bin:{HOME}/bin:" + "{HOME}/git/linux-preinstall/utilities:" + "{HOME}/git/linux-preinstall/utilities-server:" + "{HOME}/git/linux-preinstall/utilities-developer:" + "{HOME}/.local/bin:{HOME}/git/linux-preinstall/utilities:" + "{HOME}/git/linux-preinstall/utilities-developer:" + "{HOME}/git/linux-preinstall/utilities-server:" + "{HOME}/.rvm/bin" + "".format(HOME=HOME) + ) + # ^ known good path in working bash that can run run-any + # os.environ['PATH'] = good_path # still doesn't fix issue #616 + this_env = os.environ.copy() + if platform.system() == "Linux": + # For diagnosing issue #616 + LD_LIBRARY_PATH = "/usr/lib64" + if "LD_LIBRARY_PATH" not in this_env: + print(prefix+"adding LD_LIBRARY_PATH=%s" % LD_LIBRARY_PATH) + this_env["LD_LIBRARY_PATH"] = LD_LIBRARY_PATH + elif LD_LIBRARY_PATH not in this_env['LD_LIBRARY_PATH']: + print(prefix+"LD_LIBRARY_PATH=%s" + % (os.environ['LD_LIBRARY_PATH'])) + print(prefix+"appending %s to LD_LIBRARY_PATH" % LD_LIBRARY_PATH) + if not this_env["LD_LIBRARY_PATH"].endswith(os.pathsep): + this_env["LD_LIBRARY_PATH"] += os.pathsep + os.environ["LD_LIBRARY_PATH"] += os.pathsep + this_env["LD_LIBRARY_PATH"] += LD_LIBRARY_PATH + os.environ["LD_LIBRARY_PATH"] += LD_LIBRARY_PATH + print(prefix+"LD_LIBRARY_PATH=%s" + % (os.environ['LD_LIBRARY_PATH'])) + else: + print(prefix+"detected %s in LD_LIBRARY_PATH=%s" + % (LD_LIBRARY_PATH, os.environ['LD_LIBRARY_PATH'])) + enable_call = False if enable_call: # FIXME: True for debug only--issue #616 (doesn't fix) + out['lines'] = [] + # source, stream, and bytes members are discarded before return + # in non-dummy case (not enable_call) & not necessary for caller. err = copy.deepcopy(out) - out['source'] = [] stream_metas = OrderedDict({ 'out': out, 'err': err, }) - code = subprocess.call(cmd) + print(prefix+"calling (shell=%s): %s" % (shell, cmd), + file=sys.stderr) + code = subprocess.run(cmd, shell=shell, env=this_env) return { # FIXME: for debug issue #616 only 'code': code, 'streams': stream_metas, } + if shell: + cmd = pre_bin + cmd + print(prefix+"opening (shell=%s): %s" % (shell, cmd), + file=sys.stderr) proc = subprocess.Popen(cmd, shell=shell, stderr=subprocess.PIPE, - stdout=subprocess.PIPE, cwd=cwd) + stdout=subprocess.PIPE, cwd=cwd, + env=this_env) code = None # Do not wait for finish--start displaying output immediately if enable_collect: @@ -239,6 +299,9 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False): } +issue_616_flag = "cannot open shared object file: No such file or directory" + + def main(): enablePush = True # collect the line in the inspector ui right away if len(sys.argv) < 2: @@ -261,8 +324,8 @@ def main(): else: echo0("Warning: not Minetest-like dir_name=%s" % dir_name) else: - raise ValueError('missing "%s"--use absolute path if not in cwd' - % path) + raise ValueError('missing "%s" (cwd="%s")--use absolute path if not in cwd' + % (path, os.getcwd())) # else: # cwd = os.dirname(hierosoft.which(path)) # TODO:uncomment this case? basename = os.path.basename(path) @@ -277,6 +340,8 @@ def main(): # stdout and stderr. else: targetBaseDir = exeDir + if targetBaseDir == "": + targetBaseDir = os.getcwd() if inspector: OutputInspector.addRoot(targetBaseDir) enable_collect = True @@ -304,15 +369,31 @@ def main(): err_index = len(out['lines']) all_lines = out['lines'] + err['lines'] - if inspector: - print("\nOutputInspector:") + sys.stdout.write("\nOutputInspector:") + sys.stdout.flush() + count = 0 for line in all_lines: inspector.addLine(line, enablePush) + count += 1 # NOTE: addLine adds all of the metadata! + if count < 1: + cmd_msg = cmd if isinstance(cmd, str) else shlex.join(cmd) + print(" (Output of `%s` had %s line(s) of output.)" + % (pformat(cmd_msg), count), + file=sys.stderr) + else: + print("", file=sys.stderr) + for info in inspector.getLineInfos(): print(info['all'], file=sys.stderr) - + if issue_616_flag in info['all']: + print("- detected issue #616.") + print(" See ", + file=sys.stderr) + pass + # raise SyntaxError( # "{} line(s)".format(len(all_lines))+"\n".join(all_lines) # ) diff --git a/utilities/run-any.sh b/utilities/run-any.sh new file mode 100755 index 0000000..140f761 --- /dev/null +++ b/utilities/run-any.sh @@ -0,0 +1,34 @@ +#!/bin/bash +found=false +# LD_LIBRARY_PATH=/usr/lib64 +# export LD_LIBRARY_PATH +export LD_LIBRARY_PATH=/usr/lib64 +for try_dir in ../git/EnlivenMinetest/utilities . +do + if [ -f $try_dir/run-any ]; then + if [ "x$found" != "xtrue" ]; then + found=true + echo "[run-any.sh] Found $try_dir..." + $try_dir/run-any "$@" + if [ $? -ne 0 ]; then + echo "[run-any.sh] the command failed in \"`pwd`\". Tried:" + echo "[run-any.sh] $try_dir/run-any" + echo "with args:" + for arg in $@ + do + echo "$arg" + if [ ! -f "$arg" ]; then + echo "(not in \"`pwd`\")" + fi + done + fi + fi + else + echo "There is no `realpath $try_dir/run-any`" + fi +done +if [ "x$found" != "xtrue" ]; then + echo "File $0, line 3: run-any was not found from working dir \"`pwd`\"." + echo " The vscode project using this file should set cwd or path to something like /home/user/minetest" + exit 1 +fi