From e88a94c7248a390724fa7c41a02979587e8380b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Thu, 3 Oct 2019 16:50:27 +0200 Subject: [PATCH] Improve detection of X13 binary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — 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 --- src/initialize_dseries_class.m | 36 +++++------------------ src/utilities/x13/select_x13_binary.m | 42 +++++++++++++++++++-------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/initialize_dseries_class.m b/src/initialize_dseries_class.m index 0b239a0..f3a3180 100644 --- a/src/initialize_dseries_class.m +++ b/src/initialize_dseries_class.m @@ -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); diff --git a/src/utilities/x13/select_x13_binary.m b/src/utilities/x13/select_x13_binary.m index 9725cd7..33bea65 100644 --- a/src/utilities/x13/select_x13_binary.m +++ b/src/utilities/x13/select_x13_binary.m @@ -1,6 +1,10 @@ -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 -- GitLab