Skip to content

Commit fdd5063

Browse files
committed
Add a function for adding Kong-directories
1 parent 0a87c35 commit fdd5063

File tree

6 files changed

+318
-103
lines changed

6 files changed

+318
-103
lines changed

kmake/src/Project.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export class Project {
224224
static currentParent: Project = null;
225225
parent: Project;
226226
shaderVersion: number;
227+
kongDirs: string[];
227228

228229
constructor(name: string) {
229230
this.name = name;
@@ -242,6 +243,7 @@ export class Project {
242243
this.includeDirs = [];
243244
this.defines = [];
244245
this.libs = [];
246+
this.kongDirs = [];
245247
this.systemDependendLibraries = {};
246248
this.includes = [];
247249
this.excludes = [];
@@ -396,6 +398,7 @@ export class Project {
396398
}
397399
for (let i of sub.includeDirs) if (!contains(this.includeDirs, path.resolve(subbasedir, i))) this.includeDirs.push(path.resolve(subbasedir, i));
398400
for (let j of sub.javadirs) if (!contains(this.javadirs, path.resolve(subbasedir, j))) this.javadirs.push(path.resolve(subbasedir, j));
401+
for (let k of sub.kongDirs) if (!contains(this.kongDirs, path.resolve(subbasedir, k))) this.kongDirs.push(path.resolve(subbasedir, k));
399402
for (let lib of sub.libs) {
400403
if (lib.indexOf('/') < 0 && lib.indexOf('\\') < 0) {
401404
if (!contains(this.libs, lib)) this.libs.push(lib);
@@ -645,7 +648,9 @@ export class Project {
645648

646649
addDefine(value: string, config: string = null) {
647650
const define = {value, config};
648-
if (containsDefine(this.defines, define)) return;
651+
if (containsDefine(this.defines, define)) {
652+
return;
653+
}
649654
this.defines.push(define);
650655
}
651656

@@ -700,6 +705,17 @@ export class Project {
700705
}
701706
}
702707

708+
addKongDir(dir: string) {
709+
this.kongDirs.push(dir);
710+
this.addDefine('KINC_KONG');
711+
}
712+
713+
addKongDirs() {
714+
for (let i = 0; i < arguments.length; ++i) {
715+
this.addKongDir(arguments[i]);
716+
}
717+
}
718+
703719
getFiles() {
704720
return this.files;
705721
}
@@ -708,6 +724,10 @@ export class Project {
708724
return this.javadirs;
709725
}
710726

727+
getKongDirs() {
728+
return this.kongDirs;
729+
}
730+
711731
getBasedir() {
712732
return this.basedir;
713733
}

kmake/src/main.ts

Lines changed: 144 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,95 @@ function compileShaders(invocations: Invocation[]): Promise<void> {
335335
});
336336
}
337337

338+
function compileKong(from: string, to: string, platform: string, dirs: string[]): Promise<void> {
339+
return new Promise<void>((resolve, reject) => {
340+
let compilerPath = '';
341+
342+
if (Project.kincDir !== '') {
343+
compilerPath = path.resolve(__dirname, 'kongruent' + exec.sys());
344+
}
345+
346+
let libsdir = path.join(from, 'Backends');
347+
if (Project.kincDir) {
348+
libsdir = path.join(Project.kincDir, '..', 'Backends');
349+
}
350+
if (fs.existsSync(libsdir) && fs.statSync(libsdir).isDirectory()) {
351+
let libdirs = fs.readdirSync(path.join(libsdir));
352+
for (let ld in libdirs) {
353+
let libdir = path.join(libsdir, libdirs[ld]);
354+
if (fs.statSync(libdir).isDirectory()) {
355+
let exe = path.join(libdir, 'krafix', 'kong-' + platform + '.exe');
356+
if (fs.existsSync(exe)) {
357+
compilerPath = exe;
358+
}
359+
}
360+
}
361+
}
362+
363+
if (compilerPath !== '') {
364+
let params: string[] = [];
365+
params.push('--platform');
366+
params.push(platform);
367+
for (const dir of dirs) {
368+
params.push('--input');
369+
params.push(dir);
370+
}
371+
params.push('--output');
372+
params.push(to);
373+
let compiler = child_process.spawn(compilerPath, params);
374+
375+
compiler.stdout.on('data', (data: any) => {
376+
log.info(data.toString());
377+
});
378+
379+
let errorLine = '';
380+
let newErrorLine = true;
381+
let errorData = false;
382+
383+
function parseData(data: string) {
384+
385+
}
386+
387+
compiler.stderr.on('data', (data: any) => {
388+
let str: string = data.toString();
389+
for (let char of str) {
390+
if (char === '\n') {
391+
if (errorData) {
392+
parseData(errorLine.trim());
393+
}
394+
else {
395+
log.error(errorLine.trim());
396+
}
397+
errorLine = '';
398+
newErrorLine = true;
399+
errorData = false;
400+
}
401+
else if (newErrorLine && char === '#') {
402+
errorData = true;
403+
newErrorLine = false;
404+
}
405+
else {
406+
errorLine += char;
407+
newErrorLine = false;
408+
}
409+
}
410+
});
411+
412+
compiler.on('close', (code: number) => {
413+
if (code === 0) {
414+
resolve();
415+
}
416+
else {
417+
reject(compilerPath + ' ' + params.join(' '));
418+
}
419+
});
420+
}
421+
else {
422+
throw 'Could not find Kong.';
423+
}
424+
});
425+
}
426+
338427
async function exportKoremakeProject(from: string, to: string, platform: string, korefile: string, retro: boolean, veryretro: boolean, options: any) {
339428
log.info('kfile found.');
340429
if (options.onlyshaders) {
@@ -377,64 +466,69 @@ async function exportKoremakeProject(from: string, to: string, platform: string,
377466
let files = project.getFiles();
378467

379468
if (!options.noshaders && !options.json) {
380-
/*let compilerPath = '';
381-
if (Project.kincDir !== '') {
382-
compilerPath = path.resolve(__dirname, 'krafix' + exec.sys());
469+
if (project.kongDirs.length > 0) {
470+
await compileKong(from, to, platform, project.kongDirs);
383471
}
384-
385-
const matches = [];
386-
for (let file of files) {
387-
if (file.file.endsWith('.glsl')) {
388-
matches.push({match: file.file, options: null});
472+
else {
473+
/*let compilerPath = '';
474+
if (Project.kincDir !== '') {
475+
compilerPath = path.resolve(__dirname, 'krafix' + exec.sys());
389476
}
390-
}
391-
392-
let shaderCompiler = new ShaderCompiler(platform, compilerPath, project.getDebugDir(), options.to,
393-
options.to builddir, matches);
394-
try {
395-
await shaderCompiler.run(false, false);
396-
}
397-
catch (err) {
398-
return Promise.reject(err);
399-
}*/
400477
401-
let shaderCount = 0;
402-
for (let file of files) {
403-
if (file.file.endsWith('.glsl')) {
404-
++shaderCount;
478+
const matches = [];
479+
for (let file of files) {
480+
if (file.file.endsWith('.glsl')) {
481+
matches.push({match: file.file, options: null});
482+
}
405483
}
406-
}
407-
let shaderIndex = 0;
408-
let invocations: Invocation[] = [];
409-
for (let file of files) {
410-
if (file.file.endsWith('.glsl')) {
411-
let outfile = file.file;
412-
const index = outfile.lastIndexOf('/');
413-
if (index > 0) outfile = outfile.substr(index);
414-
outfile = outfile.substr(0, outfile.length - 5);
415-
416-
let parsedFile = path.parse(file.file);
417484
418-
const shader = path.isAbsolute(file.file) ? file.file : path.join(file.projectDir, file.file);
419-
420-
++shaderIndex;
485+
let shaderCompiler = new ShaderCompiler(platform, compilerPath, project.getDebugDir(), options.to,
486+
options.to builddir, matches);
487+
try {
488+
await shaderCompiler.run(false, false);
489+
}
490+
catch (err) {
491+
return Promise.reject(err);
492+
}*/
421493

422-
invocations.push({
423-
projectDir: from,
424-
type: shaderLang(platform),
425-
from: shader,
426-
to: path.join(project.getDebugDir(), outfile),
427-
temp: options.to,
428-
platform: platform,
429-
builddir: options.to,
430-
name: parsedFile.name,
431-
shaderversion: project.shaderVersion,
432-
});
433-
//await compileShader(from, shaderLang(platform), shader, path.join(project.getDebugDir(), outfile), options.to, platform, options.to);
494+
let shaderCount = 0;
495+
for (let file of files) {
496+
if (file.file.endsWith('.glsl')) {
497+
++shaderCount;
498+
}
499+
}
500+
let shaderIndex = 0;
501+
let invocations: Invocation[] = [];
502+
for (let file of files) {
503+
if (file.file.endsWith('.glsl')) {
504+
let outfile = file.file;
505+
const index = outfile.lastIndexOf('/');
506+
if (index > 0) outfile = outfile.substr(index);
507+
outfile = outfile.substr(0, outfile.length - 5);
508+
509+
let parsedFile = path.parse(file.file);
510+
511+
const shader = path.isAbsolute(file.file) ? file.file : path.join(file.projectDir, file.file);
512+
513+
++shaderIndex;
514+
515+
invocations.push({
516+
projectDir: from,
517+
type: shaderLang(platform),
518+
from: shader,
519+
to: path.join(project.getDebugDir(), outfile),
520+
temp: options.to,
521+
platform: platform,
522+
builddir: options.to,
523+
name: parsedFile.name,
524+
shaderversion: project.shaderVersion,
525+
});
526+
//await compileShader(from, shaderLang(platform), shader, path.join(project.getDebugDir(), outfile), options.to, platform, options.to);
527+
}
434528
}
435-
}
436529

437-
await compileShaders(invocations);
530+
await compileShaders(invocations);
531+
}
438532
}
439533

440534
if (options.onlyshaders) {

lib/kmake/Project.js

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/kmake/Project.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)