LCOV - code coverage report
Current view: top level - config - ConfigInstall.inc (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 57 73 78.1 %
Date: 2024-10-18 14:00:25 Functions: 20 26 76.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-2023 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : 
      23             : #include "Config.h"
      24             : #include "version.h"
      25             : #include <cstdlib>
      26             : #include <cstring>
      27             : #include <dlfcn.h>
      28             : 
      29             : namespace PLMD {
      30             : namespace config {
      31             : 
      32             : namespace {
      33             : /// local tool that, given a string, returns a new string which is:
      34             : /// - enclosed in single quotes (')
      35             : /// - with all single quotes escaped
      36        4655 : std::string escapeForSingleQuote(const std::string& input) {
      37             :   std::string escaped;
      38       93105 :   for (char c : input) {
      39       88450 :     if (c == '\'') {
      40             :       escaped += "'\\''";
      41             :     } else {
      42       88450 :       escaped += c;
      43             :     }
      44             :   }
      45        9310 :   return "'" + escaped + "'";
      46             : }
      47             : }
      48             : 
      49             : // This is a fix to allow conda to correctly replace paths in binary files.
      50             : // These functions should not be static or they will be optimized away!
      51        9213 : const char* plumed_root() {return "/home/runner/opt/lib/plumed";}
      52        1550 : const char* plumed_soext() {return "so";}
      53         931 : const char* plumed_htmldir() {return "/home/runner/opt/share/doc/plumed";}
      54         930 : const char* plumed_includedir() {return "/home/runner/opt/include";}
      55         931 : const char* plumed_program_name() {return "plumed";}
      56             : 
      57        1550 : std::string getSoExt() {
      58        1550 :   return plumed_soext();
      59             : }
      60             : 
      61        3587 : bool isInstalled() {
      62        3587 :   return true;
      63             : }
      64             : 
      65        9213 : std::string getPlumedRoot() {
      66        9213 :   char *env = std::getenv("PLUMED_ROOT");
      67             :   std::string ss;
      68        9213 :   if( env == NULL) {
      69        9213 :     ss=plumed_root();
      70             :   } else {
      71           0 :     ss=std::string( env );
      72             :   }
      73        9213 :   return ss;
      74             : }
      75             : 
      76         931 : std::string getPlumedHtmldir() {
      77         931 :   if(!isInstalled()) return getPlumedRoot();
      78         931 :   char *env = std::getenv("PLUMED_HTMLDIR");
      79             :   std::string ss;
      80         931 :   if( env == NULL) {
      81         931 :     ss=plumed_htmldir();
      82             :   } else {
      83           0 :     ss=std::string( env );
      84             :   }
      85             :   return ss;
      86             : }
      87             : 
      88         931 : std::string getPlumedIncludedir() {
      89         931 :   if(!isInstalled()) return getPlumedRoot()+"/src/include";
      90         931 :   char *env = std::getenv("PLUMED_INCLUDEDIR");
      91             :   std::string ss;
      92         931 :   if( env == NULL) {
      93         930 :     ss=plumed_includedir();
      94             :   } else {
      95           2 :     ss=std::string( env );
      96             :   }
      97             :   return ss;
      98             : }
      99             : 
     100         931 : std::string getPlumedProgramName() {
     101         931 :   if(!isInstalled()) return "plumed";
     102         931 :   char *env = std::getenv("PLUMED_PROGRAM_NAME");
     103             :   std::string ss;
     104         931 :   if( env == NULL) {
     105         931 :     ss=plumed_program_name();
     106             :   } else {
     107           0 :     ss=std::string( env );
     108             :   }
     109             :   return ss;
     110             : }
     111             : 
     112         931 : std::string getEnvCommand() {
     113        1862 :   return "env PLUMED_ROOT="+escapeForSingleQuote(getPlumedRoot())+
     114        3724 :          " PLUMED_VERSION="+escapeForSingleQuote(getVersionLong())+
     115        3724 :          " PLUMED_HTMLDIR="+escapeForSingleQuote(getPlumedHtmldir())+
     116        3724 :          " PLUMED_INCLUDEDIR="+escapeForSingleQuote(getPlumedIncludedir())+
     117        3724 :          " PLUMED_PROGRAM_NAME="+escapeForSingleQuote(getPlumedProgramName())+
     118        2793 :          " PLUMED_IS_INSTALLED='"+(true?"yes":"no")+"'";
     119             : }
     120             : 
     121           4 : std::string getVersion() {
     122           4 :   return PLUMED_VERSION_SHORT;
     123             : }
     124             : 
     125        2247 : std::string getVersionLong() {
     126        2247 :   return PLUMED_VERSION_LONG;
     127             : }
     128             : 
     129        1289 : std::string getVersionGit() {
     130        1289 :   return PLUMED_VERSION_GIT;
     131             : }
     132             : 
     133          40 : std::string getMakefile() {
     134             :   static const unsigned char confu [] = {
     135             : #include "Makefile.conf.xxd"
     136             :     , 0x00
     137             :   };
     138             :   auto conf=(char*)confu;
     139          40 :   return std::string(conf,conf+std::strlen(conf));
     140             : }
     141             : 
     142           0 : bool hasMatheval() {
     143             : #ifdef __PLUMED_HAS_MATHEVAL
     144             :   return true;
     145             : #else
     146           0 :   return false;
     147             : #endif
     148             : }
     149             : 
     150           0 : bool hasDlopen() {
     151             : #ifdef __PLUMED_HAS_DLOPEN
     152           0 :   return true;
     153             : #else
     154             :   return false;
     155             : #endif
     156             : }
     157             : 
     158           0 : bool hasCregex() {
     159             : #ifdef __PLUMED_HAS_CREGEX
     160             :   return true;
     161             : #else
     162           0 :   return false;
     163             : #endif
     164             : }
     165             : 
     166           0 : bool hasMolfile() {
     167             : #ifdef __PLUMED_HAS_MOLFILE_PLUGINS
     168           0 :   return true;
     169             : #else
     170             :   return false;
     171             : #endif
     172             : }
     173             : 
     174           0 : bool hasExternalMolfile() {
     175             : #ifdef __PLUMED_HAS_EXTERNAL_MOLFILE_PLUGINS
     176             :   return true;
     177             : #else
     178           0 :   return false;
     179             : #endif
     180             : }
     181             : 
     182           0 : bool hasZlib() {
     183             : #ifdef __PLUMED_HAS_ZLIB
     184           0 :   return true;
     185             : #else
     186             :   return false;
     187             : #endif
     188             : }
     189             : 
     190        1289 : std::string getCompilationDate() {
     191        1289 :   return __DATE__;
     192             : }
     193             : 
     194        1289 : std::string getCompilationTime() {
     195        1289 :   return __TIME__;
     196             : }
     197             : 
     198        1289 : std::string getLibraryPath() {
     199             : #ifdef __PLUMED_HAS_DLADDR
     200             :   Dl_info info;
     201        1289 :   if(dladdr((void*)getLibraryPath,&info)) {
     202        1289 :     return info.dli_fname;
     203             :   } else {
     204           0 :     return "";
     205             :   }
     206             : #endif
     207             : 
     208             : }
     209             : 
     210             : 
     211             : }
     212             : }
     213             : 

Generated by: LCOV version 1.16