1 /**
2  * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
3  * Authors: Jacob Carlborg
4  * Version: Initial created: Jan 16, 2011
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6  */
7 module dvm.dvm.Wrapper;
8 
9 import std.format : format;
10 
11 import dvm.dvm.ShellScript;
12 import dvm.io.Path;
13 
14 struct Wrapper
15 {
16     string path;
17     string target;
18 
19     private ShellScript sh;
20 
21     static Wrapper opCall (string path = "", string target = "")
22     {
23         Wrapper wrapper;
24 
25         wrapper.path = path;
26         wrapper.target = target;
27 
28         return wrapper;
29     }
30 
31     void write ()
32     {
33         createContent;
34         sh.path = path;
35         sh.write;
36     }
37 
38     private void createContent ()
39     {
40         native(path.toMutable);
41         native(target.toMutable);
42 
43         sh = new ShellScript(path);
44         auto dmd = "dmd";
45         auto dmdPath = Sh.quote(target);
46 
47         sh.shebang;
48         sh.echoOff;
49         sh.nl;
50 
51         sh.ifFileIsNotEmpty(dmdPath, {
52             sh.exec(dmdPath, Sh.allArgs);
53         }, {
54             sh.printError(format(`Missing target: "%s"`, target), true);
55         });
56     }
57 }
58 
59 private:
60 
61 T[] toMutable (T) (const(T)[] array)
62 {
63 	return cast(T[]) array;
64 }