nakefile.nim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import nake
  2. import httpclient, zip/zipfiles, times, random, sequtils
  3. nakeImports
  4. randomize()
  5. const
  6. GameAssets = "http://dl.dropbox.com/u/37533467/data-08-01-2012.7z"
  7. BinLibs = "http://dl.dropbox.com/u/37533467/libs-2012-09-12.zip"
  8. ExeName = "keineschweine"
  9. ServerDefines = "-d:NoSFML -d:NoChipmunk"
  10. TestBuildDefines = "-d:escapeMenuTest -d:debugWeps -d:showFPS -d:moreNim -d:debugKeys -d:foo -d:recordMode --forceBuild"
  11. ReleaseDefines = "-d:release"
  12. ReleaseTestDefines = "-d:debugWeps -d:debugKeys --forceBuild"
  13. task "testprofile", "..":
  14. if shell("nim", TestBuildDefines, "--profiler:on", "--stacktrace:on", "compile", ExeName) == 0:
  15. shell "."/ExeName, "offline"
  16. task "test", "Build with test defines":
  17. if shell("nim", TestBuildDefines, "compile", ExeName) != 0:
  18. quit "The build failed."
  19. task "testrun", "Build with test defines and run":
  20. runTask "test"
  21. shell "."/ExeName
  22. task "test2", "Build release test build test release build":
  23. if shell("nim", ReleaseDefines, ReleaseTestDefines, "compile", ExeName) == 0:
  24. shell "."/ExeName
  25. when false:
  26. task "dirserver", "build the directory server":
  27. withDir "server":
  28. if shell("nim", ServerDefines, "compile", "dirserver") != 0:
  29. echo "Failed to build the dirserver"
  30. quit 1
  31. task "zoneserver", "build the zone server":
  32. withDir "enet_server":
  33. if shell("nim", ServerDefines, "compile", "enet_server") != 0:
  34. quit "Failed to build the zoneserver"
  35. task "zoneserver-gui", "build the zone server, with gui!":
  36. withDir "enet_server":
  37. if shell("nim", ServerDefines, "--app:gui", "compile", "enet_server") != 0:
  38. quit "Failed to build the zoneserver"
  39. task "servers", "build the server and directory server":
  40. #runTask "dirserver"
  41. runTask "zoneserver"
  42. echo "Successfully built both servers :')"
  43. task "all", "run SERVERS and TEST tasks":
  44. runTask "servers"
  45. runTask "test"
  46. task "release", "release build":
  47. let res = shell("nim", ReleaseDefines, "compile", ExeName)
  48. if res != 0:
  49. echo "The build failed."
  50. quit 1
  51. else:
  52. runTask "clean"
  53. ## zip up all the files and such or something useful here
  54. task "testskel", "create skeleton test dir for testing":
  55. let dirname = "test-" & $rand(5000)
  56. removeDir dirName
  57. createDir dirName/"data/fnt"
  58. copyFile "data/fnt/LiberationMono-Regular", dirName/"data/fnt/LiberationMono-Regular.ttf"
  59. copyFile "client_settings.json", dirName/"client_settings.json"
  60. runTask "test"
  61. copyFile ExeName, dirName/ExeName
  62. withDir dirName:
  63. shell "."/ExeName
  64. task "clean", "cleanup generated files":
  65. var dirs = @["nimcache", "server"/"nimcache"]
  66. dirs.apply(proc(x: var string) =
  67. if dirExists(x): removeDir(x))
  68. task "download", "download game assets":
  69. var
  70. skipAssets = false
  71. path = expandFilename("data")
  72. client = newHttpClient()
  73. path.add DirSep
  74. path.add(extractFilename(GameAssets))
  75. if fileExists(path):
  76. echo "The file already exists\n",
  77. "[R]emove [M]ove [Q]uit [S]kip Source: ", GameAssets
  78. case stdin.readLine.toLowerAscii
  79. of "r":
  80. removeFile path
  81. of "m":
  82. moveFile path, path/../(extractFilename(GameAssets)&"-old")
  83. of "s":
  84. skipAssets = true
  85. else:
  86. quit 0
  87. else:
  88. echo "Downloading from ", GameAssets
  89. if not skipAssets:
  90. echo "Downloading to ", path
  91. client.downloadFile(GameAssets, path)
  92. echo "Download finished"
  93. let targetDir = parentDir(parentDir(path))
  94. when defined(linux):
  95. let z7 = findExe("7z")
  96. if z7 == "":
  97. echo "Could not find 7z"
  98. elif shell(z7, "t", path) != 0: ##note to self: make sure this is right
  99. echo "Bad download"
  100. else:
  101. echo "Unpacking..."
  102. shell(z7, "x", "-w[$1]" % targetDir, path)
  103. else:
  104. echo "I do not know how to unpack the data on this system. Perhaps you could ",
  105. "fill this part in?"
  106. echo "Download binary libs? Only libs for linux are available currently, enjoy the irony.\n",
  107. "[Y]es [N]o Source: ", BinLibs
  108. case stdin.readline.toLowerAscii
  109. of "y", "yes":
  110. discard ## o_O
  111. else:
  112. return
  113. path = extractFilename(BinLibs)
  114. client.downloadFile(BinLibs, path)
  115. echo "Downloaded dem libs ", path
  116. when true: echo "Unpack it yourself, sorry."
  117. else: ## this crashes, dunno why
  118. var
  119. z: TZipArchive
  120. destDir = getCurrentDir()/("unzip" & $rand(5000))
  121. if not z.open(path, fmRead):
  122. echo "Could not open zip, bad download?"
  123. return
  124. echo "Extracting to ", destDir
  125. createDir destDir
  126. #z.extractAll destDir
  127. for f in z.walkFiles():
  128. z.extractFile(f, destDir/f)
  129. z.close()
  130. echo "Extracted the libs dir. Copy the ones you need to this dir."
  131. task "zip-lib", "zip up the libs dir":
  132. var z: ZipArchive
  133. if not z.open("libs-" & getDateStr() & ".zip", fmReadWrite):
  134. quit "Could not open zip"
  135. for file in walkDirRec("libs", {pcFile, pcDir}):
  136. echo "adding file ", file
  137. z.addFile(file)
  138. z.close()
  139. echo "Great success!"