Open rib opened 6 years ago
Actually this comes down to user error on my part, though it feels a little awkward...
Firstly, instead of using our top-level meson.build, I have a src/java/meson.build
which I created due to the restriction jar()
has that the package namespace directories for Java source code must be relative to the meson.build where jar()
is used.
Then since configure_file()
has a different restriction where the output filename can't include a subdirectory we have another meson.build file at src/java/com/impossible/glimpse/meson.build
purely to handle our use of configure_file()
to generate GlimpseConfig.java
The mistake was that I shouldn't pass the string literal 'com/impossible/glimpse/GlimpseConfig.java'
to jar()
(and I can see that it would be awkward for meson to match it up with the generated file). Instead we should do something like glimpse_config_file = configure_file(...)
in the second meson.build and then pass that variable as source to jar()
in the first meson.build.
I wonder if the restriction on configure_file
's output being in a subdirectory could be relaxed (maybe asserting that it matches the subdirectory of the input file to restrict random access to the build directory) so we could keep these related things next to each other.
Ah, no, it really doesn't work :-)
So after making the first mistake described above, and then taking a long time to realize I also needed to pass include_directories: include_directories('.')
for my code to compile (due to class interdependencies), I thought all was well because my generated code also compiled. Unfortunately that was only true until my non-generated code needed to reference the GlimpseConfig
class in the generated file.
The problem is that javac
needs to have the location for the generated com/impossible/glimpse/
hierarchy, under the build directory, added to the given -sourcepath
(./src/java
in this case). Without that then if any non-generated code tries to reference the GlimpseConfig
class then javac
won't be able to automatically compile the dependency class as part of its default -implicit:class
behaviour.
I've tested a patch to address this which I can open a pull request for.
I just tried using
configure_file()
to process aGlimpseConfig.java.in
in our project with a file like:This results in a file under our
build
directory likebuild/src/java/com/impossible/glimpse/GlimpseConfig.java
Passing
'com/impossible/glimpse/GlimpseConfig.java'
as a source file tojar()
doesn't currently work though.