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

Fix javacppBuildParser default value set issue #12

Merged
merged 2 commits into from
May 5, 2021
Merged

Fix javacppBuildParser default value set issue #12

merged 2 commits into from
May 5, 2021

Conversation

devjeonghwan
Copy link
Member

@devjeonghwan devjeonghwan commented May 4, 2021

I think there is a problem in 'gradle-javacpp' plugin.

I used this plugin to multi gradle project(a.k.a sub project). like below structure.

rootproject/build.gradle
rootproject/settings.gradle
rootproject/subproject_1/build.gradle
rootproject/subproject_1/src/main/cpp
rootproject/subproject_1/src/main/java

rootproject/build.gradle

plugins {
    id 'org.bytedeco.gradle-javacpp-build' version '1.5.5'
}
...
subprojects { subproject ->
    apply plugin: 'org.bytedeco.gradle-javacpp-build'

    // This code can be more simpler like "javacppBuildParser { ... }".
    tasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {
        if (it.name.equals("javacppBuildParser")) {
            System.out.println("rootproject build.gradle set output directory changed to '$buildDir/generated/sources/javacpp'")
            outputDirectory(file("$buildDir/generated/sources/javacpp"))
        }
    }
}

rootproject/settings.gradle

rootProject.name = "rootproject"
include 'subproject_1'

rootproject/subproject_1/build.gradle

...
javacppBuildParser {
    System.out.println("subproject_1 build.gradle set output directory changed to '$buildDir/generated/sources/javacpp'")
    outputDirectory(file("$buildDir/generated/sources/javacpp"))
}
...

And i execute 'javacppBuildParser' task. it works fine.

> Configure project :subproject_1
rootproject build.gradle set output directory changed to 'rootproject/subproject_1/build/generated/sources/javacpp'
subproject_1 build.gradle set output directory changed to 'rootproject/subproject_1/build/generated/sources/javacpp'
...
> Task :subproject_1:javacppBuildParser
jnijavacpp.cpp
rootproject/subproject_1/build/generated/sources/javacpp/jnijavacpp.cpp(433): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
...

(working on rootproject/subproject_1/build/generated/sources/javacpp/ directory)

But If i remove javacppBuildParser { ... } code in subproject_1/build.gradle and then I execute 'javacppBuildParser' task, working like not set outputDirectory.

> Configure project :subproject_1
rootproject build.gradle set output directory changed to 'rootproject/subproject_1/build/generated/sources/javacpp'
...
> Task :subproject_1:javacppBuildParser
jnijavacpp.cpp
rootproject/subproject_1/src/main/java/jnijavacpp.cpp(433): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
...

(working on rootproject/subproject_1/src/main/java/ directory)

I think problem is this code

Basically, root project configure execute before subproject configure.

So executed like this.

  1. root project changed subproject_1's outputDirectory
  2. BuildPlugin.java#L138 changed subproject's outputDirectory to default value.
  3. sub project doesn't change subproject's outputDirectory.

As a result, root project's work(change outputDirectory) was ignored. because overwritten in step 2.

If the "BuildPlugin.java#L138" is only for set a default value. should do null check.

Fix this issue

@saudet
Copy link
Member

saudet commented May 4, 2021

Looks good thanks! I just want to update the CHANGELOG.md file and fix the formatting though. Can you give me access to add commits to this pull request? You don't need to give me access to the whole repository, you just need to select the checkbox you should see on this page, as documented here: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork

@devjeonghwan devjeonghwan reopened this May 4, 2021
@devjeonghwan
Copy link
Member Author

devjeonghwan commented May 4, 2021

screenshot
umm... sorry, i can't see that feature. (maybe, my fork repository is organizations repo) i gave repo write permission to you.

@saudet
Copy link
Member

saudet commented May 4, 2021

Ah, I'm sorry, this looks like a known bug: isaacs/github#1681

@saudet saudet merged commit 962d358 into bytedeco:master May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants