annotate semicongine/build.nim @ 1127:073ce95ae5c7

fix: wrong string interpolation
author sam <sam@basx.dev>
date Mon, 29 Apr 2024 02:37:42 -0700
parents 881be2633761
children af18922b416d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
396
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
1 # this should be used with nimscript
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
2
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/strformat
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
4 import std/os
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
5 import std/strutils
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
6
388
405bb1fb52b8 add: import-helpers for nimscripts
Sam <sam@basx.dev>
parents: 387
diff changeset
7 import ./core/audiotypes
396
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
8 import ./core/constants
388
405bb1fb52b8 add: import-helpers for nimscripts
Sam <sam@basx.dev>
parents: 387
diff changeset
9
1039
ea9270ed03ea and even more cleanup of the repo
sam <sam@basx.dev>
parents: 438
diff changeset
10 const BLENDER_CONVERT_SCRIPT = currentSourcePath().parentDir().parentDir().joinPath("tools/blender_gltf_converter.py")
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
11 const STEAMCMD_ZIP = currentSourcePath().parentDir().parentDir().joinPath("tools/steamcmd.zip")
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
12 const STEAMBUILD_DIR_NAME = "steam"
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
13
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
14 var STEAMLIB: string
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
15 if defined(linux):
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
16 STEAMLIB = currentSourcePath().parentDir().parentDir().joinPath("libs/libsteam_api.so")
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
17 elif defined(windows):
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
18 STEAMLIB = currentSourcePath().parentDir().parentDir().joinPath("libs/steam_api.dll")
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
19 else:
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
20 raise newException(Exception, "Unsupported platform")
1120
056abf6386d7 fix: correct sqlite dlls for windows
sam <sam@basx.dev>
parents: 1104
diff changeset
21 let SQLITELIB_32 = currentSourcePath().parentDir().parentDir().joinPath("libs/sqlite3_32.dll")
056abf6386d7 fix: correct sqlite dlls for windows
sam <sam@basx.dev>
parents: 1104
diff changeset
22 let SQLITELIB_64 = currentSourcePath().parentDir().parentDir().joinPath("libs/sqlite3_64.dll")
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
23
437
e75c6da1d261 fix: exe-bundling not working correctly
Sam <sam@basx.dev>
parents: 400
diff changeset
24 proc semicongine_builddir*(buildname: string, builddir = "./build"): string =
1104
ed79529e70a3 fix: packaging fails if there are no resources, fix: zip-generation
sam <sam@basx.dev>
parents: 1102
diff changeset
25 assert projectName() != "", "Please specify project file as a commandline argument"
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
26 var platformDir = "unkown"
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
27
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
28 if defined(linux):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
29 platformDir = "linux"
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
30 elif defined(windows):
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
31 platformDir = "windows"
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
32 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
33 raise newException(Exception, "Unsupported platform")
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
34
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
35 return builddir / buildname / platformDir / projectName()
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
36
437
e75c6da1d261 fix: exe-bundling not working correctly
Sam <sam@basx.dev>
parents: 400
diff changeset
37 proc semicongine_build_switches*(buildname: string, builddir = "./build") =
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
38 switch("experimental", "strictEffects")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
39 switch("experimental", "strictFuncs")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
40 switch("define", "nimPreviewHashRef")
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
41 if defined(linux):
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
42 switch("define", "VK_USE_PLATFORM_XLIB_KHR")
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
43 elif defined(windows):
400
7c31e5a780f1 fix: enforce gui-app on windows
sam <sam@basx.dev>
parents: 396
diff changeset
44 switch("define", "VK_USE_PLATFORM_WIN32_KHR")
7c31e5a780f1 fix: enforce gui-app on windows
sam <sam@basx.dev>
parents: 396
diff changeset
45 switch("app", "gui")
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
46 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
47 raise newException(Exception, "Unsupported platform")
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
48
437
e75c6da1d261 fix: exe-bundling not working correctly
Sam <sam@basx.dev>
parents: 400
diff changeset
49 switch("outdir", semicongine_builddir(buildname, builddir = builddir))
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
50 switch("passL", "-Wl,-rpath,'$ORIGIN'") # adds directory of executable to dynlib search path
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
51
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
52 proc semicongine_pack*(outdir: string, bundleType: string, resourceRoot: string, withSteam: bool) =
438
1ab09f8cc68d did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 437
diff changeset
53 switch("define", "PACKAGETYPE=" & bundleType)
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
54
1088
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
55 assert resourceRoot.dirExists, &"Resource root '{resourceRoot}' does not exists"
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
56
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
57 outdir.rmDir()
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
58 outdir.mkDir()
396
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
59
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
60 echo "BUILD: Packing assets from '" & resourceRoot & "' into directory '" & outdir & "'"
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
61 let outdir_resources = joinPath(outdir, RESOURCEROOT)
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
62 if bundleType == "dir":
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
63 cpDir(resourceRoot, outdir_resources)
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
64 elif bundleType == "zip":
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
65 outdir_resources.mkDir()
1088
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
66 for resourceDir in resourceRoot.listDirs():
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
67 let outputfile = joinPath(outdir_resources, resourceDir.splitPath().tail & ".zip")
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
68 withdir resourceDir:
396
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
69 if defined(linux):
1088
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
70 echo &"zip -r {relativePath(outputfile, resourceDir)} ."
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
71 exec &"zip -r {relativePath(outputfile, resourceDir)} ."
396
c94db8b83040 did: adjust build-variables and config
Sam <sam@basx.dev>
parents: 392
diff changeset
72 elif defined(windows):
1088
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
73 echo &"powershell Compress-Archive * {relativePath(outputfile, resourceDir)}"
ac3025fcc324 fix: tests
sam <sam@basx.dev>
parents: 1085
diff changeset
74 exec &"powershell Compress-Archive * {relativePath(outputfile, resourceDir)}"
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
75 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
76 raise newException(Exception, "Unsupported platform")
437
e75c6da1d261 fix: exe-bundling not working correctly
Sam <sam@basx.dev>
parents: 400
diff changeset
77 elif bundleType == "exe":
e75c6da1d261 fix: exe-bundling not working correctly
Sam <sam@basx.dev>
parents: 400
diff changeset
78 switch("define", "BUILD_RESOURCEROOT=" & joinPath(getCurrentDir(), resourceRoot)) # required for in-exe packing of resources, must be absolute
1102
5f4ff2e9d5c4 add: sqlite dll for windows builds
sam <sam@basx.dev>
parents: 1088
diff changeset
79 if defined(windows):
1120
056abf6386d7 fix: correct sqlite dlls for windows
sam <sam@basx.dev>
parents: 1104
diff changeset
80 SQLITELIB_32.cpFile(outdir.joinPath(SQLITELIB_32.extractFilename))
056abf6386d7 fix: correct sqlite dlls for windows
sam <sam@basx.dev>
parents: 1104
diff changeset
81 SQLITELIB_64.cpFile(outdir.joinPath(SQLITELIB_64.extractFilename))
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
82 if withSteam:
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
83 STEAMLIB.cpFile(outdir.joinPath(STEAMLIB.extractFilename))
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
84
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
85 proc semicongine_zip*(dir: string) =
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
86 withdir dir.parentDir:
1125
e61aed76463e fix: wrong place
sam <sam@basx.dev>
parents: 1122
diff changeset
87 let zipFile = dir.lastPathPart & ".zip"
e61aed76463e fix: wrong place
sam <sam@basx.dev>
parents: 1122
diff changeset
88 if zipFile.fileExists:
e61aed76463e fix: wrong place
sam <sam@basx.dev>
parents: 1122
diff changeset
89 zipFile.rmFile()
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
90 if defined(linux):
1104
ed79529e70a3 fix: packaging fails if there are no resources, fix: zip-generation
sam <sam@basx.dev>
parents: 1102
diff changeset
91 exec &"zip -r {dir.lastPathPart} {dir.lastPathPart}"
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
92 elif defined(windows):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
93 exec &"powershell Compress-Archive * {dir.lastPathPart}"
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
94 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
95 raise newException(Exception, "Unsupported platform")
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
96
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
97
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
98 # need this because fileNewer from std/os does not work in Nim VM
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
99 proc fileNewerStatic(file1, file2: string): bool =
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
100 assert file1.fileExists
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
101 assert file2.fileExists
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
102 when defined(linux):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
103 let command = "/usr/bin/test " & file1 & " -nt " & file2
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
104 let ex = gorgeEx(command)
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
105 return ex.exitCode == 0
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
106 elif defined(window):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
107 {.error "Resource imports not supported on windows for now".}
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
108
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
109 proc import_meshes*(files: seq[(string, string)]) =
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
110 if files.len == 0:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
111 return
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
112
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
113 var args = @["--background", "--python", BLENDER_CONVERT_SCRIPT, "--"]
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
114 for (input, output) in files:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
115 args.add input
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
116 args.add output
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
117
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
118 exec("blender " & args.join(" "))
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
119
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
120 proc import_audio*(files: seq[(string, string)]) =
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
121 for (input, output) in files:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
122 let command = "ffmpeg " & ["-y", "-i", input, "-ar", $AUDIO_SAMPLE_RATE, output].join(" ")
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
123 exec(command)
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
124
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
125 proc semicongine_import_resource_file*(resourceMap: openArray[(string, string)]) =
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
126 when not defined(linux):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
127 {.warning: "Resource files can only be imported on linux, please make sure that the required files are created by runing the build on a linux machine.".}
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
128 return
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
129 var meshfiles: seq[(string, string)]
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
130 var audiofiles: seq[(string, string)]
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
131
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
132 for (target_rel, source_rel) in resourceMap:
1076
bfcec39dfb0b fix: steamcmd and build-script location
sam <sam@basx.dev>
parents: 1075
diff changeset
133 let target = thisDir().joinPath(target_rel)
bfcec39dfb0b fix: steamcmd and build-script location
sam <sam@basx.dev>
parents: 1075
diff changeset
134 let source = thisDir().joinPath(source_rel)
392
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
135 if not source.fileExists:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
136 raise newException(IOError, &"Not found: {source}")
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
137 if not target.fileExists or source.fileNewerStatic(target):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
138 echo &"{target} is outdated"
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
139 if source.endsWith("blend"):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
140 meshfiles.add (source, target)
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
141 elif source.endsWith("mp3") or source.endsWith("ogg") or source.endsWith("wav"):
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
142 audiofiles.add (source, target)
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
143 else:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
144 raise newException(Exception, &"unkown file type: {source}")
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
145 target.parentDir().mkDir()
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
146 else:
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
147 echo &"{target} is up-to-date"
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
148 import_meshes meshfiles
ff751cbe66e3 add: build-time code for resouce importing
Sam <sam@basx.dev>
parents: 391
diff changeset
149 import_audio audiofiles
1073
56e3fb525527 add: initial code for automated steam builds
sam <sam@basx.dev>
parents: 1039
diff changeset
150
56e3fb525527 add: initial code for automated steam builds
sam <sam@basx.dev>
parents: 1039
diff changeset
151
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
152 # for steam-buildscript docs see https://partner.steamgames.com/doc/sdk/uploading
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
153 proc semicongine_steam_upload*(steamaccount, password, buildscript: string) =
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
154 let steamdir = thisDir().joinPath(STEAMBUILD_DIR_NAME)
1073
56e3fb525527 add: initial code for automated steam builds
sam <sam@basx.dev>
parents: 1039
diff changeset
155 if not dirExists(steamdir):
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
156 steamdir.mkDir
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
157 let zipFilename = STEAMCMD_ZIP.extractFilename
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
158 STEAMCMD_ZIP.cpFile(steamdir.joinPath(zipFilename))
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
159 withDir(steamdir):
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
160 if defined(linux):
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
161 exec &"unzip {zipFilename}"
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
162 rmFile zipFilename
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
163 exec "steamcmd/steamcmd.sh +quit" # self-update steamcmd
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
164 elif defined(windows):
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
165 exec &"powershell Expand-Archive -LiteralPath {zipFilename} ."
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
166 rmFile zipFilename
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
167 exec "steamcmd/steamcmd.exe +quit" # self-update steamcmd
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
168 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
169 raise newException(Exception, "Unsupported platform")
1075
e0635e0bfac3 fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents: 1073
diff changeset
170
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
171 var steamcmd: string
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
172 if defined(linux):
1082
ea33259c013d add: api to interact with steam
sam <sam@basx.dev>
parents: 1076
diff changeset
173 steamcmd = STEAMBUILD_DIR_NAME.joinPath("steamcmd").joinPath("steamcmd.sh")
1084
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
174 elif defined(windows):
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
175 steamcmd = STEAMBUILD_DIR_NAME.joinPath("steamcmd").joinPath("steamcmd.exe")
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
176 else:
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
177 raise newException(Exception, "Unsupported platform")
7477b2a6852f add: support steam uploads on windows
sam <sam@basx.dev>
parents: 1082
diff changeset
178 let scriptPath = "..".joinPath("..").joinPath(buildscript)
1076
bfcec39dfb0b fix: steamcmd and build-script location
sam <sam@basx.dev>
parents: 1075
diff changeset
179 exec &"./{steamcmd} +login \"{steamaccount}\" \"{password}\" +run_app_build {scriptPath} +quit"
1126
881be2633761 add: command to sign executables on windows
sam <sam@basx.dev>
parents: 1125
diff changeset
180
881be2633761 add: command to sign executables on windows
sam <sam@basx.dev>
parents: 1125
diff changeset
181 proc semicongine_sign_executable*(file: string) =
881be2633761 add: command to sign executables on windows
sam <sam@basx.dev>
parents: 1125
diff changeset
182 const SIGNTOOL_EXE = "C:/Program Files (x86)/Windows Kits/10/App Certification Kit/signtool.exe"
881be2633761 add: command to sign executables on windows
sam <sam@basx.dev>
parents: 1125
diff changeset
183 if not SIGNTOOL_EXE.fileExists:
881be2633761 add: command to sign executables on windows
sam <sam@basx.dev>
parents: 1125
diff changeset
184 raise newException(Exception, &"signtool.exe not found at ({SIGNTOOL_EXE}), please install the Windows SDK")
1127
073ce95ae5c7 fix: wrong string interpolation
sam <sam@basx.dev>
parents: 1126
diff changeset
185 exec &"\"{SIGNTOOL_EXE}\" sign /a /tr http://timestamp.globalsign.com/tsa/r6advanced1 /fd SHA256 /td SHA256 {file}"