NCBI C++ ToolKit
proj_projects.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: proj_projects.cpp 76048 2017-01-09 19:49:55Z gouriano $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Viatcheslav Gorelenkov
27  *
28  */
29 #include <ncbi_pch.hpp>
30 #include "proj_projects.hpp"
31 #include "proj_builder_app.hpp"
32 #include "proj_tree.hpp"
33 #include "ptb_err_codes.hpp"
34 
35 #include <corelib/ncbienv.hpp>
36 #include <util/xregexp/regexp.hpp>
38 
39 //-----------------------------------------------------------------------------
41  const string& file_full_path)
42 {
43  m_PassAll = false;
44  m_ExcludePotential = false;
45  m_RootSrcDir = root_src_dir;
46  if (CDirEntry(file_full_path).IsFile()) {
47  InitFromFile(file_full_path);
48  } else {
49  InitFromString(file_full_path);
50  }
51  string dll_subtree = GetApp().GetConfig().Get("ProjectTree", "dll");
52  string s = ConvertToMask("dll");
54  if (GetApp().GetBuildType().GetType() == CBuildType::eDll) {
55  m_listEnabled.push_back(s);
56  }
57  } else {
58  m_listDisabled.push_back(s);
59  }
60 }
61 
62 string CProjectsLstFileFilter::ConvertToMask(const string& name)
63 {
64  string s = NStr::Replace(name,"\\","/");
65  if (NStr::EndsWith(s,'$')) {
66  s.erase(s.size()-1,1);
67  while (NStr::EndsWith(s,'/')) {
68  s.erase(s.size()-1,1);
69  }
70  s += "/$";
71  } else {
72  s += '/';
73  }
74  return s;
75 }
76 
77 
78 void CProjectsLstFileFilter::InitFromString(const string& subtree)
79 {
80  string separator;
81  separator += CDirEntry::GetPathSeparator();
82  string nsubtree = NStr::Replace(subtree, "/",separator);
83  string sub = CDirEntry::AddTrailingPathSeparator(nsubtree);
85  if (!m_PassAll) {
86  string s = CDirEntry::CreateRelativePath(m_RootSrcDir,nsubtree);
87  NStr::ReplaceInPlace(s,"\\","/");
88  if (NStr::EndsWith(s,'/')) {
89  s.erase(s.size()-1,1);
90  }
91  m_listEnabled.push_back( s );
92  }
93 // m_ExcludePotential = true;
95 }
96 
97 void CProjectsLstFileFilter::InitFromFile(const string& file_full_path)
98 {
99  CNcbiIfstream ifs(file_full_path.c_str(), IOS_BASE::in | IOS_BASE::binary);
100  if ( !ifs )
101  NCBI_THROW(CProjBulderAppException, eFileOpen, file_full_path);
102 
103  string strline;
104  while ( NcbiGetlineEOL(ifs, strline) ) {
105 
106  // skip "update" statements
107  if (strline.find(" update-only") != NPOS)
108  continue;
109 
111  if (strline.empty()) {
112  continue;
113  }
114  if ( NStr::StartsWith(strline, "#include") ) {
115  NStr::ReplaceInPlace(strline,"#include","",0,1);
117  NStr::ReplaceInPlace(strline,"\"","");
118  string name = CDirEntry::ConvertToOSPath(strline);
119  if (CDirEntry::IsAbsolutePath(name)) {
120  InitFromFile( name );
121  } else {
122  CDirEntry d(file_full_path);
124  }
125  } else if ( NStr::StartsWith(strline, "#") ) {
126  continue;
127  } else if ( NStr::StartsWith(strline, "/*") ) {
128  continue;
129  } else {
130  if ( NStr::StartsWith(strline, "-") ) {
131  strline.erase(0,1);
132  string s = ConvertToMask( strline );
133  m_listDisabled.push_back( s );
134  } else {
135  string s = ConvertToMask( strline );
136  m_listEnabled.push_back( s );
137  }
138  }
139  }
140 }
141 
142 string CProjectsLstFileFilter::GetAllowedTagsInfo(const string& file_full_path)
143 {
144  if (!CDirEntry(file_full_path).IsFile()) {
145  return kEmptyStr;
146  }
147  CNcbiIfstream ifs(file_full_path.c_str(), IOS_BASE::in | IOS_BASE::binary);
148  if (!ifs) {
149  return kEmptyStr;
150  }
151  string strline;
152  string key("#define TAGS");
153  while ( NcbiGetlineEOL(ifs, strline) ) {
155  if ( NStr::StartsWith(strline, key) ) {
157  NStr::ReplaceInPlace(strline,"[",kEmptyStr);
158  NStr::ReplaceInPlace(strline,"]",kEmptyStr);
160  return strline;
161  }
162  }
163  return kEmptyStr;
164 }
165 
166 bool CProjectsLstFileFilter::CheckProject(const string& project_base_dir, bool* weak) const
167 {
168  string proj_dir = CDirEntry::CreateRelativePath(m_RootSrcDir,project_base_dir);
169  proj_dir = NStr::Replace(proj_dir,"\\","/");
170  proj_dir += '/';
171  bool include_ok = false;
172  if (!m_PassAll) {
173  ITERATE(list<string>, s, m_listEnabled) {
174  string str(*s);
175  CRegexp rx("^" + str);
176  if (rx.IsMatch(proj_dir)) {
177  include_ok = true;
178  break;
179  } else if (weak) {
180  list<string> splitmask, splitdir;
183  if (splitmask.size() > splitdir.size()) {
184  splitmask.resize(splitdir.size());
185  string reduced( NStr::Join(splitmask,"/"));
186  CRegexp r("^" + reduced);
187  if (r.IsMatch(proj_dir)) {
188  *weak = true;
189  return false;
190  }
191  }
192  }
193  }
194  if ( !include_ok )
195  return false;
196  }
197  ITERATE(list<string>, s, m_listDisabled) {
198  string str(*s);
199  str += "$";
200  CRegexp rx("^" + str);
201  if (rx.IsMatch(proj_dir)) {
202  if (!m_PassAll) {
203  PTB_INFO_EX(project_base_dir, ePTB_NoError,
204  "skipped because of this rule in LST file: " << *s);
205  }
206  return false;
207  }
208  }
209  return true;
210 }
211 
212 
CDirEntry –.
Definition: ncbifile.hpp:262
static EMsvcPlatform GetMsvcPlatform(void)
CProjBulderAppException –.
const string & GetBuildRoot(void) const
list< string > m_listEnabled
string ConvertToMask(const string &name)
void InitFromFile(const string &file_full_path)
virtual bool CheckProject(const string &project_base_dir, bool *weak=0) const
void InitFromString(const string &subtree)
static string GetAllowedTagsInfo(const string &file_full_path)
list< string > m_listDisabled
CRegexp –.
Definition: regexp.hpp:70
static const char * str(char *buf, int n)
Definition: stats.c:84
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
string GetDir(EIfEmptyPath mode=eIfEmptyPath_Current) const
Get the directory component for this directory entry.
Definition: ncbifile.cpp:475
static bool IsAbsolutePath(const string &path)
Check if a "path" is absolute for the current OS.
Definition: ncbifile.cpp:508
static string AddTrailingPathSeparator(const string &path)
Add trailing path separator, if needed.
Definition: ncbifile.cpp:455
static string CreateRelativePath(const string &path_from, const string &path_to)
Create a relative path between two points in the file system specified by their absolute paths.
Definition: ncbifile.cpp:599
static string ConcatPathEx(const string &first, const string &second)
Concatenate two parts of the path for any OS.
Definition: ncbifile.cpp:791
static string ConvertToOSPath(const string &path)
Convert "path" on any OS to the current OS-dependent path.
Definition: ncbifile.cpp:745
static char GetPathSeparator(void)
Get path separator symbol specific for the current platform.
Definition: ncbifile.cpp:433
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
Definition: regexp.cpp:193
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, string::size_type *count=NULL)
Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line)
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
#define NPOS
Definition: ncbistr.hpp:133
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3314
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
@ fSplit_Truncate
Definition: ncbistr.hpp:2501
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
const struct ncbi::grid::netcache::search::fields::KEY key
Defines unified interface to application:
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
CProjBulderApp & GetApp(void)
access to App singleton
#define PTB_INFO_EX(file, err_code, msg)
@ ePTB_NoError
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
Modified on Tue Apr 23 07:40:01 2024 by modify_doxy.py rev. 669887