karakum-team / karakum

Converter of TypeScript declaration files to Kotlin declarations
Apache License 2.0
37 stars 0 forks source link

Support Linux paths in confing on Windows #6

Closed joffrey-bion closed 1 year ago

joffrey-bion commented 1 year ago

Since Karakum's config is likely to be checked in version control, it would be best if it supported Linux-style relative paths even on Windows.

At the moment, the Gradle plugin seems to concatenate Windows absolute paths with the Linux relative path from the config (e.g. when substituting <nodeModules>). This happens for everything except the output property, which is correctly converted.

Example input config <project>/karakum.config.json:

{
    "input": "<nodeModules>/@blueprintjs/icons/lib/esm/index.d.ts",
    "output": "src/jsMain/generated",
    "libraryName": "blueprintjs-icons"
}

Output config in <project>/build/karakum/karakum.config.json:

{
  "input" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\node_modules/@blueprintjs/icons/lib/esm/index.d.ts",
  "output" : "C:\\Projects\\kotlin-blueprintjs\\kotlin-blueprintjs-icons\\src\\jsMain\\generated",
  "libraryName" : "blueprintjs-icons",
  "plugins" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\packages\\kotlin-blueprintjs-kotlin-blueprintjs-icons\\karakum/plugins/*.js",
  "annotations" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\packages\\kotlin-blueprintjs-kotlin-blueprintjs-icons\\karakum/annotations/*.js",
  "nameResolvers" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\packages\\kotlin-blueprintjs-kotlin-blueprintjs-icons\\karakum/nameResolvers/*.js",
  "inheritanceModifiers" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\packages\\kotlin-blueprintjs-kotlin-blueprintjs-icons\\karakum/inheritanceModifiers/*.js"
}

When this happens, the input file is actually not found and nothing is generated. This happens silently by the way, no error in the build log, and the build doesn't fail:

> Task :kotlin-blueprintjs-icons:generateKarakumExternals
Source files root: /
Source files count: 0
Covered nodes: 0
Uncovered nodes: 0

BUILD SUCCESSFUL in 941ms
sgrishchenko commented 1 year ago

I tried to adapt Karakum for Windows. I checked it on kotlin-wrappers, so it seems it works now. Could you also check if it works for you?

joffrey-bion commented 1 year ago

Hi. Thanks again for making this change!

So I checked again with 1.0.0-alpha.20, and with the same input config:

{
    "input": "<nodeModules>/@blueprintjs/icons/lib/esm/index.d.ts",
    "output": "src/jsMain/generated",
    "libraryName": "blueprintjs-icons"
}

I get the following generated config:

{
  "input" : "C:/Projects/kotlin-blueprintjs/build/js/node_modules/@blueprintjs/icons/lib/esm/index.d.ts",
  "output" : "C:\\Projects\\kotlin-blueprintjs\\kotlin-blueprintjs-icons\\src\\jsMain\\generated",
  "libraryName" : "blueprintjs-icons",
  "cwd" : "C:\\Projects\\kotlin-blueprintjs\\build\\js\\packages\\kotlin-blueprintjs-kotlin-blueprintjs-icons"
}

Which is a bit weird. Shouldn't we generate a proper Windows path for the input field in the config?

I'm assuming Karakum itself should deal with the Windows paths in the config on its own. If I were not using the Gradle plugin, I would probably want to either use Windows paths everywhere in the config, or linux paths everywhere in the config (likely the latter).

In any case, this seems to work (in the sense that the path is correctly read by Karakum from the Gradle-generated config, so it seems good enough for now. Thanks! (feel free to close this issue, and if further problems appear due to these paths, we can always reopen)

sgrishchenko commented 1 year ago

Shouldn't we generate a proper Windows path for the input field in the config?

It is fully proper glob pattern, it works for Windows too, globs are not paths, in globs \ symbol means escaping, so using \ as path separator in globs is bad idea. So, rule is simple: if it is path, Gradle plugin will generate OS specific string for you (because it is simple and it works), if it is glob pattern, it will use posix separator. If you write config by hand, just use posix separator, it works on Windows, because I normalize all paths and convert them to posix style on configuration phase.

joffrey-bion commented 1 year ago

So, rule is simple: if it is path, Gradle plugin will generate OS specific string for you (because it is simple and it works), if it is glob pattern, it will use posix separator.

Ah ok, got it. It's clear now, thanks!

joffrey-bion commented 1 year ago

By the way, it might be worth documenting the different properties of the config and what they mean, including that input is not a path but a glob pattern

sgrishchenko commented 1 year ago

Yea, its definitely true, I need more documentation, I am going to document next thing in near feature: Gradle plugin, Karakum plugins (and other extensions) and configuration of course.