Commit ca414338 authored by Sébastien Villemot's avatar Sébastien Villemot

Improve detection of X13 binary

— On GNU/Linux, the locally installed binary now has priority over the
  system-wide binary
— Do not require 32-bit binary if we are on a 64-bit system and the 64-bit
  binary is there (or vice versa)
— Code factorization in the detection logic
parent 82f10685
Pipeline #1995 passed with stage
in 1 minute and 6 seconds
......@@ -18,28 +18,6 @@ function initialize_dseries_class()
% Get the path to the dseries toolbox.
dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
% Check that the x13 binary is available
nox13 = false;
if ismac()
if ~exist([dseries_src_root '../externals/x13/osx/64/x13as'], 'file')
nox13 = true;
end
elseif isunix()
[status, ~] = system('which x13as');
if status && ~(exist([dseries_src_root '../externals/x13/linux/64/x13as'], 'file') && exist([dseries_src_root '../externals/x13/linux/32/x13as'], 'file'))
nox13 = true;
end
elseif ispc()
if ~(exist([dseries_src_root '../externals/x13/windows/64/x13as.exe'], 'file') && exist([dseries_src_root '../externals/x13/windows/32/x13as.exe'], 'file'))
nox13 = true;
end
else
error('Unsupported platform.')
end
if nox13
warning('X13 binary is not available.\nIf you are under Debian or Ubuntu, you can install it through your package manager, with ''apt install x13as''.\nIf you are under Windows or macOS, this probably means that you did not install the dseries toolbox through an official package.\n');
end
% Set the subfolders to be added in the path.
p = {'read'; ...
'utilities/is'; ...
......@@ -52,12 +30,8 @@ p = {'read'; ...
'utilities/print'; ...
'utilities/variables'; ...
'utilities/cumulate'; ...
'utilities/struct'};
% Add /utilities/x13' if x13 binary is available.
if ~nox13
p{end+1} = 'utilities/x13';
end
'utilities/struct'; ...
'utilities/x13'};
% Add missing routines if dynare is not in the path
if ~exist('isint','file')
......@@ -136,4 +110,10 @@ end
P = cellfun(@(c)[dseries_src_root c], p, 'uni', false);
addpath(P{:});
% If x13 binary is not available, display a warning, and remove the x13
% subdirectory from the path
if isempty(select_x13_binary(true));
rmpath([dseries_src_root 'utilities/x13']);
end
assignin('caller', 'dseries_src_root', dseries_src_root);
function x13_binary = select_x13_binary()
function x13_binary = select_x13_binary(warn_only)
% Copyright (C) 2017 Dynare Team
% Returns the path to the X13 binary. If no X13 binary can be found, raises an
% error (unless warn_only=true, in which case it returns an empty string and
% displays a warning).
% Copyright (C) 2017-2019 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
......@@ -15,6 +19,10 @@ function x13_binary = select_x13_binary()
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if nargin < 1
warn_only = false;
end
dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
dseries_x13_root = sprintf('%s%s%s%s%s%s%s', dseries_src_root, '..', filesep(), 'externals', filesep(), 'x13', filesep());
......@@ -26,15 +34,16 @@ if ismac()
x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as');
end
elseif isunix()
[status, x13_binary] = system('which x13as');
if ~status
x13_binary = deblank(x13_binary);
x13_binary = sprintf('%s%s%s', dseries_x13_root, 'linux', filesep());
if is64bit()
x13_binary = sprintf('%s%s%s%s', x13_binary, '64', filesep(), 'x13as');
else
x13_binary = sprintf('%s%s%s', dseries_x13_root, 'linux', filesep());
if is64bit()
x13_binary = sprintf('%s%s%s%s', x13_binary, '64', filesep(), 'x13as');
else
x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as');
x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as');
end
if ~exist(x13_binary, 'file')
[status, x13_binary] = system('which x13as');
if ~status
x13_binary = deblank(x13_binary);
end
end
elseif ispc()
......@@ -45,5 +54,14 @@ elseif ispc()
x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as.exe');
end
else
error('X13 binary is not available for this plateform')
end
\ No newline at end of file
error('Unsupported platform')
end
if ~exist(x13_binary, 'file')
if warn_only
warning('X13 binary is not available.\nIf you are under Debian or Ubuntu, you can install it through your package manager, with ''apt install x13as''.\nIf you are under Windows or macOS, this probably means that you did not install the dseries toolbox through an official package.\n');
x13_binary = '';
else
error('Can''t find X13 binary');
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment