Browse Source

Work on issue #616 (not fixed yet).

master
poikilos 1 year ago
parent
commit
6cdf41e56d
  1. 3
      projects/minetest-rsync.code-workspace
  2. 21
      projects/trolltest-rsync.code-workspace
  3. 113
      utilities/run-any
  4. 34
      utilities/run-any.sh

3
projects/minetest-rsync.code-workspace

@ -14,6 +14,9 @@
"name": "Launch minetest-rsync", "name": "Launch minetest-rsync",
"program": "../git/EnlivenMinetest/utilities/run-any", "program": "../git/EnlivenMinetest/utilities/run-any",
"args": ["./bin/minetest"], "args": ["./bin/minetest"],
"env": {
"LD_LIBRARY_PATH": "/usr/lib64",
},
} }
] ]
} }

21
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"
}
]
}
}

113
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 # If in same git dir as REPO_DIR rather than installed as a module
sys.path.insert(0, try_path) sys.path.insert(0, try_path)
break break
if platform.system() == "Windows":
HOME = os.environ['USERPROFILE']
else:
HOME = os.environ['HOME']
if sys.version_info.major < 3: if sys.version_info.major < 3:
ModuleNotFoundError = ImportError ModuleNotFoundError = ImportError
FileNotFoundError = IOError FileNotFoundError = IOError
@ -115,45 +118,102 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False):
else: else:
if cmd.startswith(bin_rel): if cmd.startswith(bin_rel):
cmd = "./" + cmd[len(bin_rel):] cmd = "./" + cmd[len(bin_rel):]
pre_bin = "export LD_LIBRARY_PATH=/usr/lib64 " # doesn't fix #616
force_shell = False force_shell = False
# ^ Either True/False succeeds in bash, either fails in vscode # ^ Either True/False succeeds in bash, either way LD_LIBRARY_PATH
# with https://github.com/Poikilos/EnlivenMinetest/issues/616 # fails in vscode:
# https://github.com/Poikilos/EnlivenMinetest/issues/616
if not shell and force_shell: if not shell and force_shell:
# force_shell fails with shell=True (just hangs # force_shell fails with shell=True (just hangs
# near `meta['bytes'] = err['source'].read(1)`, # near `meta['bytes'] = err['source'].read(1)`,
# even if run-any is run from bash prompt manually) # even if run-any is run from bash prompt manually)
if platform.system() == "Linux": if platform.system() == "Linux":
if isinstance(cmd, list): 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: else:
cmd = ["bash", "-c", "cd '" + cwd + "'; " + cmd] cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + cmd]
run_msg = "Running %s" % pformat(cmd) run_msg = prefix+"Running %s" % pformat(cmd)
run_msg += ' # shell=%s in "%s"' % (shell, cwd) run_msg += ' # shell=%s in "%s"' % (shell, cwd)
echo0(run_msg) echo0(run_msg)
if cwd is not None: if cwd is not None:
os.chdir(cwd) os.chdir(cwd)
enable_call = False
out = { out = {
'bytes': None, # current line bytes 'bytes': None, # current line bytes
'string': "", # current line string 'string': "", # current line string
# ^ (same as bytes if Python 2 running) # ^ (same as bytes if Python 2 running)
'buffer': "", # cumulative buffer '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) 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) err = copy.deepcopy(out)
out['source'] = []
stream_metas = OrderedDict({ stream_metas = OrderedDict({
'out': out, 'out': out,
'err': err, '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 return { # FIXME: for debug issue #616 only
'code': code, 'code': code,
'streams': stream_metas, '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, proc = subprocess.Popen(cmd, shell=shell, stderr=subprocess.PIPE,
stdout=subprocess.PIPE, cwd=cwd) stdout=subprocess.PIPE, cwd=cwd,
env=this_env)
code = None code = None
# Do not wait for finish--start displaying output immediately # Do not wait for finish--start displaying output immediately
if enable_collect: 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(): def main():
enablePush = True # collect the line in the inspector ui right away enablePush = True # collect the line in the inspector ui right away
if len(sys.argv) < 2: if len(sys.argv) < 2:
@ -261,8 +324,8 @@ def main():
else: else:
echo0("Warning: not Minetest-like dir_name=%s" % dir_name) echo0("Warning: not Minetest-like dir_name=%s" % dir_name)
else: else:
raise ValueError('missing "%s"--use absolute path if not in cwd' raise ValueError('missing "%s" (cwd="%s")--use absolute path if not in cwd'
% path) % (path, os.getcwd()))
# else: # else:
# cwd = os.dirname(hierosoft.which(path)) # TODO:uncomment this case? # cwd = os.dirname(hierosoft.which(path)) # TODO:uncomment this case?
basename = os.path.basename(path) basename = os.path.basename(path)
@ -277,6 +340,8 @@ def main():
# stdout and stderr. # stdout and stderr.
else: else:
targetBaseDir = exeDir targetBaseDir = exeDir
if targetBaseDir == "":
targetBaseDir = os.getcwd()
if inspector: if inspector:
OutputInspector.addRoot(targetBaseDir) OutputInspector.addRoot(targetBaseDir)
enable_collect = True enable_collect = True
@ -304,15 +369,31 @@ def main():
err_index = len(out['lines']) err_index = len(out['lines'])
all_lines = out['lines'] + err['lines'] all_lines = out['lines'] + err['lines']
if inspector: if inspector:
print("\nOutputInspector:") sys.stdout.write("\nOutputInspector:")
sys.stdout.flush()
count = 0
for line in all_lines: for line in all_lines:
inspector.addLine(line, enablePush) inspector.addLine(line, enablePush)
count += 1
# NOTE: addLine adds all of the metadata! # 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(): for info in inspector.getLineInfos():
print(info['all'], file=sys.stderr) print(info['all'], file=sys.stderr)
if issue_616_flag in info['all']:
print("- detected issue #616.")
print(" See <https://"
"github.com/Poikilos/EnlivenMinetest/issues/616>",
file=sys.stderr)
pass
# raise SyntaxError( # raise SyntaxError(
# "{} line(s)".format(len(all_lines))+"\n".join(all_lines) # "{} line(s)".format(len(all_lines))+"\n".join(all_lines)
# ) # )

34
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
Loading…
Cancel
Save