1 /** 2 * Copyright: Copyright (c) 2010-2011 Jacob Carlborg. All rights reserved. 3 * Authors: Jacob Carlborg 4 * Version: Initial created: Aug 15, 2010 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 6 */ 7 module dvm.dvm.Options; 8 9 import tango.sys.Environment; 10 import tango.sys.HomeFolder; 11 12 import mambo.core..string; 13 import mambo.util.Singleton; 14 import mambo.util.Version; 15 16 import dvm.io.Path; 17 18 class Options 19 { 20 mixin Singleton; 21 22 enum indentation = " "; 23 enum numberOfIndentations = 1; 24 enum path = Path(); 25 26 bool verbose = false; 27 bool tango = false; 28 bool isDefault = false; 29 30 bool force = false; 31 bool decline = false; 32 bool latest = false; 33 bool compileDebug = false; 34 35 version (D_LP64) 36 bool is64bit = true; 37 38 else 39 bool is64bit = false; 40 41 version (OSX) 42 enum platform = "osx"; 43 44 else version (FreeBSD) 45 enum platform = "freebsd"; 46 47 else version (linux) 48 enum platform = "linux"; 49 50 else version (Windows) 51 enum platform = "windows"; 52 53 else 54 static assert (false, "Platform not supported"); 55 } 56 57 private struct Path 58 { 59 enum bin = "bin"; 60 enum bin32 = "bin32"; 61 enum bin64 = "bin64"; 62 enum src = "src"; 63 enum lib = "lib"; 64 enum lib32 = "lib32"; 65 enum lib64 = "lib64"; 66 enum import_ = "import"; 67 enum license = "license.txt"; 68 enum readme = "README.TXT"; 69 enum std = "std"; 70 enum object_di = "object.di"; 71 72 version (Posix) 73 { 74 enum libExtension = ".a"; 75 enum tangoLibName = "libtango"; 76 enum pathSeparator = ":"; 77 enum confName = "dmd.conf"; 78 enum scriptExtension = ""; 79 enum executableExtension = ""; 80 } 81 82 else 83 { 84 enum libExtension = ".lib"; 85 enum tangoLibName = "tango"; 86 enum pathSeparator = ";"; 87 enum confName = "sc.ini"; 88 enum scriptExtension = ".bat"; 89 enum executableExtension = ".exe"; 90 } 91 92 private 93 { 94 string home_; 95 string dvm_; 96 string env_; 97 string compilers_; 98 string archives_; 99 string result_; 100 string tmp_; 101 string scripts_; 102 string binDir_; 103 string dvmScript_; 104 string dvmExecutable_; 105 string conf_; 106 string tangoZip_; 107 string tangoTmp_; 108 string tangoBob_; 109 string tangoLib_; 110 string tangoSrc_; 111 string tangoObject_; 112 string tangoVendor_; 113 string tangoUnarchived_; 114 string defaultEnv_; 115 string defaultBin_; 116 117 version (Posix) 118 { 119 enum string dvmDir = ".dvm"; 120 enum string dvmExecName = "dvm"; 121 } 122 123 else version (Windows) 124 { 125 enum string dvmDir = "dvm"; 126 enum string dvmExecName = "_dvm"; 127 } 128 } 129 130 string home () 131 { 132 if (home_.length > 0) 133 return home_; 134 135 version (Posix) 136 return home_ = homeFolder.assumeUnique; 137 138 version (Windows) 139 return home_ = standard(Environment.get("APPDATA")); 140 } 141 142 string dvm () 143 { 144 if (dvm_.length > 0) 145 return dvm_; 146 147 return dvm_ = join(home, dvmDir).assumeUnique; 148 } 149 150 string dvmExecutable () 151 { 152 if (dvmExecutable_.length > 0) 153 return dvmExecutable_; 154 155 return dvmExecutable_ = join(binDir, dvmExecName ~ executableExtension).assumeUnique; 156 } 157 158 string dvmScript () 159 { 160 if (dvmScript_.length > 0) 161 return dvmScript_; 162 163 version (Posix) 164 auto dir = scripts; 165 166 version (Windows) 167 auto dir = binDir; 168 169 return dvmScript_ = join(dir, "dvm" ~ scriptExtension).assumeUnique; 170 } 171 172 string env () 173 { 174 if (env_.length > 0) 175 return env_; 176 177 return env_ = join(dvm, "env").assumeUnique; 178 } 179 180 string compilers () 181 { 182 if (compilers_.length > 0) 183 return compilers_; 184 185 return compilers_ = join(dvm, "compilers").assumeUnique; 186 } 187 188 string archives () 189 { 190 if (archives_.length > 0) 191 return archives_; 192 193 return archives_ = join(dvm, "archives").assumeUnique; 194 } 195 196 string result () 197 { 198 if (result_.length > 0) 199 return result_; 200 201 return result_ = join(tmp, "result" ~ scriptExtension).assumeUnique; 202 } 203 204 string scripts () 205 { 206 if (scripts_.length > 0) 207 return scripts_; 208 209 return scripts_ = join(dvm, "scripts").assumeUnique; 210 } 211 212 string binDir () 213 { 214 if (binDir_.length > 0) 215 return binDir_; 216 217 return binDir_ = join(dvm, "bin").assumeUnique; 218 } 219 220 string tmp () 221 { 222 if (tmp_.length > 0) 223 return tmp_; 224 225 return tmp_ = join(dvm, "tmp").assumeUnique; 226 } 227 228 string conf () 229 { 230 if (conf_.length > 0) 231 return conf_; 232 233 return conf_ = join(bin, confName).assumeUnique; 234 } 235 236 string tangoZip () 237 { 238 if (tangoZip_.length > 0) 239 return tangoZip_; 240 241 return tangoZip_ = join(tmp, "tango.zip").assumeUnique; 242 } 243 244 string tangoTmp () 245 { 246 if (tangoTmp_.length > 0) 247 return tangoTmp_; 248 249 return tangoTmp_ = join(tangoUnarchived, "trunk").assumeUnique; 250 } 251 252 string tangoUnarchived () 253 { 254 if (tangoUnarchived_.length > 0) 255 return tangoUnarchived_; 256 257 return tangoUnarchived_ = join(tmp, "tango", "head").assumeUnique; 258 } 259 260 string tangoBob () 261 { 262 if (tangoBob_.length > 0) 263 return tangoBob_; 264 265 auto suffix = Options.instance.is64bit ? "64" : "32"; 266 auto path = join(tangoTmp, "build", "bin").assumeUnique; 267 268 version (OSX) 269 path = join(path, "osx" ~ suffix).assumeUnique; 270 271 else version (FreeBSD) 272 path = join(path, "freebsd" ~ suffix).assumeUnique; 273 274 else version (linux) 275 path = join(path, "linux" ~ suffix).assumeUnique; 276 277 else version (Windows) 278 path = join(path, "win" ~ suffix).assumeUnique; 279 280 else 281 static assert(false, "Unhandled platform for installing Tango"); 282 283 return tangoBob_ = join(path, "bob" ~ executableExtension).assumeUnique; 284 } 285 286 string tangoLib () 287 { 288 if (tangoLib_.length > 0) 289 return tangoLib_; 290 291 return tangoLib_ = join(tangoTmp, tangoLibName ~ libExtension).assumeUnique; 292 } 293 294 string tangoSrc () 295 { 296 if (tangoSrc_.length) 297 return tangoSrc_; 298 299 return tangoSrc_ = join(tangoTmp, "tango").assumeUnique; 300 } 301 302 string tangoObject () 303 { 304 if (tangoObject_.length > 0) 305 return tangoObject_; 306 307 return tangoObject_ = join(tangoTmp, object_di).assumeUnique; 308 } 309 310 string tangoVendor () 311 { 312 if (tangoVendor_.length > 0) 313 return tangoVendor_; 314 315 return tangoVendor_ = join(tangoSrc, "core", "vendor", std).assumeUnique; 316 } 317 318 string defaultEnv () 319 { 320 if (defaultEnv_.length > 0) 321 return defaultEnv_; 322 323 return defaultEnv_ = join(env, "default").assumeUnique; 324 } 325 326 string defaultBin () 327 { 328 if (defaultBin_.length > 0) 329 return defaultBin_; 330 331 return defaultBin_ = join(binDir, "dvm-default-dc" ~ scriptExtension).assumeUnique; 332 } 333 }