From c0e6e9c8f7d10b2de8b136bfb6d597c44f4b0407 Mon Sep 17 00:00:00 2001 From: "Henry So, Jr." Date: Mon, 22 May 2017 19:17:58 -0400 Subject: [PATCH 1/2] Changed from os.popen to os.execute due to TL2017 strangeness. Fixes #1362. --- tex/gregoriotex.lua | 69 ++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/tex/gregoriotex.lua b/tex/gregoriotex.lua index e87bbc553..8ece393cc 100644 --- a/tex/gregoriotex.lua +++ b/tex/gregoriotex.lua @@ -84,6 +84,8 @@ local new_score_last_syllables = nil local state_hashes = nil local new_state_hashes = nil local auxname = nil +local tmpname = nil +local test_snippet_filename = nil local snippet_filename = nil local snippet_logname = nil @@ -120,33 +122,53 @@ local translation_mark = 1 local abovelinestext_mark = 2 log("marker whatsit id is %d", marker_whatsit_id) +local function get_prog_output(cmd, fmt) + cmd = string.format(cmd, tmpname) + local rc = os.execute(cmd) + local content = nil + if rc == 0 then + local f = io.open(tmpname, 'r'); + if f then + content = f:read(fmt) + f:close() + end + end + os.remove(tmpname) + return content +end + local function gregorio_exe() if real_gregorio_exe == nil then + local tmp_gabcfile = io.open(test_snippet_filename, 'w') + tmp_gabcfile:write("name:test;\n%%\n(c4)(g)\n") + tmp_gabcfile:close() + local exe_version -- first look for one with the exact version real_gregorio_exe = 'gregorio-5_0_1' -- FILENAME_VERSION - exe_version = io.popen(real_gregorio_exe..' --version', 'r') - if exe_version then - exe_version = exe_version:read("*line") - end + local cmd = string.format("%s -o %%s %s", real_gregorio_exe, + test_snippet_filename) + exe_version = get_prog_output(cmd, '*line') if not exe_version then -- look for suffix-less executable real_gregorio_exe = 'gregorio' - exe_version = io.popen(real_gregorio_exe..' --version', 'r') - exe_version = exe_version:read("*line") - if not exe_version or string.match(exe_version,"%d+%.%d+%.") - ~= string.match(internalversion,"%d+%.%d+%.") then - real_gregorio_exe = nil - err("Unable to find gregorio executable.\n".. - "shell-escape mode may not be activated. Try\n\n".. - "%s --shell-escape %s.tex\n\n".. - "See the documentation of Gregorio or your TeX\n".. - "distribution to automatize it.", - tex.formatname, tex.jobname) - end + cmd = string.format("%s -o %%s %s", real_gregorio_exe, + test_snippet_filename) + exe_version = get_prog_output(cmd, '*line') + end + if not exe_version or string.match(exe_version,"%d+%.%d+%.") + ~= string.match(internalversion,"%d+%.%d+%.") then + real_gregorio_exe = nil + err("Unable to find gregorio executable.\n".. + "shell-escape mode may not be activated. Try\n\n".. + "%s --shell-escape %s.tex\n\n".. + "See the documentation of Gregorio or your TeX\n".. + "distribution to automatize it.", + tex.formatname, tex.jobname) end + os.remove(test_snippet_filename) log("will use %s", real_gregorio_exe) end @@ -334,10 +356,14 @@ local function init(arg, enable_height_computation) end if outputdir and lfs.isdir(outputdir) then auxname = outputdir..'/'..tex.jobname..'.gaux' + tmpname = outputdir..'/'..tex.jobname..'.gtmp' + test_snippet_filename = outputdir..'/'..tex.jobname..'.test.gsnippet' snippet_filename = outputdir..'/'..tex.jobname..'.gsnippet' snippet_logname = outputdir..'/'..tex.jobname..'.gsniplog' else auxname = tex.jobname..'.gaux' + tmpname = tex.jobname..'.gtmp' + test_snippet_filename = tex.jobname..'.test.gsnippet' snippet_filename = tex.jobname..'.gsnippet' snippet_logname = tex.jobname..'.gsniplog' end @@ -904,18 +930,17 @@ local function direct_gabc(gabc, header, allow_deprecated) gabc = gabc:match('^()%s*$') and '' or gabc:match('^%s*(.*%S)') f:write('name:direct-gabc;\n'..(header or '')..'\n%%\n'..gabc:gsub('\\par ', '\n')) f:close() - local cmd = string.format('%s -W %s-S -l %s %s', gregorio_exe(), deprecated, - snippet_logname, snippet_filename) - local p = io.popen(cmd, 'r') - if p == nil then + local cmd = string.format('%s -W %s-o %%s -l %s %s', gregorio_exe(), + deprecated, snippet_logname, snippet_filename) + local content = get_prog_output(cmd, '*a') + if content == nil then err("\nSomething went wrong when executing\n %s\n" .."shell-escape mode may not be activated. Try\n\n" .."%s --shell-escape %s.tex\n\n" .."See the documentation of Gregorio or your TeX\n" .."distribution to automatize it.", cmd, tex.formatname, tex.jobname) else - tex.print(p:read("*a"):explode('\n')) - p:close() + tex.print(content:explode('\n')) end local glog = io.open(snippet_logname, 'a+') if glog == nil then From e48dccf403730573d8b86fce93a93faeb20c2359 Mon Sep 17 00:00:00 2001 From: "Henry So, Jr." Date: Mon, 22 May 2017 22:51:32 -0400 Subject: [PATCH 2/2] Added a change log linking to #1362. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb5d7987..61b664cc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. As of v3.0.0 this project adheres to [Semantic Versioning](http://semver.org/). It follows [some conventions](http://keepachangelog.com/). ## [Unreleased][unreleased] - +- Worked around an issue discovered during the TeX Live 2017 pre-test. See [#1362](https://github.com/gregorio-project/gregorio/issues/1362). ## [5.0.1] - 2017-04-16 - Fixed a bug in the TeXLive compatibility code for Windows users. Thanks to Akira Kakuto for the catch.