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 70023 2015-11-30 14:28:08Z 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  if (GetApp().IsCMakeMode()) {
94  return;
95  }
96 // m_ExcludePotential = true;
98 }
99 
100 void CProjectsLstFileFilter::InitFromFile(const string& file_full_path)
101 {
102  CNcbiIfstream ifs(file_full_path.c_str(), IOS_BASE::in | IOS_BASE::binary);
103  if ( !ifs )
104  NCBI_THROW(CProjBulderAppException, eFileOpen, file_full_path);
105 
106  string strline;
107  while ( NcbiGetlineEOL(ifs, strline) ) {
108 
109  // skip "update" statements
110  if (strline.find(" update-only") != NPOS)
111  continue;
112 
114  if (strline.empty()) {
115  continue;
116  }
117  if ( NStr::StartsWith(strline, "#include") ) {
118  NStr::ReplaceInPlace(strline,"#include","",0,1);
120  NStr::ReplaceInPlace(strline,"\"","");
121  string name = CDirEntry::ConvertToOSPath(strline);
122  if (CDirEntry::IsAbsolutePath(name)) {
123  InitFromFile( name );
124  } else {
125  CDirEntry d(file_full_path);
127  }
128  } else if ( NStr::StartsWith(strline, "#") ) {
129  continue;
130  } else if ( NStr::StartsWith(strline, "/*") ) {
131  continue;
132  } else {
133  if ( NStr::StartsWith(strline, "-") ) {
134  strline.erase(0,1);
135  string s = ConvertToMask( strline );
136  m_listDisabled.push_back( s );
137  } else {
138  string s = ConvertToMask( strline );
139  m_listEnabled.push_back( s );
140  }
141  }
142  }
143 }
144 
145 string CProjectsLstFileFilter::GetAllowedTagsInfo(const string& file_full_path)
146 {
147  if (!CDirEntry(file_full_path).IsFile()) {
148  return kEmptyStr;
149  }
150  CNcbiIfstream ifs(file_full_path.c_str(), IOS_BASE::in | IOS_BASE::binary);
151  if (!ifs) {
152  return kEmptyStr;
153  }
154  string strline;
155  string key("#define TAGS");
156  while ( NcbiGetlineEOL(ifs, strline) ) {
158  if ( NStr::StartsWith(strline, key) ) {
159  NStr::ReplaceInPlace(strline,key,kEmptyStr);
160  NStr::ReplaceInPlace(strline,"[",kEmptyStr);
161  NStr::ReplaceInPlace(strline,"]",kEmptyStr);
163  return strline;
164  }
165  }
166  return kEmptyStr;
167 }
168 
169 bool CProjectsLstFileFilter::CheckProject(const string& project_base_dir, bool* weak) const
170 {
171  string proj_dir = CDirEntry::CreateRelativePath(m_RootSrcDir,project_base_dir);
172  proj_dir = NStr::Replace(proj_dir,"\\","/");
173  proj_dir += '/';
174  bool include_ok = false;
175  if (!m_PassAll) {
176  ITERATE(list<string>, s, m_listEnabled) {
177  string str(*s);
178  CRegexp rx("^" + str);
179  if (rx.IsMatch(proj_dir)) {
180  include_ok = true;
181  break;
182  } else if (weak) {
183  list<string> splitmask, splitdir;
186  if (splitmask.size() > splitdir.size()) {
187  splitmask.resize(splitdir.size());
188  string reduced( NStr::Join(splitmask,"/"));
189  CRegexp r("^" + reduced);
190  if (r.IsMatch(proj_dir)) {
191  *weak = true;
192  return false;
193  }
194  }
195  }
196  }
197  if ( !include_ok )
198  return false;
199  }
200  ITERATE(list<string>, s, m_listDisabled) {
201  string str(*s);
202  str += "$";
203  CRegexp rx("^" + str);
204  if (rx.IsMatch(proj_dir)) {
205  if (!m_PassAll) {
206  PTB_INFO_EX(project_base_dir, ePTB_NoError,
207  "skipped because of this rule in LST file: " << *s);
208  }
209  return false;
210  }
211  }
212  return true;
213 }
214 
215 
void InitFromFile(const string &file_full_path)
static bool IsAbsolutePath(const string &path)
Check if a "path" is absolute for the current OS.
Definition: ncbifile.cpp:495
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3367
CProjBulderApp & GetApp(void)
access to App singleton
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) ...
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3190
static string ConcatPathEx(const string &first, const string &second)
Concatenate two parts of the path for any OS.
Definition: ncbifile.cpp:781
CDirEntry –.
Definition: ncbifile.hpp:241
const string & GetBuildRoot(void) const
string GetDir(EIfEmptyPath mode=eIfEmptyPath_Current) const
Get the directory component for this directory entry.
Definition: ncbifile.cpp:461
Defines unified interface to application:
static char GetPathSeparator(void)
Get path separator symbol specific for the current platform.
Definition: ncbifile.cpp:419
static string GetAllowedTagsInfo(const string &file_full_path)
#define kEmptyStr
Definition: ncbistr.hpp:120
Merge adjacent delimiters.
Definition: ncbistr.hpp:2377
CProjBulderAppException –.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3319
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:893
#define NPOS
Definition: ncbistr.hpp:130
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
void InitFromString(const string &subtree)
list< string > m_listEnabled
#define PTB_INFO_EX(file, err_code, msg)
CRegexp –.
Definition: regexp.hpp:69
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:5440
string ConvertToMask(const string &name)
const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
static string Join(const list< string > &arr, const CTempString delim)
Join strings using the specified delimiter.
Definition: ncbistr.cpp:3633
virtual bool CheckProject(const string &project_base_dir, bool *weak=0) const
list< string > m_listDisabled
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
Definition: regexp.cpp:188
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters.
Definition: ncbiapp.hpp:665
static const char * str(char *buf, int n)
Definition: stats.c:84
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3095
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:5456
#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:546
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:253
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
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:573
std::istream & in(std::istream &in_, double &x_)
static string ConvertToOSPath(const string &path)
Convert relative "path" on any OS to the current OS-dependent relative path.
Definition: ncbifile.cpp:735
static int CompareNocase(const CTempString str, SIZE_TYPE pos, SIZE_TYPE n, const char *pattern)
Case-insensitive compare of a substring with a pattern.
Definition: ncbistr.cpp:170
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
static EMsvcPlatform GetMsvcPlatform(void)
static string AddTrailingPathSeparator(const string &path)
Add trailing path separator, if needed.
Definition: ncbifile.cpp:441
Modified on Tue Aug 30 19:37:39 2016 by modify_doxy.py rev. 506947