1 #include "Core.h"
2
ChDir(const String & path)3 void Builder::ChDir(const String& path)
4 {
5 host->ChDir(path);
6 }
7
GetHostPath(const String & path) const8 String Builder::GetHostPath(const String& path) const
9 {
10 return host->GetHostPath(path);
11 }
12
TrimSlash(String s)13 String TrimSlash(String s)
14 {
15 while(findarg(*s.Last(), '/', '\\') >= 0)
16 s.Trim(s.GetCount() - 1);
17 return s;
18 }
19
GetHostPathQ(const String & path) const20 String Builder::GetHostPathQ(const String& path) const
21 {
22 return '\"' + TrimSlash(GetHostPath(path)) + '\"';
23 }
24
GetFileInfo(const Vector<String> & path) const25 Vector<Host::FileInfo> Builder::GetFileInfo(const Vector<String>& path) const
26 {
27 return host->GetFileInfo(path);
28 }
29
GetFileInfo(const String & path) const30 Host::FileInfo Builder::GetFileInfo(const String& path) const
31 {
32 return GetFileInfo(Vector<String>() << path)[0];
33 }
34
GetFileTime(const String & path) const35 Time Builder::GetFileTime(const String& path) const
36 {
37 return GetFileInfo(path);
38 }
39
CmdX(const char * s)40 String Builder::CmdX(const char *s)
41 { // expand ` character delimited sections by executing them as commands
42 String r, cmd;
43 bool cmdf = false;
44 for(; *s; s++)
45 if(*s == '`') {
46 if(cmdf) {
47 r << Sys(cmd);
48 cmd.Clear();
49 }
50 cmdf = !cmdf;
51 }
52 else
53 (cmdf ? cmd : r).Cat(*s);
54 int q = r.Find(' ');
55 if(r.GetCount() > 8000 && q >= 0) {
56 String rn = CatAnyPath(outdir, AsString(tmpfilei.GetAdd(outdir, 0)++) + ".cmd");
57 PutVerbose("Generating response file: " << rn);
58 PutVerbose(r);
59 r.Replace("\\", "/"); // clang win32 needs this
60 SaveFile(rn, r.Mid(q + 1));
61 r = r.Mid(0, q) + " @" + rn;
62 }
63 return r;
64 }
65
Execute(const char * cmdline)66 int Builder::Execute(const char *cmdline)
67 {
68 return host->Execute(CmdX(cmdline));
69 }
70
Execute(const char * cl,Stream & out)71 int Builder::Execute(const char *cl, Stream& out)
72 {
73 return host->Execute(CmdX(cl), out);
74 }
75
DeleteFile(const Vector<String> & path)76 void Builder::DeleteFile(const Vector<String>& path)
77 {
78 host->DeleteFile(path);
79 }
80
DeleteFile(const String & path)81 void Builder::DeleteFile(const String& path)
82 {
83 host->DeleteFile(Vector<String>() << path);
84 }
85
RealizeDir(const String & path)86 bool Builder::RealizeDir(const String& path)
87 {
88 return host->RealizeDir(path);
89 }
90
SaveFile(const String & path,const String & data)91 bool Builder::SaveFile(const String& path, const String& data)
92 {
93 return host->SaveFile(path, data);
94 }
95
LoadFile(const String & path)96 String Builder::LoadFile(const String& path)
97 {
98 return host->LoadFile(path);
99 }
100
FileExists(const String & path) const101 bool Builder::FileExists(const String& path) const
102 {
103 return !IsNull(GetFileInfo(path).length);
104 }
105