Skip to content

Commit

Permalink
Add version check for executable
Browse files Browse the repository at this point in the history
We need to make sure that the gregorio executable being used by the auto compilation feature is version matched to the GregorioTeX version being used.
  • Loading branch information
rpspringuel committed Aug 1, 2016
1 parent 763aed2 commit ca74fd4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tex/gregoriosyms.sty
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

% The version of gregorio. All gregoriotex*.tex files must have the same.
% All gtex files must also have the same version.
\xdef\gre@gregorioversion{4.2.0-rc2}% GREGORIO_VERSION - VersionManager.py
\xdef\gre@gregoriotexversion{4.2.0-rc2}% GREGORIO_VERSION - VersionManager.py

\providecommand{\gre@declarefileversion}[2]{\relax}

Expand Down Expand Up @@ -102,11 +102,11 @@
\long\def\gre@ifnotlatex#1{}
\input gregoriotex-symbols.tex

\xdef\gre@gregoriotexluaversion{\directlua{tex.write(gregoriotex.get_gregorioversion())}}%
\xdef\gre@gregoriotexluaversion{\directlua{tex.write(gregoriotex.get_gregoriotexluaversion())}}%

% Test to make sure that gregoriotex.lua is of the same version.
\IfStrEq*{\gre@gregoriotexluaversion}{\gre@gregorioversion}{}{%else
\gre@error{uncoherent file versions: gregoriosyms.sty is in version \number\gre@gregorioversion \space\space while gregoriotex.lua is in version \gre@gregoriotexluaversion}}%
\IfStrEq*{\gre@gregoriotexluaversion}{\gre@gregoriotexversion}{}{%else
\gre@error{uncoherent file versions: gregoriosyms.sty is in version \number\gre@gregoriotexversion \space\space while gregoriotex.lua is in version \gre@gregoriotexluaversion}}%

%%%%%%%%%
%% Color definitions
Expand Down
22 changes: 14 additions & 8 deletions tex/gregoriotex-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@

% The version of gregorio. All gregoriotex*.tex files must have the same.
% All gtex files must also have the same version.
\xdef\gre@gregorioversion{4.2.0-rc2}% GREGORIO_VERSION - VersionManager.py
\xdef\gre@gregoriotexversion{4.2.0-rc2}% GREGORIO_VERSION - VersionManager.py

% first some macros to allow checks for version:
% Tests that all gregoriotex files are of the same version.
% #1 is the name of the file
% #2 is the version

\def\gre@declarefileversion#1#2{%
\IfStrEq*{#2}{\gre@gregorioversion}{}{%else
\gre@error{uncoherent file versions: gregoriotex-main.tex is in version \number\gre@gregorioversion \space\space while #1 is in version \number#2}}%
\IfStrEq*{#2}{\gre@gregoriotexversion}{}{%else
\gre@error{Version Inconsistency!\MessageBreak gregoriotex-main.tex is in version \number\gre@gregoriotexversion \space\space while #1 is in version \number#2}}%
}%

% Macro called by scores.
Expand All @@ -177,9 +177,9 @@
% #1 is the version of GregorioTeX the score is made for.

\def\GregorioTeXAPIVersion#1{%
\StrBefore{\gre@gregorioversion}{.}[\gre@gregoriomajorversion]%
\StrBefore{\gre@gregoriotexversion}{.}[\gre@gregoriomajorversion]%
\IfBeginWith{#1}{\gre@gregoriomajorversion}{\relax}{%else
\gre@error{GregorioTeX is in version \gre@gregorioversion \space\space while a score you included requires version #1. Please recompile your scores}}%
\gre@error{Version Inconsistency!\MessageBreak GregorioTeX is in version \gre@gregoriotexversion \space\space while a score you included requires version #1. Please recompile your scores}}%
}%

\RequireLuaModule{gregoriotex}%
Expand All @@ -189,11 +189,17 @@
\directlua{gregoriotex.init(arg, true)}%
\fi %

\xdef\gre@gregoriotexluaversion{\directlua{tex.write(gregoriotex.get_gregorioversion())}}%
\xdef\gre@gregoriotexluaversion{\directlua{tex.write(gregoriotex.get_gregoriotexluaversion())}}%

% Test to make sure that gregoriotex.lua is of the same version.
\IfStrEq*{\gre@gregoriotexluaversion}{\gre@gregorioversion}{}{%else
\gre@error{uncoherent file versions: gregoriotex-main.tex is in version \number\gre@gregorioversion \space\space while gregoriotex.lua is in version \gre@gregoriotexluaversion}}%
\IfStrEq*{\gre@gregoriotexluaversion}{\gre@gregoriotexversion}{}{%else
\gre@error{Version Inconsistency!\MessageBreak gregoriotex-main.tex is in version \number\gre@gregoriotexversion \space\space while gregoriotex.lua is in version \gre@gregoriotexluaversion}}%

% Test to make sure gregorio executable is of the same version.
\xdef\gre@gregorioversion{\directlua{tex.write(gregoriotex.get_gregorioversion())}}%
\IfBeginWith*{\gre@gregorioversion}{\gre@gregoriotexversion}
{\relax} % true
{\gre@error{Version Inconsistency!\MessageBreak GregorioTeX is in version \gre@gregoriotexversion\MessageBreak while Gregorio executable is in version \gre@gregorioversion}} %false


%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
19 changes: 18 additions & 1 deletion tex/gregoriotex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,26 @@ local function direct_gabc(gabc, header, allow_deprecated)
os.remove(snippet_logname)
end

local function get_gregorioversion()
local function get_gregoriotexluaversion()
return internalversion
end

local function get_gregorioversion()
local p = io.popen('gregorio --version', 'r')
if p == nil then
err("\nSomething went wrong when executing\n gregorio --version\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)
else
gregorioversion = p:read("*a")
p:close()
gregorioversion = string.sub(gregorioversion,10,string.find(gregorioversion,'\n')-2)
end
return gregorioversion
end

local function check_font_version()
local gregoriofont = get_font_by_name('gre@font@music')
if gregoriofont then
Expand Down Expand Up @@ -1286,6 +1302,7 @@ gregoriotex.atScoreEnd = atScoreEnd
gregoriotex.atScoreBeginning = atScoreBeginning
gregoriotex.check_font_version = check_font_version
gregoriotex.get_gregorioversion = get_gregorioversion
gregoriotex.get_gregoriotexluaversion = get_gregoriotexluaversion
gregoriotex.map_font = map_font
gregoriotex.init_variant_font = init_variant_font
gregoriotex.change_score_glyph = change_score_glyph
Expand Down

0 comments on commit ca74fd4

Please sign in to comment.