Reorganise the gradle build script#32
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #32 +/- ##
=======================================
Coverage ? 38.20%
Complexity ? 15
=======================================
Files ? 24
Lines ? 89
Branches ? 6
=======================================
Hits ? 34
Misses ? 51
Partials ? 4 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
mgautierfr
left a comment
There was a problem hiding this comment.
I don't see any dependency between build and generateHeader nor between test and build. It is sad that it is one of the goal of the issue.
We have modify the lib/src/main/cpp/CMakeLists.txt file for this , Here we have placed a condition, If it's linux target then it will generate the .so file (in build directory), If we will use the ./gradlew build command then it will generate the .aar file for android.
CMakeList.txt is a internal implementation detail of the build system. User should run gradle to build the wrapper (which will run cmake for us). They must not run cmake directly so we can remove this condition.
About all the task copyLibzim*, would it be possible to move it in a function with parameters to avoid duplication.
And why having differents tasks for that ? Do we have the possibility to use only the arm64 library ? If not, we don't need different tasks (and the tasks downloadLibzimSoHandHeaderFiles and unzipLibzim do all archs)
I'm not sure to understand build the dependency system in gradle.
You never tell gradle that build or generateHeader depends of other tasks, but they are run anyway. Why do you need to tell that build depends of buildLinuxSoFile ?
There was a problem hiding this comment.
The diff of this file is really difficult to read.
I don't know if you have change something (and what) or if you have simply moved code in the file.
It would have been better to have a commit moving code (without changing it) and another commit changing the code (if needed). Of course with nice commit message.
| commandLine 'bash', '-c', "cmake . -B ${buildDir} && make -C ${buildDir}" | ||
| } | ||
|
|
||
| build.dependsOn buildLinuxSoFile No newline at end of file |
There was a problem hiding this comment.
What build target does more than buildLinuxSoFile ?
There was a problem hiding this comment.
build target for generating the .aar file for android.
|
@mgautierfr , Thanks for the review.
Here,
Good point, We should use
I'm not getting this point, but if we are generating the .aar file with build command for android, then IMO we can only generate the .aar or .so at a time. |
@mgautierfr for this i have create two new tasks ( |
Could we use regex/glob with |
7c1dfed to
92a22a6
Compare
|
@MohitMaliFtechiz There is something I don't understand in gradle (and it is me not knowing gradle. I probably need a pointer or a explanation from you about that): How gradle defines the dependencies between targets. Except for |
@mgautierfr , in android library project, |
I have try to use regex/glob with |
It seems from the doc that we can somehow use complex rules to know what to copy: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html |
hi @mgautierfr , Thanks for the reference, i have try this way to copy the |
|
I’m sorry to bother you with details but I’m not really happy with a few target naming:
@mgautierfr What do you think? |
But we are also building so file for other targeted platform than linux (android)
I like to have the build script independent of the CI. Else I agree with all your other remarks. |
c39149c to
9488ddd
Compare
Done.
Regrading this i am agree with @mgautierfr .
|
Then please update/remove from CI accordingly. |
|
@kelson42 , I have did the changes but currently CI has some problem to run, so i have not tested yet. Once CI runs I'll test it. |
mgautierfr
left a comment
There was a problem hiding this comment.
I don't know why the CI is not running but here my review anyway.
I'm not sure it will work as it seems you have forget to commit few things.
I hadn't pay attention since now but please rewrite (almost) all your commit messages.
A good commit message is :
A title on one line
A full description (if needed), separated with a empty line
from the title line.
The description can be as long as needed, but take care that
the lines themeselves (both in description and title) are not too
long (keep them under 80 chars)
Almost all your commit is only one long line and it breaks the assertion about
commit message format (and the way it is display in github and all other git tools)
| .filter(f -> f.name.startsWith(matchesString)) | ||
| .map(s -> s.name.replace(matchesString, "")) | ||
| .collect(Collectors.toList())[0] | ||
| static void renameFolders(String path, String startWith) { |
There was a problem hiding this comment.
The method doesn't simply rename folders.
It is removing date information for the folder. It should be named accordingly.
| dependsOn testSourceJar | ||
| source = fileTree('src/test/') | ||
| destinationDirectory = file('src/test/') | ||
| classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar") |
There was a problem hiding this comment.
Do we need to package the sources as a jar to compile it ?
Could be simply build from the sources directly ?
There was a problem hiding this comment.
Yes, we need to package the sources as a jar to compile the test cases. I have tried to build from the sources directly, But it was not including the sources with classpath in test cases.
| task generateHeader(type: Exec) { | ||
| workingDir "${projectDir}/src/main/java/org/kiwix/" | ||
| commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/ ${getLibzimFiles()} ${getLibkiwixFiles()}" | ||
| commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}" |
There was a problem hiding this comment.
We don't have java subdirectory in test.
Have you forget something in your commit ? Or I missing something ?
There was a problem hiding this comment.
@mgautierfr , we are generating java subdirectory in test via buildHeaders, Because we are generating the test source jar from .class files, which we are using in our test cases.
There was a problem hiding this comment.
Ok.
It would be better to not generate things in source directory. Everything should be generated in the build directory.
There was a problem hiding this comment.
Since we are compile test.java file we required java sources in the same directory , I tried from build but its importing.
There was a problem hiding this comment.
When you are building the kiwix-android application, you don't need the java sources of the wrapper.
Why do you need the source of the wrapper when you build the test application ?
|
|
@kelson42 , I have changed in the CI. but |
Currently linux libzim tar file containing 0 byte .so file, so for now we are changing the libzim linux tar file url. Once this issue is fixed we will remove this temporary url.
This method is for building headers files, so for the better naming of this method we have renamed this as buildHeaders.
To avoid recompiling the source in test cases. Now we are generating .so file while building the .aar file. For this we have created buildLinuxBinding task which dependsOn build target. As now test/CMakeList is unused so we have removed it.
Earlier in gradle, There are so many tasks for copying headers and .so files of libzim, libkiwix. Now, we are copying everything in copyLibzimHeaderAndSoFiles, copyLibkiwixHeaderAndSoFiles tasks.
We are compiling and running test cases via gradle task and removing compile_and_run_test.sh as it is only for running test cases.
Earlier we are depending on the date variable to copy headers and .so files from folder. Now we introduce removeDateFromFolderName method for removing the date from folders name, so it would be more easy to getting files from folder.
Earlier we are using the java commands to compile and run test cases, Now we are using gradle for building and running test cases.
6eede1e to
fea35c2
Compare
this changes has being done. |
|
@mgautierfr any update? |
Fixes #31
In this PR we are avoiding to regenerate source files in test cases instead of this now we are generating the
.sofile when we are building the.aarfile for android.buildLinuxSoFile,buildtask dependsOnbuildLinuxSoFile(which means firstbuildLinuxSoFileexecutes and after thatbuildtask executes) .buildLinuxSoFilegenerates thelinux .sofile (inbuilddirectory), which we are using in test cases.lib/src/main/cpp/CMakeLists.txtfile for this , Here we have placed a condition, If it's linux target then it will generate the.sofile (in build directory), If we will use the./gradlew buildcommand then it will generate the.aarfile for android.CMakeListfile because now it's unused.We have removed the
copyBuildKiwixSoFilegradle task because now we are directly generating the.sofile in build directory.We have rename the
generateHeaderFilesFromJavaWrappermethod togenerateHeadersfor better readability as mention on ticket.Important Note
For now i have changed the linux .so file url (to test our new changes) https://download.openzim.org/nightly/2023-03-20/libzim_linux-x86_64-2023-03-20.tar.gz ,Because now Linux libzim tar file containing 0 byte .so file openzim/libzim#772 , Once this issue is fixed we will remove this added url .