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

apply-cpp-change-to does not work for C source files #304

Closed
carstenhag opened this issue Jan 26, 2021 · 2 comments · Fixed by #305
Closed

apply-cpp-change-to does not work for C source files #304

carstenhag opened this issue Jan 26, 2021 · 2 comments · Fixed by #305

Comments

@carstenhag
Copy link
Contributor

carstenhag commented Jan 26, 2021

I tried to use the modifier apply-cpp-change-to, this is its documentation:

apply-cpp-change-to: Add a function to a C/C++ source file. Each iteration adds a new function and removes the function added by the previous iteration.

But when I specify a scenario with for example apply-cpp-change-to = ["app/src/cpp/library.c"] and try to run it, I get this error:

* Settings
Project dir: ..
Output dir: profile-out-16
Profiler: none
Benchmark: true
Versions: []
Gradle User Home: gradle-user-home
Targets: [incremental_abi_change]
java.lang.RuntimeException: Could not create instance of mutator ApplyChangeToNativeSourceFileMutator
        at org.gradle.profiler.mutations.FileChangeMutatorConfigurator.getBuildMutatorForFile(FileChangeMutatorConfigurator.java:42)
        at org.gradle.profiler.mutations.FileChangeMutatorConfigurator.configure(FileChangeMutatorConfigurator.java:27)
        at org.gradle.profiler.ScenarioLoader.lambda$loadScenarios$2(ScenarioLoader.java:216)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at org.gradle.profiler.ScenarioLoader.loadScenarios(ScenarioLoader.java:218)
        at org.gradle.profiler.ScenarioLoader.doLoadScenarios(ScenarioLoader.java:156)
        at org.gradle.profiler.ScenarioLoader.loadScenarios(ScenarioLoader.java:137)
        at org.gradle.profiler.Main.run(Main.java:49)
        at org.gradle.profiler.Main.main(Main.java:18)
Caused by: java.lang.IllegalArgumentException: Can only modify C++ source or header files
        at org.gradle.profiler.mutations.ApplyChangeToNativeSourceFileMutator.<init>(ApplyChangeToNativeSourceFileMutator.java:12)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at org.gradle.profiler.mutations.FileChangeMutatorConfigurator.getBuildMutatorForFile(FileChangeMutatorConfigurator.java:37)
        ... 16 more

library.c is a file in our project that's used with JNI. It looks about like this:

#include <jni.h>

JNIEXPORT jstring JNICALL
Java_de_maibornwolff_sample_data_xyz_XyzLibrary_getXyz(JNIEnv *env, jobject thiz) {
    return (*env)->  NewStringUTF(env, "sample data");
}

//... more JNIEXPORT-marked functions

I then renamed the file to .cpp and then gradle-profiler did actually mutate the file. It added int _m_386a15b3_dc61_408a_8c5e_054204298a4e_incremental_abi_change_7a762916_WARM_UP_1 () { } which is expected.

@lptr
Copy link
Member

lptr commented Jan 26, 2021

Thanks for the report. Would you be interested in contributing a PR for this?

@carstenhag
Copy link
Contributor Author

Yep, just submitted a PR :)

@wolfs wolfs closed this as completed in #305 Mar 1, 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 a pull request may close this issue.

2 participants