<commit_before>/*  Part of SWI-Prolog

    Author:        <NAME> and <NAME>
    E-mail:        <EMAIL>
    WWW:           http://www.swi-prolog.org
    Copyright (C): 2014, VU University Amsterdam

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(check_installation,
	  [ check_installation/0
	  ]).

/** <module> Check installation issues and features

This library performs checks on  the   installed  system to verify which
optional components are available and  whether   all  libaries that load
shared objects/DLLs can be loaded.
*/

%%	component(?Component, -Features) is nondet.
%
%	This predicate describes the test components. Features is a dict
%	with the following components:
%
%	  - test:Goal
%	  (Additional) test that must succeed for the component to be
%	  functional.
%	  - url:URL
%	  URL with additional information, relative to
%	  =|http://www.swi-prolog.org/build/issues/|=.  If not provided,
%	  the library file with extension =|.html|= is used.
%	  - optional:true
%	  If the library does not exist, do not complain.
%	  - os:OS
%	  One of =windows=, =unix= or =linux=. If present, the component
%	  is only checked for if we are running on a version of the
%	  specified operating system.
%	  - features:Goal
%	  After successful evaluation that loading and basic operation
%	  of the component succeeds, run this to check additional
%	  features.

% Feature tests
component(gmp,
	  _{ test:current_prolog_flag(bounded, false),
	     url:'gmp.html'
	   }).
component(command_line_editing,
	  _{ test:current_predicate(system:rl_add_history/1),
	     url:'cmdlineedit.html'
	   }).
% Packages that depend on foreign libraries
component(library(archive), _{features:archive_features}).
component(library(cgi), _{}).
component(library(crypt), _{}).
component(library(db), _{optional:true}).
component(library(double_metaphone), _{}).
component(library(filesex), _{}).
component(library(http/http_stream), _{}).
component(library(http/json), _{}).
component(library(isub), _{}).
component(library(jpl), _{}).
component(library(memfile), _{}).
component(library(mime), _{}).
component(library(odbc), _{}).
component(library(pce),
	  _{pre:load_foreign_library(pce_principal:foreign(pl2xpce)),
	    url:'xpce.html'}).
component(library(pdt_console), _{}).
component(library(porter_stem), _{}).
component(library(process), _{}).
component(library(readutil), _{}).
component(library(rlimit), _{os:unix}).
component(library(semweb/rdf_db), _{}).
component(library(semweb/rdf_ntriples), _{}).
component(library(semweb/turtle), _{}).
component(library(sgml), _{}).
component(library(sha), _{}).
component(library(snowball), _{}).
component(library(socket), _{}).
component(library(ssl), _{}).
component(library(syslog), _{os:unix}).
component(library(table), _{}).
component(library(time), _{}).
component(library(tipc/tipc), _{os:linux}).
component(library(unicode), _{}).
component(library(uri), _{}).
component(library(uuid), _{}).
component(library(zlib), _{}).

issue_base('http://www.swi-prolog.org/build/issues/').

:- thread_local
	issue/1.

:- meta_predicate
	run_silent(0, +).

%%	check_installation
%
%	Check features of the installed   system. Performs the following
%	tests:
%
%	  1. Test whether features that depend on optional libraries
%	     are present (e.g., unbounded arithmetic support)
%	  2. Test that all standard libraries that depend on foreign
%	     code are present.
%
%	If issues are found it prints a   diagnostic message with a link
%	to a wiki page with additional information about the issue.

check_installation :-
	print_message(informational, installation(checking)),
	retractall(issue(_)),
	forall(component(Source, _Properties),
	       check_installation(Source)),
	findall(I, retract(issue(I)), Issues),
	(   Issues == []
	->  print_message(informational, installation(perfect))
	;   length(Issues, Count),
	    print_message(warning, installation(imperfect(Count)))
	).

check_installation(Source) :-
	component(Source, Properties), !,
	check_installation(Source, Properties.put(source,Source)).

check_installation(Source, Properties) :-
	compound(Source), !,
	check_source(Source, Properties).
check_installation(Feature, Properties) :-
	print_message(informational, installation(checking(Feature))),
	(   call(Properties.test)
	->  print_message(informational, installation(ok))
	;   print_issue(installation(missing(Properties)))
	).

check_source(_Source, Properties) :-
	OS = Properties.get(os),
	\+ current_os(OS), !.
check_source(Source, Properties) :-
	exists_source(Source), !,
	print_message(informational, installation(loading(Source))),
	(   run_silent(( (   Pre = Properties.get(pre)
			 ->  call(Pre)
			 ;   true
			 ),
			 load_files(Source, [silent(true)])
		       ),
		       Properties.put(action, load))
	->  test_component(Properties),
	    print_message(informational, installation(ok)),
	    check_features(Properties)
	;   true
	).
