1 /**
2  * Copyright: Copyright (c) 2011 Nick Sabalausky. All rights reserved.
3  * Authors: Nick Sabalausky
4  * Version: Initial created: July 31, 2011
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6  */
7 module dvm.commands.DmcInstall;
8 
9 import tango.core.Exception;
10 import tango.io.Stdout;
11 import tango.io.device.File;
12 import tango.net.http.HttpGet;
13 import tango.sys.Common;
14 import tango.sys.Environment;
15 import tango.sys.Process;
16 import tango.sys.win32.Types;
17 import tango.text.Util;
18 import tango.util.compress.Zip : extractArchive;
19 
20 import mambo.util.Version;
21 
22 import dvm.commands.Command;
23 import dvm.commands.DvmInstall;
24 import dvm.commands.Fetch;
25 import dvm.commands.Use;
26 import mambo.core._;
27 import dvm.dvm.Wrapper;
28 import dvm.dvm._;
29 import Path = dvm.io.Path;
30 import dvm.util.Util;
31 
32 // DMC is Windows-only, but this is allowed on Posix
33 // in case someone wants to try to use it through Wine.
34 
35 class DmcInstall : Fetch
36 {
37     private
38     {
39         string archivePath;
40         string tmpCompilerPath;
41         Wrapper wrapper;
42         string installPath_;
43     }
44 
45     override void execute ()
46     {
47         install;
48     }
49 
50 private:
51 
52     void install ()
53     {
54         archivePath = Path.join(options.path.archives, dmcArchiveName);
55 
56         fetchDMC(options.path.archives);
57         println("Installing: dmc");
58 
59         unpack;
60         moveFiles;
61 
62         version (Windows)
63             installWrapper;
64     }
65 
66     void unpack ()
67     {
68         tmpCompilerPath = Path.join(options.path.tmp, "dmc");
69         verbose("Unpacking:");
70         verbose(options.indentation, "source: ", archivePath);
71         verbose(options.indentation, "destination: ", tmpCompilerPath, '\n');
72         extractArchive(archivePath, tmpCompilerPath);
73     }
74 
75     void moveFiles ()
76     {
77         verbose("Moving:");
78         Path.move(Path.join(tmpCompilerPath, "dm"), installPath);
79     }
80 
81     version (Windows)
82         void installWrapper ()
83         {
84             wrapper.target = Path.join(installPath, options.path.bin, "dmc.exe");
85             wrapper.path = Path.join(options.path.dvm, options.path.bin, "dmc.bat");
86 
87             verbose("Installing wrapper: " ~ wrapper.path);
88             wrapper.write;
89         }
90 
91     string installPath ()
92     {
93         if (installPath_.length > 0)
94             return installPath_;
95 
96         return installPath_ = Path.join(options.path.compilers, "dmc");
97     }
98 }