Skip to content

Commit

Permalink
temp: Fix generation issues and infinite dependency loops
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlsh committed Feb 10, 2024
1 parent aa8a702 commit 1b1aaf2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .ts-for-gir.packages-all.rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
33 changes: 6 additions & 27 deletions packages/cli/src/generation-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,43 +36,19 @@ 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<void> {
this.log.info(START_MODULE(this.config.environment, this.config.buildType))

if (girModules.length == 0) {
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
Expand All @@ -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)
}

Expand Down
17 changes: 11 additions & 6 deletions packages/generator-html-doc/src/html-doc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<void> {
return Promise.resolve(this.log.danger(DANGER_HTML_DOC_GENERATOR_NOT_IMPLEMENTED))
}

generate(_registry: NSRegistry, _module: GirModule): Promise<void> {
throw new Error('Method not implemented.')
}

finish(_registry: NSRegistry): Promise<void> {
throw new Error('Method not implemented.')
}
}
23 changes: 8 additions & 15 deletions packages/generator-typescript/src/type-definition-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ class ModuleGenerator extends FormatGenerator<string[]> {
}

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

Expand All @@ -269,10 +265,6 @@ class ModuleGenerator extends FormatGenerator<string[]> {
}

generateField(tsProp: IntrospectedField, indentCount = 0) {
if (!tsProp) {
throw new Error('[generateProperty] Not all required properties set!')
}

const desc: string[] = []
const isStatic = false //tsProp.isStatic

Expand Down Expand Up @@ -819,15 +811,17 @@ class ModuleGenerator extends FormatGenerator<string[]> {
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
}

Expand Down Expand Up @@ -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()
}

Expand Down
33 changes: 9 additions & 24 deletions packages/lib/src/gir-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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[]) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
*/
Expand All @@ -1418,8 +1405,6 @@ export class GirModule {
this.libraryVersion = glibModule.libraryVersion
}
}

// this.setModuleTsData()
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/lib/src/newlib/gir/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion types
Submodule types updated 305 files

0 comments on commit 1b1aaf2

Please sign in to comment.