From 1b1aaf2407cacead3809ab6e29ceb7012bb49955 Mon Sep 17 00:00:00 2001 From: Evan Welsh Date: Sat, 10 Feb 2024 15:20:29 -0800 Subject: [PATCH] temp: Fix generation issues and infinite dependency loops --- .ts-for-gir.packages-all.rc.js | 3 ++ packages/cli/src/generation-handler.ts | 33 ++++--------------- .../src/html-doc-generator.ts | 17 ++++++---- .../src/type-definition-generator.ts | 23 +++++-------- packages/lib/src/gir-module.ts | 33 +++++-------------- packages/lib/src/newlib/gir/util.ts | 4 ++- types | 2 +- 7 files changed, 41 insertions(+), 74 deletions(-) diff --git a/.ts-for-gir.packages-all.rc.js b/.ts-for-gir.packages-all.rc.js index ca4fdb511..d0b22f931 100644 --- a/.ts-for-gir.packages-all.rc.js +++ b/.ts-for-gir.packages-all.rc.js @@ -20,6 +20,9 @@ export default { // GNOME Shell gir file dependencies on Fedora Workstation 38 (package: mutter) '/usr/lib64/mutter-12', + // GNOME Shell gir file dependencies on Fedora Workstation 39 (package: mutter) + '/usr/lib64/mutter-13', + // GNOME Shell gir file dependencies on Ubuntu 22.04 (package: libmutter-10-dev) '/usr/lib/x86_64-linux-gnu/mutter-10', diff --git a/packages/cli/src/generation-handler.ts b/packages/cli/src/generation-handler.ts index 55e7f60a3..d8ef4a3b5 100644 --- a/packages/cli/src/generation-handler.ts +++ b/packages/cli/src/generation-handler.ts @@ -12,7 +12,7 @@ import { GeneratorType, Generator } from '@ts-for-gir/generator-base' import { TypeDefinitionGenerator } from '@ts-for-gir/generator-typescript' // import { HtmlDocGenerator } from '@ts-for-gir/generator-html-doc' -import type { InheritanceTable, GenerateConfig, NSRegistry } from '@ts-for-gir/lib' +import type { GenerateConfig, NSRegistry } from '@ts-for-gir/lib' export class GenerationHandler { log: Logger @@ -36,19 +36,6 @@ export class GenerationHandler { } } - private finalizeInheritance(inheritanceTable: InheritanceTable): void { - for (const clsName of Object.keys(inheritanceTable)) { - let p: string | string[] = inheritanceTable[clsName][0] - while (p) { - p = inheritanceTable[p] - if (p) { - p = p[0] - inheritanceTable[clsName].push(p) - } - } - } - } - public async start(girModules: GirModule[], registry: NSRegistry): Promise { this.log.info(START_MODULE(this.config.environment, this.config.buildType)) @@ -56,23 +43,12 @@ export class GenerationHandler { this.log.error(ERROR_NO_MODULE_SPECIFIED) } - GirModule.allGirModules = girModules - this.log.info(FILE_PARSING_DONE) - const inheritanceTable: InheritanceTable = {} - for (const girModule of girModules) girModule.init(inheritanceTable) - - this.finalizeInheritance(inheritanceTable) - this.log.info(TSDATA_PARSING_DONE) - for (const girModule of girModules) { - if (this.config.outdir) { - await mkdir(this.config.outdir, { recursive: true }) - } - this.log.log(` - ${girModule.packageName} ...`) - girModule.start(girModules) + if (this.config.outdir) { + await mkdir(this.config.outdir, { recursive: true }) } // TODO: Put this somewhere that makes sense @@ -85,6 +61,9 @@ export class GenerationHandler { await this.generator.start(registry) for (const girModule of girModules) { + this.log.log(` - ${girModule.packageName} ...`) + girModule.start(girModules) + await this.generator.generate(registry, girModule) } diff --git a/packages/generator-html-doc/src/html-doc-generator.ts b/packages/generator-html-doc/src/html-doc-generator.ts index 8d626c26f..d262cf8f2 100644 --- a/packages/generator-html-doc/src/html-doc-generator.ts +++ b/packages/generator-html-doc/src/html-doc-generator.ts @@ -2,7 +2,7 @@ import { Logger, DANGER_HTML_DOC_GENERATOR_NOT_IMPLEMENTED } from '@ts-for-gir/lib' import { Generator } from '@ts-for-gir/generator-base' -import type { GenerateConfig, GirModulesGrouped, InheritanceTable, GirModule } from '@ts-for-gir/lib' +import type { GenerateConfig, GirModule, NSRegistry } from '@ts-for-gir/lib' /** * A template that can be used to implement an HTML Documentation Generator @@ -12,11 +12,16 @@ export class HtmlDocGenerator implements Generator { constructor(protected readonly config: GenerateConfig) { this.log = new Logger(config.environment, config.verbose, HtmlDocGenerator.name) } - public async start( - girModules: GirModule[], - girModulesGrouped: GirModulesGrouped[], - inheritanceTable: InheritanceTable, - ) { + + async start(_registry: NSRegistry): Promise { return Promise.resolve(this.log.danger(DANGER_HTML_DOC_GENERATOR_NOT_IMPLEMENTED)) } + + generate(_registry: NSRegistry, _module: GirModule): Promise { + throw new Error('Method not implemented.') + } + + finish(_registry: NSRegistry): Promise { + throw new Error('Method not implemented.') + } } diff --git a/packages/generator-typescript/src/type-definition-generator.ts b/packages/generator-typescript/src/type-definition-generator.ts index 5f316f81e..ebe5dfa13 100644 --- a/packages/generator-typescript/src/type-definition-generator.ts +++ b/packages/generator-typescript/src/type-definition-generator.ts @@ -243,10 +243,6 @@ class ModuleGenerator extends FormatGenerator { } generateProperty(tsProp: IntrospectedProperty, construct?: boolean, indentCount = 0) { - // if (!tsProp) { - // throw new Error('[generateProperty] Not all required properties set!') - // } - const desc: string[] = [] const isStatic = false //tsProp.isStatic @@ -269,10 +265,6 @@ class ModuleGenerator extends FormatGenerator { } generateField(tsProp: IntrospectedField, indentCount = 0) { - if (!tsProp) { - throw new Error('[generateProperty] Not all required properties set!') - } - const desc: string[] = [] const isStatic = false //tsProp.isStatic @@ -819,15 +811,17 @@ class ModuleGenerator extends FormatGenerator { generateEnumMember(tsMember: GirEnumMember, indentCount = 1) { const desc: string[] = [] - // if (!tsMember) { - // this.log.warn(NO_TSDATA('generateEnumerationMember')) - // return desc - // } - desc.push(...this.addGirDocComment(tsMember.doc, [], indentCount)) + const invalid = isInvalid(tsMember.name) + const indent = generateIndent(indentCount) - desc.push(`${indent}${tsMember.name},`) + if (invalid) { + desc.push(`${indent}"${tsMember.name}",`) + } else { + desc.push(`${indent}${tsMember.name},`) + } + return desc } @@ -1835,7 +1829,6 @@ export class TypeDefinitionGenerator implements Generator { public async generate(registry: NSRegistry, module: GirModule) { this.module = new ModuleGenerator(module, this.config) - console.log('generating...' + module.name) await this.module.exportModuleTS() } diff --git a/packages/lib/src/gir-module.ts b/packages/lib/src/gir-module.ts index 50cd1745d..22d7c422e 100644 --- a/packages/lib/src/gir-module.ts +++ b/packages/lib/src/gir-module.ts @@ -67,10 +67,6 @@ import { LoadOptions } from './newlib/types.js' import { GirVisitor } from './newlib/visitor.js' export class GirModule { - /** - * Array of all gir modules - */ - static allGirModules: GirModule[] = [] /** * E.g. 'Gtk' */ @@ -112,8 +108,6 @@ export class GirModule { return [...new Set([...this.dependencies, ...this.transitiveDependencies])] } - repo!: GirRepository - ns: GirModule /** * Used to find namespaces that are used in other modules */ @@ -160,12 +154,13 @@ export class GirModule { this.c_prefixes = [...prefixes] this.package_version = ['0', '0'] this.config = config - this.repo = repo this.dependencyManager = DependencyManager.getInstance(this.config) - this.dependencies = this.dependencyManager.fromGirIncludes(this.repo.include || []) + this.dependencies = this.dependencyManager.fromGirIncludes(repo.include || []) + } - this.ns = this + get ns() { + return this } private checkTransitiveDependencies(transitiveDependencies: Dependency[]) { @@ -1198,12 +1193,13 @@ export class GirModule { if (!ns) throw new Error(`Missing namespace in ${repo.repository[0].package[0].$.name}`) const modName = ns.$['name'] - let version = ns.$['version'] + const version = ns.$['version'] + // TODO: Hardcoding HarfBuzz here leads to issues when loading... // Hardcode harfbuzz version for now... - if (modName === 'HarfBuzz' && version === '0.0') { - version = '2.0' - } + // if (modName === 'HarfBuzz' && version === '0.0') { + // version = '2.0' + // } const options: LoadOptions = { loadDocs: !config.noComments, @@ -1398,15 +1394,6 @@ export class GirModule { return building } - /** - * Before processing the typescript data, each module should be initialized first. - * This is done in the `GenerationHandler`. - */ - public init(inheritanceTable: InheritanceTable) { - // this.loadTypes() - // this.loadInheritance(inheritanceTable) - } - /** * Start processing the typescript data */ @@ -1418,8 +1405,6 @@ export class GirModule { this.libraryVersion = glibModule.libraryVersion } } - - // this.setModuleTsData() } } diff --git a/packages/lib/src/newlib/gir/util.ts b/packages/lib/src/newlib/gir/util.ts index 872fc9e11..04bcb0dee 100644 --- a/packages/lib/src/newlib/gir/util.ts +++ b/packages/lib/src/newlib/gir/util.ts @@ -355,7 +355,9 @@ export function isInvalid(name: string): boolean { } export function parseDoc(element: GirDocElement): string | null { - return element.doc?.[0]?._ ?? null; + const el = element.doc?.[0]?._; + + return el ? `${el}` : null; } export function parseDeprecatedDoc(element: GirDocElement): string | null { diff --git a/types b/types index 42c6850ac..e5ee6c15f 160000 --- a/types +++ b/types @@ -1 +1 @@ -Subproject commit 42c6850ac4c40d61fe5862b1def764d8628504f5 +Subproject commit e5ee6c15f61bf4eb6b89511ddfe2aa6606763058