YSTest: Dependency.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Dependency.cpp
浏览该文件的文档.
1 /*
2 © 2015-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "NPL/YModules.h"
29 #include YFM_NPL_Dependency
30 #include YFM_NPL_SContext
31 #include YFM_YSLib_Service_FileSystem // for YSLib::IO::*;
32
33 using namespace YSLib;
34
35 namespace NPL
36 {
37
38 vector<string>
39 DecomposeMakefileDepList(std::istream& is)
40 {
41 is.unsetf(std::ios_base::skipws);
42
43 using s_it_t = std::istream_iterator<char>;
44 // NOTE: Escaped spaces would be saved to prevent being used as delimiter.
45 set<size_t> spaces;
46 const auto sbuf(Session(s_it_t(is), s_it_t(),
47 [&](LexicalAnalyzer& lexer, char c){
48 lexer.ParseQuoted(c,
49 [&](string& buf, const UnescapeContext& uctx, char) -> bool{
50 const auto& escs(uctx.GetSequence());
51
52 // NOTE: See comments in %munge function of 'mkdeps.c' from libcpp
53 // of GCC.
54 if(escs.length() == 1)
55 {
56 if(uctx.Prefix == "\\")
57 switch(escs[0])
58 {
59 case ' ':
60 spaces.insert(buf.size());
61 case '\\':
62 case '#':
63 buf += escs[0];
64 return true;
65 default:
66 ;
67 }
68 if(uctx.Prefix == "$" && escs[0] == '$')
69 {
70 buf += '$';
71 return true;
72 }
73 }
74 return {};
75 }, [](char ch, string& pfx) -> bool{
76 if(ch == '\\')
77 pfx = "\\";
78 else if(ch == '$')
79 pfx = "$";
80 else
81 return {};
82 return true;
83 });
84 }).GetBuffer());
85 vector<string> lst;
86
87 ystdex::split_if(sbuf.begin(), sbuf.end(), static_cast<int(&)(int)>(
88 std::isspace), [&](string::const_iterator b, string::const_iterator e){
89 lst.push_back(string(b, e));
90 }, [&](string::const_iterator i){
91 return !ystdex::exists(spaces, size_t(i - sbuf.cbegin()));
92 });
93 return lst;
94 }
95
96 bool
97 FilterMakefileDependencies(vector<string>& lst)
98 {
99 const auto i_c(std::find_if(lst.cbegin(), lst.cend(),
100 [](const string& dep){
101 return !dep.empty() && dep.back() == ':';
102 }));
103
104 return i_c != lst.cend()
105 && (lst.erase(lst.cbegin(), i_c + 1), !lst.empty());
106 }
107
108
109 void
110 InstallFile(const char* dst, const char* src)
111 {
112 using namespace YSLib::IO;
113
114 // FIXME: Blocked. TOCTTOU access.
115 try
116 {
117 if(HaveSameContents(dst, src))
118 return;
119 }
120 CatchIgnore(FileOperationFailure&)
121 CopyFile(dst, src, PreserveModificationTime);
122 }
123
124 void
125 InstallDirectory(const string& dst, const string& src)
126 {
127 using namespace YSLib::IO;
128
129 TraverseTree([](const Path& dname, const Path& sname){
130 InstallFile(string(dname).c_str(), string(sname).c_str());
131 }, Path(dst), Path(src));
132 }
133
134 void
135 InstallHardLink(const char* dst, const char* src)
136 {
137 using namespace YSLib::IO;
138
139 if(VerifyDirectory(src))
140 throw std::invalid_argument("Source is a directory.");
141 else
142 uremove(dst);
143 TryExpr(CreateHardLink(dst, src))
144 CatchExpr(..., InstallFile(dst, src))
145 }
146
147 void
148 InstallSymbolicLink(const char* dst, const char* src)
149 {
150 using namespace YSLib::IO;
151
152 uremove(dst);
153 TryExpr(CreateSymbolicLink(dst, src))
154 CatchExpr(..., InstallFile(dst, src))
155 }
156
157 void
158 InstallExecutable(const char* dst, const char* src)
159 {
160 InstallFile(dst, src);
161 }
162
163 } // namespace NPL;
164
NPL::UnescapeContext::Prefix
string Prefix
转义序列前缀。
Definition: Lexical.h:63
NPL::InstallExecutable
src void InstallExecutable(const char *, const char *)
Definition: Dependency.cpp:158
YSLib::Text::buf
const char * buf
Definition: TextFile.h:77
YSLib::IO::TraverseTree
auto TraverseTree(_func f, const Path &dst, const Path &src, _tParams &&...args) -> decltype(f(std::declval< Path & >(), std::declval< Path & >(), std::forward< _tParams >(args)...))
递归遍历目录树。
Definition: YSLib/Service/FileSystem.h:508
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::IO::PreserveModificationTime
const auto PreserveModificationTime(ystdex::bind_forward(&FileDescriptor::SetModificationTime,&FileDescriptor::GetModificationTime))
保持修改时间。
NPL::InstallFile
void InstallFile(const char *dst, const char *src)
Definition: Dependency.cpp:110
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
NPL::LexicalAnalyzer::ParseQuoted
void ParseQuoted(char, Unescaper=NPLUnescape, PrefixHandler=HandleBackslashPrefix)
解析单个字面量字符并添加至字符解析结果：反转义以外无视边界字符。
Definition: Lexical.cpp:208
NPL::UnescapeContext
反转义上下文。
Definition: Lexical.h:59
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::IO::VerifyDirectory
VerifyDirectory
Definition: YSLib/Service/FileSystem.h:394
ystdex::split_if
void split_if(_tIn b, _tIn e, _fPred is_delim, _fInsert insert, _func pred)
以满足迭代器谓词的指定分隔符分割序列。
Definition: algorithm.hpp:229
CatchIgnore
#define CatchIgnore(_ex)
指定异常处理器忽略指定异常。
Definition: YBaseMacro.h:133
ystdex::exists
bool exists(const _tCon &con, const _tKey &key)
判断指定的容器中存在指定的键。
Definition: container.hpp:677
NPL::InstallHardLink
YF_API const char src const string const char const char *src void InstallHardLink(const char *, const char *)
Definition: Dependency.cpp:135
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:93
NPL::InstallSymbolicLink
src void InstallSymbolicLink(const char *, const char *)
Definition: Dependency.cpp:148
platform::CreateSymbolicLink
void CreateSymbolicLink(const char *dst, const char *src, bool is_dir)
Definition: YCLib/FileSystem.cpp:240
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YModules.h
NPL::FilterMakefileDependencies
YF_API bool FilterMakefileDependencies(vector< string > &)
过滤 GCC 兼容编译器 -MMD 选项生成的 Makefile 项列表并选取依赖项。
Definition: Dependency.cpp:97
YSLib::IO
Definition: YAdaptor.h:371
NPL
Definition: NPL/Configuration.h:34
platform::FileOperationFailure
表示文件操作失败的异常。
Definition: FileIO.h:1142
platform::uremove
bool uremove(const char *path) ynothrowv
Definition: FileIO.cpp:1044
YSLib::i
return i
Definition: YCoreUtilities.h:176
platform::CreateHardLink
void CreateHardLink(const char *dst, const char *src)
Definition: YCLib/FileSystem.cpp:208
platform::HaveSameContents
bool HaveSameContents(const char *path_a, const char *path_b, mode_t mode)
Definition: FileIO.cpp:1155
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
NPL::InstallDirectory
void InstallDirectory(const string &dst, const string &src)
Definition: Dependency.cpp:125
NPL::LexicalAnalyzer
词法分析器。
Definition: Lexical.h:145
YSLib::IO::Path
路径。
Definition: YSLib/Service/FileSystem.h:109
NPL::DecomposeMakefileDepList
YF_API vector< string > DecomposeMakefileDepList(std::istream &)
从内容为 GCC 兼容编译器 -MMD 选项生成的 Makefile 的流中分解路径。
Definition: Dependency.cpp:39
YSLib::IO::CopyFile
YF_API void CopyFile(UniqueFile, FileDescriptor)
复制文件。
Definition: YSLib/Service/FileSystem.cpp:166