nakefile.nim 4.9 KB

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