check_source(_Source, Properties) :-<commit_msg>Avoid reloading on repeated check_installation/0.<commit_after>/*  Part of SWI-Prolog

    Author:        <NAME> and <NAME>
    E-mail:        <EMAIL>
    WWW:           http://www.swi-prolog.org
    Copyright (C): 2014, VU University Amsterdam

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(check_installation,
	  [ check_installation/0
	  ]).

/** <module> Check installation issues and features

This library performs checks on  the   installed  system to verify which
optional components are available and  whether   all  libaries that load
shared objects/DLLs can be loaded.
*/

%%	component(?Component, -Features) is nondet.
%
%	This predicate describes the test components. Features is a dict
%	with the following components:
%
%	  - test:Goal
%	  (Additional) test that must succeed for the component to be
%	  functional.
%	  - url:URL
%	  URL with additional information, relative to
%	  =|http://www.swi-prolog.org/build/issues/|=.  If not provided,
%	  the library file with extension =|.html|= is used.
%	  - optional:true
%	  If the library does not exist, do not complain.
%	  - os:OS
%	  One of =windows=, =unix= or =linux=. If present, the component
%	  is only checked for if we are running on a version of the
%	  specified operating system.
%	  - features:Goal
%	  After successful evaluation that loading and basic operation
%	  of the component succeeds, run this to check additional
%	  features.

% Feature tests
component(gmp,
	  _{ test:current_prolog_flag(bounded, false),
	     url:'gmp.html'
	   }).
component(command_line_editing,
	  _{ test:current_predicate(system:rl_add_history/1),
	     url:'cmdlineedit.html'
	   }).
% Packages that depend on foreign libraries
component(library(archive), _{features:archive_features}).
component(library(cgi), _{}).
component(library(crypt), _{}).
component(library(db), _{optional:true}).
component(library(double_metaphone), _{}).
component(library(filesex), _{}).
component(library(http/http_stream), _{}).
component(library(http/json), _{}).
component(library(isub), _{}).
component(library(jpl), _{}).
component(library(memfile), _{}).
component(library(mime), _{}).
component(library(odbc), _{}).
component(library(pce),
	  _{pre:load_foreign_library(pce_principal:foreign(pl2xpce)),
	    url:'xpce.html'}).
component(library(pdt_console), _{}).
component(library(porter_stem), _{}).
component(library(process), _{}).
component(library(readutil), _{}).
component(library(rlimit), _{os:unix}).
component(library(semweb/rdf_db), _{}).
component(library(semweb/rdf_ntriples), _{}).
component(library(semweb/turtle), _{}).
component(library(sgml), _{}).
component(library(sha), _{}).
component(library(snowball), _{}).
component(library(socket), _{}).
component(library(ssl), _{}).
component(library(syslog), _{os:unix}).
component(library(table), _{}).
component(library(time), _{}).
component(library(tipc/tipc), _{os:linux}).
component(library(unicode), _{}).
component(library(uri), _{}).
component(library(uuid), _{}).
component(library(zlib), _{}).

issue_base('http://www.swi-prolog.org/build/issues/').

:- thread_local
	issue/1.

:- meta_predicate
	run_silent(0, +).

%%	check_installation
%
%	Check features of the installed   system. Performs the following
%	tests:
%
%	  1. Test whether features that depend on optional libraries
%	     are present (e.g., unbounded arithmetic support)
%	  2. Test that all standard libraries that depend on foreign
%	     code are present.
%
%	If issues are found it prints a   diagnostic message with a link
%	to a wiki page with additional information about the issue.

check_installation :-
	print_message(informational, installation(checking)),
	retractall(issue(_)),
	forall(component(Source, _Properties),
	       check_installation(Source)),
	findall(I, retract(issue(I)), Issues),
	(   Issues == []
	->  print_message(informational, installation(perfect))
	;   length(Issues, Count),
	    print_message(warning, installation(imperfect(Count)))
	).

check_installation(Source) :-
	component(Source, Properties), !,
	check_installation(Source, Properties.put(source,Source)).

check_installation(Source, Properties) :-
	compound(Source), !,
	check_source(Source, Properties).
check_installation(Feature, Properties) :-
	print_message(informational, installation(checking(Feature))),
	(   call(Properties.test)
	->  print_message(informational, installation(ok))
	;   print_issue(installation(missing(Properties)))
	).

check_source(_Source, Properties) :-
	OS = Properties.get(os),
	\+ current_os(OS), !.
check_source(Source, Properties) :-
	exists_source(Source), !,
	print_message(informational, installation(loading(Source))),
	(   run_silent(( (   Pre = Properties.get(pre)
			 ->  call(Pre)
			 ;   true
			 ),
			 load_files(Source, [silent(true), if(not_loaded)])
		       ),
		       Properties.put(action, load))
	->  test_component(Properties),
	    print_message(informational, installation(ok)),
	    check_features(Properties)
	;   true
	).
check_source(_Source, Properties) :-
{'fraction_non_alphanumeric': 0.12231337161607875, 'fraction_numerical': 0.003855619360131255, 'mean_word_length': 4.486498649864987, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7460840', 'n_tokens_mistral': 3768, 'n_tokens_neox': 3531, 'n_words': 1041}