1 |
Hi folks, |
2 |
|
3 |
There have been plenty of events going on in my project this week and |
4 |
several pieces of good news. To start with, I placed the last piece |
5 |
of jigsaw of my plans on the two existing Kotlin ebuilds in the Spark |
6 |
overlay, dev-java/kotlin-common-bin and dev-lang/kotlin-bin, by |
7 |
writing up the src_test phase function for each of them that would |
8 |
compile some sample Kotlin programs provided by JetBrains using the |
9 |
Kotlin libraries and the compiler. Then, thanks to fordfrog's |
10 |
assistance, I further improved java-ebuilder and implemented a more |
11 |
precise and reliable way of extracting metadata values from ebuilds, |
12 |
especially each ebuild's SLOT. Last but not least, today I have just |
13 |
created the ebuild for a revolutionary package of kotlin-stdlib that |
14 |
compiles from source, which, to my knowledge, has not appeared yet in |
15 |
any other GNU/Linux distribution. |
16 |
|
17 |
The plan to use sample programs to test the Kotlin compiler was in my |
18 |
original project proposal, but it was not quite easy to implement |
19 |
because compilation of those programs using kotlinc without any extra |
20 |
arguments to it failed, and there were not any instructions to build |
21 |
those tests from the command-line interface. After all, Kotlin |
22 |
heavily relies on Gradle, and the Kotlin Gradle plugin is the de facto |
23 |
tool for building Kotlin projects, so JetBrains, the upstream, has not |
24 |
paid any attention to command-line compiler support. However, the |
25 |
upstream supports building the sample programs from Gradle, and the |
26 |
source code for the Kotlin Gradle plugin is also available, so I had |
27 |
thought of studying how the sample Kotlin programs would be compiled |
28 |
by Gradle by looking at Gradle and the plugin's internals. It later |
29 |
turned out that source code inspection was not necessary at all after |
30 |
I first tried to run Gradle with the '--debug' option, which made |
31 |
Gradle print out the Kotlin compiler option it used to compile those |
32 |
programs. With such information, I successfully implemented |
33 |
dev-lang/kotlin-bin's src_test function by getting the sample program |
34 |
compilation work. Strictly speaking, it is not necessary to test |
35 |
pre-compiled binary packages, but I have modified those packages to |
36 |
install their files in a Gentoo-compliant way, which differs from the |
37 |
upstream's intended package layout, so running those tests would help |
38 |
me and any future maintainers ensure we are modifying the installation |
39 |
paths right. |
40 |
|
41 |
Meanwhile, I contacted fordfrog to discuss the improvements I had made |
42 |
on java-ebuilder and mentioned my effort to let it recognize all kinds |
43 |
of SLOT expressions that might use any combination of plain string |
44 |
literals, Bash string manipulation syntax, and ebuild functions like |
45 |
ver_cut. He suggested that we could skip writing a parser to evaluate |
46 |
the expressions ourselves, and read the evaluated value from ebuild |
47 |
metadata cache generated by Portage's egencache program instead. This |
48 |
method could get us the precise evaluation result, and the |
49 |
implementation would be easy to maintain in the future. A parser, on |
50 |
the other hand, could only mock Portage's behavior to a limited extent |
51 |
and would require updates when anything among Portage, eclasses, |
52 |
Gentoo PMS, etc. is changed. To implement it, I first studied how to |
53 |
get egencache to create cache for an arbitrary ebuild repository that |
54 |
could be at anywhere in the file system, because egencache would by |
55 |
default refuse to create cache for repos not added to Portage, but |
56 |
sometimes users would need to use such a repo. Then, I created a few |
57 |
prototypes, collected feedback on them from fordfrog, incorporated the |
58 |
suggestions, and tuned java-ebuilder for best performance under |
59 |
general use cases. Now, my fork of java-ebuilder is capable of |
60 |
handling all kinds of SLOT expressions. Without fordfrog's insightful |
61 |
advice on a solution that would both be easy to implement and work |
62 |
correctly, I could not have made this improvement, so thanks fordfrog |
63 |
for your help! |
64 |
|
65 |
In my original plan, I did not think of building any Kotlin component |
66 |
from source because Gradle seemed to be a complicated build system to |
67 |
me, and building the entire Kotlin toolchain from Gradle was quite an |
68 |
obscure process. After discovering the way to easily find the Kotlin |
69 |
compiler options used by Gradle and seeing Benda's question about |
70 |
building Kotlin from source, I brought the idea of creating at least a |
71 |
source-based package for the Kotlin Standard Library back to the |
72 |
table. With the same '--debug' trick, I extracted Kotlin compiler |
73 |
options that were used to build multiple components of Kotlin |
74 |
libraries, including kotlin-stdlib, kotlin-stdlib-jdk{7,8} and |
75 |
kotlin-annotations-jvm. Today, I tried to first make an ebuild to |
76 |
compile kotlin-stdlib from source because it was the component that |
77 |
required the least prerequisites to build, and the good news is the |
78 |
ebuild [1] can use the Kotlin compiler and a pre-built bootstrap copy |
79 |
of the Standard Library to build kotlin-stdlib directly from its |
80 |
source code without any compiler errors! The ebuild is not perfect |
81 |
yet, but at least this has proven that some Kotlin components can |
82 |
still be built without Gradle. This not only complies with Gentoo's |
83 |
spirit of building everything from source whenever possible but is |
84 |
probably also the birth of the first Kotlin package for a GNU/Linux |
85 |
distribution that is built from source. Kotlin packages in other |
86 |
distributions' repositories like Arch Linux's AUR are all binary ones |
87 |
exploiting the pre-built distribution archive from JetBrains, just |
88 |
like dev-lang/kotlin-common-bin. |
89 |
|
90 |
I am looking forward to getting rid of the '-bin' suffix in at least |
91 |
the Kotlin library package's name and witnessing creation of the |
92 |
world's first source-based Kotlin package on Gentoo. I have already |
93 |
written an eclass [2] that will help me create source packages for |
94 |
other Kotlin library components next week. Even if I cannot make it, |
95 |
my current work can probably still act as a basis for any future |
96 |
developers to bring such packages to reality. |
97 |
|
98 |
Best regards, |
99 |
Leo |
100 |
|
101 |
[1]: https://github.com/Leo3418/spark-overlay/blob/master/dev-java/kotlin-stdlib/kotlin-stdlib-1.5.10.ebuild |
102 |
[2]: https://github.com/Leo3418/spark-overlay/blob/master/eclass/kotlin-tasks.eclass |