Fixed downloading of glslangValidator

This commit is contained in:
Noah Santschi-Cooney 2019-10-06 10:52:25 +01:00
parent 41995c3f38
commit ffa0007c51

View file

@ -1,14 +1,12 @@
import { ConfigProvider } from './config' import * as unzip from 'adm-zip';
import { execSync } from 'child_process' import { execSync } from 'child_process';
import { extensionMap, ShaderFileExtension } from './fileTypes' import { writeFileSync } from 'fs';
import * as path from 'path'
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import { platform } from 'os'; import { platform } from 'os';
import * as unzip from 'adm-zip' import { ConfigProvider } from './config';
import { createWriteStream } from 'fs' import { extensionMap, ShaderFileExtension } from './fileTypes';
import { writeFileSync, fstat } from 'fs';
import { connection } from './server';
import { glslProviderLog as log } from './logging'; import { glslProviderLog as log } from './logging';
import { connection } from './server';
const url = { const url = {
@ -50,12 +48,12 @@ export class GLSLangProvider {
const glslangPath = this._config.config.shaderpacksPath + glslangBin const glslangPath = this._config.config.shaderpacksPath + glslangBin
const response = await fetch(url[platform()]) const response = await fetch(url[platform()])
log.warn(() => 'glslangValidator download response status: ' + response.status )
const zip = new unzip(await response.buffer()) const zip = new unzip(await response.buffer())
const bin = zip.readFile('bin' + glslangBin) const bin = zip.readFile('bin' + glslangBin)
log.warn(() => 'buffer length ' + bin.length)
writeFileSync(glslangPath, bin) writeFileSync(glslangPath, bin, {encoding: null, mode: 0o755})
if (!this.testExecutable()) { if (!this.testExecutable()) {
connection.window.showErrorMessage( connection.window.showErrorMessage(
@ -79,20 +77,22 @@ export class GLSLangProvider {
} }
public testExecutable(glslangPath?: string): boolean { public testExecutable(glslangPath?: string): boolean {
let success = false let stdout = ''
try { try {
const stdout = execSync(glslangPath || this._config.config.glslangValidatorPath, { stdout = execSync(glslangPath || this._config.config.glslangValidatorPath, {
stdio: 'pipe', stdio: 'pipe',
}).toString() }).toString()
success = stdout.startsWith('Usage')
} catch (e) { } catch (e) {
success = (e.stdout.toString() as string).startsWith('Usage') stdout = (e.stdout.toString() as string)
} }
log.warn(() => 'glslangValidator first line stdout: ' + stdout.split('\n')[0])
const success = stdout.startsWith('Usage')
if (success) { if (success) {
log.info(() => `glslangValidator found at ${this._config.config.glslangValidatorPath}`) log.info(() => `glslangValidator found at ${this._config.config.glslangValidatorPath}`)
} else { } else {
log.error(() => `glslangValidator not found at ${this._config.config.glslangValidatorPath}`, null) log.warn(() => `glslangValidator not found at ${this._config.config.glslangValidatorPath}`)
} }
return success return success