Kotlin2Js Gradle plugin #524
Conversation
Sorry for delay! |
Looks like all commits should be merged in one. Thoughts? |
Can do. ETA 1 hour.
|
or maybe two -- impl and tests |
abstract protected fun createBlankArgs(): T | ||
public var kotlinOptions: T = createBlankArgs() | ||
|
||
public var kotlinDestinationDir : File? = getDestinationDir() |
bashor
Nov 11, 2014
Member
Unnecessary space before colon(:
)
Unnecessary space before colon(:
)
|
||
protected fun isJava(it: File): Boolean = FilenameUtils.getExtension(it.getName()).equalsIgnoreCase("java") | ||
|
||
private fun getKotlinSources(): ArrayList<File> = getSource() |
bashor
Nov 11, 2014
Member
The call chain may be written in one line
The call chain may be written in one line
bashor
Nov 11, 2014
Member
Why just not List
?
Why just not List
?
abesto
Nov 11, 2014
Author
Contributor
Good point :)
Good point :)
Fixed the two code style comments, squash coming up soon. |
|
||
args.freeArgs = sources.map { it.getAbsolutePath() } | ||
abstract protected fun populateTargetSpecificArgs(args: T, sources: ArrayList<File>) |
bashor
Nov 11, 2014
Member
looks like we don't need sources
in populateTargetSpecificArgs
looks like we don't need sources
in populateTargetSpecificArgs
bashor
Nov 11, 2014
Member
I think will be better if move up populateTargetSpecificArgs and afterCompileHook declarations, because it's part of API of this class
I think will be better if move up populateTargetSpecificArgs and afterCompileHook declarations, because it's part of API of this class
abesto
Nov 11, 2014
Author
Contributor
Absolutely.
Absolutely.
.filterNot { isJava(it) } | ||
.toArrayList() | ||
|
||
protected fun populateCommonArgs(args: T, sources: ArrayList<File>) { |
bashor
Nov 11, 2014
Member
should be it private?
should be it private?
abesto
Nov 11, 2014
Author
Contributor
In an ideal world, yes. I don't know enough to confidently say no-one will ever need to override it. If you say go, I'll change it.
In an ideal world, yes. I don't know enough to confidently say no-one will ever need to override it. If you say go, I'll change it.
bashor
Nov 11, 2014
Member
let's do it :)
let's do it :)
protected fun isJava(it: File): Boolean = FilenameUtils.getExtension(it.getName()).equalsIgnoreCase("java") | ||
|
||
private fun getKotlinSources(): ArrayList<File> = getSource() | ||
.filterNot { isJava(it) } |
bashor
Nov 11, 2014
Member
I think more properly to check that it's kotlin file.
P.S. I see that it's legacy code
I think more properly to check that it's kotlin file.
P.S. I see that it's legacy code
bashor
Nov 11, 2014
Member
You can get file extension by file.extension
.
And You can use JetFileType.EXTENSION
instead of magic string.
You can get file extension by file.extension
.
And You can use JetFileType.EXTENSION
instead of magic string.
abesto
Nov 11, 2014
Author
Contributor
FYI, I'll rebase to the latest master to get JetFileType.EXTENSION
. Would have to do it anyway. I'll squash the commits again once we're done with the review.
FYI, I'll rebase to the latest master to get JetFileType.EXTENSION
. Would have to do it anyway. I'll squash the commits again once we're done with the review.
bashor
Nov 11, 2014
Member
ok
ok
abesto
Nov 11, 2014
Author
Contributor
JavaFileType
has slightly different constants, so I used the common interface to make the symmetry obvious.
JavaFileType
has slightly different constants, so I used the common interface to make the symmetry obvious.
private fun getJavaSourceRoots(): HashSet<File> = getSource() | ||
.filter { isJava(it) } | ||
.map { findSrcDirRoot(it) } | ||
.filter { it != null } |
bashor
Nov 11, 2014
Member
May be replaced with filterNotNull
May be replaced with filterNotNull
abesto
Nov 11, 2014
Author
Contributor
Great! I spent a minute or so looking for this method but couldn't find it for some reason.
Great! I spent a minute or so looking for this method but couldn't find it for some reason.
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details") | ||
else -> {} | ||
} | ||
private fun getJavaSourceRoots(): HashSet<File> = getSource() |
bashor
Nov 11, 2014
Member
May be List
?
May be List
?
abesto
Nov 11, 2014
Author
Contributor
It needs to be a set because generally there will be several files in each source root, leading to multiple entries for each source root. But I've generalized it from HashSet to just Set.
It needs to be a set because generally there will be several files in each source root, leading to multiple entries for each source root. But I've generalized it from HashSet to just Set.
bashor
Nov 11, 2014
Member
ok
ok
|
||
fun outputFile(): String { | ||
return if (StringUtils.isEmpty(kotlinOptions.outputFile)) { | ||
"${kotlinDestinationDir}/app.js" |
bashor
Nov 11, 2014
Member
I think outputFile can not be omitted and if it omitted compilation should be failed.
I think outputFile can not be omitted and if it omitted compilation should be failed.
abesto
Nov 11, 2014
Author
Contributor
Isn't this the same case as destination
for the JVM task? There the plugin defaults to kotlinDestinationDir
. This is basically the same logic. Of course we don't need to keep symmetry between the plugins.
I don't have a strong preference, it's up to you :)
Isn't this the same case as destination
for the JVM task? There the plugin defaults to kotlinDestinationDir
. This is basically the same logic. Of course we don't need to keep symmetry between the plugins.
I don't have a strong preference, it's up to you :)
bashor
Nov 11, 2014
Member
They are similar but not the same.
In k2js compiler right now file name will be used as module name, so I think this parameter should be provided explicitly. (Probably in the future it will be replaced with moduleName
)
They are similar but not the same.
In k2js compiler right now file name will be used as module name, so I think this parameter should be provided explicitly. (Probably in the future it will be replaced with moduleName
)
bashor
Nov 11, 2014
Member
As far as i understand JVM task, by default, use project's build dir.
As far as i understand JVM task, by default, use project's build dir.
abesto
Nov 11, 2014
Author
Contributor
Ok, that makes sense. I'm convinced.
Ok, that makes sense. I'm convinced.
|
||
[TaskAction] fun rewrite() { | ||
val file = File(sourceMapPath()) | ||
val text = file.readText("UTF-8") |
bashor
Nov 11, 2014
Member
charset parameter may be omitted -- UTF-8 will by use by default
charset parameter may be omitted -- UTF-8 will by use by default
Sorry for the delay, I shot myself in the foot by upgrading my default java to 8, causing strange gradle internal errors. Almost done with "fail if outputFile not set". |
... and then proceeded to shoot myself in the foot repeatedly with various tools. Anyway, that's it for me today. Next time I'll have more than 10 minutes to hack on this will probably be Thursday. Thanks for the review so far! |
Thanks for your efforts! |
compilerClass = javaClass<Kotlin2JsCompile>()) { | ||
val copyKotlinJsTaskName = sourceSet.getTaskName("copy", "kotlinJs") | ||
val clean = project.getTasks().findByName("clean") | ||
val compileJava = project.getTasks().findByName(sourceSet.getCompileJavaTaskName()) as AbstractCompile? |
bashor
Nov 12, 2014
Member
Why we need javaTask?
Why we need javaTask?
abesto
Nov 15, 2014
Author
Contributor
Because a bunch of tasks are added to its dependencies, so that they run on gradle build
.
Because a bunch of tasks are added to its dependencies, so that they run on gradle build
.
bashor
Nov 15, 2014
Member
Could we avoid to use it?
Could we avoid to use it?
} | ||
} | ||
|
||
public open class RewritePathsInSourceMap() : DefaultTask() { |
bashor
Nov 12, 2014
Member
Ideally it should be fixed in compiler as part of KT-4078. You can just add TODO comment that this hack should be dropped after KT-4078 will be fixed or fix it :)
Ideally it should be fixed in compiler as part of KT-4078. You can just add TODO comment that this hack should be dropped after KT-4078 will be fixed or fix it :)
abesto
Nov 15, 2014
Author
Contributor
Ah, nice to know this is something you've already thought about. I'd prefer not to attack 4078, added TODOs in abesto@c50a32e
Ah, nice to know this is something you've already thought about. I'd prefer not to attack 4078, added TODOs in abesto@c50a32e
|
||
override fun createBlankArgs(): K2JSCompilerArguments = K2JSCompilerArguments() | ||
|
||
public fun addLibraryFiles(vararg fs: String) { |
bashor
Nov 12, 2014
Member
I think we should extract all libraries from dependencies instead.
I think we should extract all libraries from dependencies instead.
clean?.dependsOn("clean" + kotlinTaskName.capitalize()) | ||
|
||
createCopyKotlinJsTask(jsLibraryJar) | ||
createCopyKotlinSourcesForSourceMapTask() |
bashor
Nov 13, 2014
Member
I think we should not be able to copy source files.
I think we should not be able to copy source files.
abesto
Nov 15, 2014
Author
Contributor
I'm not exactly sure what you mean. Let me explain the use-case I tried to solve here, maybe that's an answer; if not, please clarify.
There are two things you may want to do with source maps. One, use them locally. In this case it doesn't matter where the Kotlin sources are, the browser will find them over the file://
protocol. Two, distribute the source-map and Kotlin sources with the project; either as a debug build of the application, or as an example of kotlin2js. In this case the Kotlin sources need to be copied to a place the sourcemap can reference; also it needs to be edited to point to paths relative to the sourcemap (that's what createRewritePathsInSourceMapTask
does).
I'm not exactly sure what you mean. Let me explain the use-case I tried to solve here, maybe that's an answer; if not, please clarify.
There are two things you may want to do with source maps. One, use them locally. In this case it doesn't matter where the Kotlin sources are, the browser will find them over the file://
protocol. Two, distribute the source-map and Kotlin sources with the project; either as a debug build of the application, or as an example of kotlin2js. In this case the Kotlin sources need to be copied to a place the sourcemap can reference; also it needs to be edited to point to paths relative to the sourcemap (that's what createRewritePathsInSourceMapTask
does).
bashor
Nov 15, 2014
Member
I think that this gradle task should not be able to copy source files because user can do it in plain gradle if need, and how he want. And maybe it can lead to accidental leakage of sources.
But we should provide better way to setup source map generation(KT-4078).
I think that this gradle task should not be able to copy source files because user can do it in plain gradle if need, and how he want. And maybe it can lead to accidental leakage of sources.
But we should provide better way to setup source map generation(KT-4078).
You can find some my minor changes in https://github.com/JetBrains/kotlin/commits/rr/z/pr/524__4.
You can see build results for this branch here |
Thanks for linking your changes, they look good to me. Should I merge / cherry-pick them into this branch, or will you take care of that after the next squash? |
Would be nice if You cherry-pick my changes. |
Done. Also: does adab044 mean that I shouldn't add |
Ok, I'll make it so. I'm curious: is there a reason besides "let's not surprise the developer by adding dependencies"? |
What version of the compiler you? |
They(maven, gradle) have own dependency manager and probably will be proper to use it. |
Agree with using Gradle to define the dependency, that's how it's implemented currently. The plugin uses the Gradle dependency manager to set |
For developing Kotlin we use plugin from https://teamcity.jetbrains.com/guestAuth/repository/download/bt345/bootstrap.tcbuildtag/updatePlugins.xml You can find more information here |
Wrt/ the build error: rebased on latest master (321e758). I'm using CLI tools to build. Did |
|
0.9.686 is OK, it's latest bootstrap compiler. So, I'll try build your branch locally. |
I got it -- it's conflict between kotlin's Stream and java's Stream, try to run build on older runtime. |
Bah. This again. Nice, thanks for figuring it out, build works with Java 7. Will now fix if any tests are broken and squash the commits. |
Yes, for maven and gradle we prefer this way. Anyway we should provide a way to build with and without stdlib. |
Conflicts: libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt
Quick check, are you waiting for some changes, or just didn't get around to moving on with this? |
Hi, Zoltán! Sorry for delay! Right now I waiting some changes in master, I hope it'll happen in some days. Additionally we don't sure that our buildtools(ant, maven, gradle) should copy js files from libraries to out dir. Maybe user should do it himself(by own tools)? Thanks! |
No problem at all, thanks for the prompt response. Avoiding hacks is great, I'm fine with waiting for it. About not copying the library to the out dir: as a user of the plugins, I have no idea where to find the |
Good points, thanks! Let's continue discussion here. |
Hi, @abesto! I pushed PR commits manually with minor fixes. |
Thanks a lot for your contributions! |
Additionally I turn off now copy js |
\o/ best |
This comment has been minimized.
This comment has been minimized.
yanex
commented on libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt
in 0435c90
Dec 24, 2014
Files with ".kts" extension are Kotlin source files as well. |
No description provided.