Skip to content

Commit 17bf8d1

Browse files
authored
tools: simplify and remove redundancies in vshader.v (#20161)
1 parent e5e26db commit 17bf8d1

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

cmd/tools/vshader.v

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ const shdc_urls = {
5757
'osx_a64': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/osx_arm64/sokol-shdc'
5858
}
5959
const shdc_version_file = os.join_path(cache_dir, 'sokol-shdc.version')
60-
const shdc = shdc_exe()
61-
const shdc_exe_name = 'sokol-shdc.exe'
60+
const shdc_exe = os.join_path(cache_dir, 'sokol-shdc.exe')
6261

6362
struct Options {
6463
show_help bool
@@ -192,7 +191,7 @@ fn compile_shader(opt CompileOptions, shader_file string) ! {
192191
}
193192

194193
cmd :=
195-
'${os.quoted_path(shdc)} --input ${os.quoted_path(shader_file)} --output ${os.quoted_path(out_file)} --slang ' +
194+
'${os.quoted_path(shdc_exe)} --input ${os.quoted_path(shader_file)} --output ${os.quoted_path(out_file)} --slang ' +
196195
os.quoted_path(slangs.join(':'))
197196
if opt.verbose {
198197
eprintln('${tool_name} executing:\n${cmd}')
@@ -238,18 +237,18 @@ fn ensure_external_tools(opt Options) ! {
238237
return
239238
}
240239

241-
is_shdc_available := os.is_file(shdc)
242-
is_shdc_executable := os.is_executable(shdc)
240+
is_shdc_available := os.is_file(shdc_exe)
241+
is_shdc_executable := os.is_executable(shdc_exe)
243242
if opt.verbose {
244243
eprintln('reading version from ${shdc_version_file} ...')
245244
version := os.read_file(shdc_version_file) or { 'unknown' }
246-
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc}"')
245+
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc_exe}"')
247246
eprintln('executable: ${is_shdc_executable}')
248247
eprintln(' available: ${is_shdc_available}')
249248
if is_shdc_available {
250-
eprintln(' file path: ${shdc}')
251-
eprintln(' file size: ${os.file_size(shdc)}')
252-
eprintln(' file time: ${time.unix_microsecond(os.file_last_mod_unix(shdc),
249+
eprintln(' file path: ${shdc_exe}')
250+
eprintln(' file size: ${os.file_size(shdc_exe)}')
251+
eprintln(' file time: ${time.unix_microsecond(os.file_last_mod_unix(shdc_exe),
253252
0)}')
254253
}
255254
}
@@ -260,13 +259,6 @@ fn ensure_external_tools(opt Options) ! {
260259
download_shdc(opt)!
261260
}
262261

263-
// shdc_exe returns an absolute path to the `sokol-shdc` tool.
264-
// Please note that the tool isn't guaranteed to actually be present, nor is
265-
// it guaranteed that it can be invoked.
266-
fn shdc_exe() string {
267-
return os.join_path(cache_dir, shdc_exe_name)
268-
}
269-
270262
// download_shdc downloads the `sokol-shdc` tool to an OS specific cache directory.
271263
fn download_shdc(opt Options) ! {
272264
// We want to use the same, runtime, OS type as this tool is invoked on.
@@ -284,19 +276,18 @@ fn download_shdc(opt Options) ! {
284276
if opt.verbose {
285277
eprintln('> update_to_shdc_version: ${update_to_shdc_version} | shdc_version: ${shdc_version}')
286278
}
287-
file := shdc_exe()
288279
if opt.verbose {
289-
if shdc_version != update_to_shdc_version && os.exists(file) {
280+
if shdc_version != update_to_shdc_version && os.exists(shdc_exe) {
290281
eprintln('${tool_name} updating sokol-shdc to version ${shdc_version} ...')
291282
} else {
292283
eprintln('${tool_name} installing sokol-shdc version ${update_to_shdc_version} ...')
293284
}
294285
}
295-
if os.exists(file) {
296-
os.rm(file)!
286+
if os.exists(shdc_exe) {
287+
os.rm(shdc_exe)!
297288
}
298289

299-
mut dtmp_file, dtmp_path := util.temp_file(util.TempFileOptions{ path: os.dir(file) })!
290+
mut dtmp_file, dtmp_path := util.temp_file(util.TempFileOptions{ path: os.dir(shdc_exe) })!
300291
dtmp_file.close()
301292
if opt.verbose {
302293
eprintln('${tool_name} downloading sokol-shdc from ${download_url}')
@@ -308,11 +299,7 @@ fn download_shdc(opt Options) ! {
308299
// Make it executable
309300
os.chmod(dtmp_path, 0o775)!
310301
// Move downloaded file in place
311-
os.mv(dtmp_path, file)!
312-
if runtime_os in ['linux', 'macos'] {
313-
// Use the .exe file ending to minimize platform friction.
314-
os.mv(file, shdc)!
315-
}
302+
os.mv(dtmp_path, shdc_exe)!
316303
// Update internal version file
317304
os.write_file(shdc_version_file, shdc_version)!
318305
}

0 commit comments

Comments
 (0)