Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin2Js Gradle plugin #524

Closed
wants to merge 3 commits into from
Closed

Kotlin2Js Gradle plugin #524

wants to merge 3 commits into from

Conversation

abesto
Copy link
Contributor

@abesto abesto commented Nov 6, 2014

No description provided.

@bashor bashor self-assigned this Nov 6, 2014
@bashor
Copy link
Member

bashor commented Nov 11, 2014

Sorry for delay!
I'll see it today.

@bashor
Copy link
Member

bashor commented Nov 11, 2014

Looks like all commits should be merged in one. Thoughts?

@abesto
Copy link
Contributor Author

abesto commented Nov 11, 2014

Can do. ETA 1 hour.
On Nov 11, 2014 5:52 PM, "Zalim Bashorov" notifications@github.com wrote:

Looks like all commits should be merged in one. Thoughts?


Reply to this email directly or view it on GitHub
#524 (comment).

@bashor
Copy link
Member

bashor commented Nov 11, 2014

or maybe two -- impl and tests

abstract protected fun createBlankArgs(): T
public var kotlinOptions: T = createBlankArgs()

public var kotlinDestinationDir : File? = getDestinationDir()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary space before colon(:)

@abesto
Copy link
Contributor Author

abesto commented Nov 11, 2014

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>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we don't need sources in populateTargetSpecificArgs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think will be better if move up populateTargetSpecificArgs and afterCompileHook declarations, because it's part of API of this class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely.

.filterNot { isJava(it) }
.toArrayList()

protected fun populateCommonArgs(args: T, sources: ArrayList<File>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be it private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it :)


[TaskAction] fun rewrite() {
val file = File(sourceMapPath())
val text = file.readText("UTF-8")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charset parameter may be omitted -- UTF-8 will by use by default

@abesto
Copy link
Contributor Author

abesto commented Nov 11, 2014

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".

@abesto
Copy link
Contributor Author

abesto commented Nov 11, 2014

... 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!

@bashor
Copy link
Member

bashor commented Nov 11, 2014

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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need javaTask?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a bunch of tasks are added to its dependencies, so that they run on gradle build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid to use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bashor
Copy link
Member

bashor commented Nov 15, 2014

You can find some my minor changes in https://github.com/JetBrains/kotlin/commits/rr/z/pr/524__4.
It includes:

  • fixes of windows specific issues;
  • temporary disable assert for source map which fails on windows(build log;
  • temporary drop copying source files(AFAIR something fails on windows).

You can see build results for this branch here

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

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?

@bashor
Copy link
Member

bashor commented Nov 15, 2014

Would be nice if You cherry-pick my changes.

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

Done. Also: does adab044 mean that I shouldn't add kotlin-js-library as a dependency (and thus add the jar to libraryFiles) anymore? Edit: atm I can't try it out because my build against master fails with [error] /Users/abesto/playground/kotlin/libraries/stdlib/src/kotlin/io/ReadWrite.kt: (156, 37) Type mismatch: inferred type is java.util.stream.Stream<kotlin.String!>! but kotlin.Stream<kotlin.String> was expected, not yet sure if I messed up my local env or there's really a bug.

@bashor
Copy link
Member

bashor commented Nov 15, 2014

does adab044 mean that I shouldn't add kotlin-js-library as a dependency (and thus add the jar to libraryFiles) anymore?

I think in maven and in gradle user should declare kotlin-js-library as dependency explicitly.
Probably You already saw that I added args.noStdlib = true in your code

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

Ok, I'll make it so. I'm curious: is there a reason besides "let's not surprise the developer by adding dependencies"?

@bashor
Copy link
Member

bashor commented Nov 15, 2014

What version of the compiler you?
Did you rebase on current master?

@bashor
Copy link
Member

bashor commented Nov 15, 2014

They(maven, gradle) have own dependency manager and probably will be proper to use it.

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

Agree with using Gradle to define the dependency, that's how it's implemented currently. The plugin uses the Gradle dependency manager to set kotlin-js-library as a compile dependency. I take it you don't think we should do this, the user should specify it explicitly; I'll remove the code from the plugin that adds the dependency.

@bashor
Copy link
Member

bashor commented Nov 15, 2014

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

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

Wrt/ the build error: rebased on latest master (321e758). I'm using CLI tools to build. Did ant -f update_dependencies.xml, then ant -f build.xml dies with the above error. AFAICT I don't even have a working Kotlin compiler since I can't build the stdlib.

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

./dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/kotlinc-jvm -version                                                                                                                                                           22:29:22
INFO: Kotlin Compiler version 0.9.686

@bashor
Copy link
Member

bashor commented Nov 15, 2014

0.9.686 is OK, it's latest bootstrap compiler. So, I'll try build your branch locally.

@bashor
Copy link
Member

bashor commented Nov 15, 2014

I got it -- it's conflict between kotlin's Stream and java's Stream, try to run build on older runtime.

@abesto
Copy link
Contributor Author

abesto commented Nov 15, 2014

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.

@bashor
Copy link
Member

bashor commented Nov 15, 2014

I take it you don't think we should do this, the user should specify it explicitly; I'll remove the code from the plugin that adds the dependency.

Yes, for maven and gradle we prefer this way.

Anyway we should provide a way to build with and without stdlib.

abesto and others added 3 commits November 15, 2014 23:25
Conflicts:
	libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt
@abesto
Copy link
Contributor Author

abesto commented Nov 19, 2014

Quick check, are you waiting for some changes, or just didn't get around to moving on with this?

@bashor
Copy link
Member

bashor commented Nov 19, 2014

Hi, Zoltán!

Sorry for delay!

Right now I waiting some changes in master, I hope it'll happen in some days.
This changes allow to avoid your "hack" in kotlin-javascript-library and allow to use kotlin2js gradle project from IDEA.

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)?
Feel free to share your thoughts.

Thanks!

@abesto
Copy link
Contributor Author

abesto commented Nov 19, 2014

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 kotlin.js for the version of Kotlin I'm using in my project. OTOH, I can see how automatically copying the file is not clean. How about providing a task type, but not creating a task by default? That way the user can manage what happens explicitly, without having to think about Kotlin internals.

@bashor
Copy link
Member

bashor commented Nov 21, 2014

Good points, thanks! Let's continue discussion here.

@bashor
Copy link
Member

bashor commented Dec 24, 2014

Hi, @abesto!

I pushed PR commits manually with minor fixes.

@bashor
Copy link
Member

bashor commented Dec 24, 2014

Thanks a lot for your contributions!

@bashor
Copy link
Member

bashor commented Dec 24, 2014

Additionally I turn off now copy js kotlin.js from jar, it's current common behavior of all our build tools. we'll continue to think how simplify build process.

@bashor bashor closed this Dec 24, 2014
@abesto
Copy link
Contributor Author

abesto commented Dec 24, 2014

\o/ best 🎄 🎁 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants