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

How to compile AIDL files using meson? #2539

Open
rom1v opened this issue Oct 27, 2017 · 12 comments
Open

How to compile AIDL files using meson? #2539

rom1v opened this issue Oct 27, 2017 · 12 comments

Comments

@rom1v
Copy link

rom1v commented Oct 27, 2017

Here are 2 aidl files.

src/com/rom1v/example/Service.aidl:

package com.rom1v.example;
interface Service {
    void doSomething();
}

src/another/package/Other.aidl:

package another.package;
interface Other {
    int get();
}

I would like to compile them using meson (and compile these generated java files along with my sources), so I started a build.meson:

project('example', 'java')

aidl = [
    'src/com/rom1v/example/Service.aidl',
    'src/another/package/Other.aidl',
]

From these sources, I want to generate:

  • MYBUILDDIR/gen/com/rom1v/example/Service.java
  • MYBUILDDIR/gen/another/package/Other.java

To generate them manually, I use these commands:

aidl -ogen src/com/rom1v/example/Service.aidl
aidl -ogen src/another/package/Other.aidl

How to do the same using Meson?

I guess generator is what I want, but I can't figure out what output value to use (it does not accept pathes, and only supports @PLAINNAME@ and @BASENAME@ as substitutions).

aidl_compiler = find_program('aidl')
gen = generator(aidl_compiler, output: ???, arguments: ['-ogen', '@INPUT@'])

ref: https://stackoverflow.com/questions/46729488/how-to-compile-aidl-files-using-meson

It seems to me that Meson assumes that all outputs may be generated in a flat directory, assumption that is false in the Java world.

@NickeZ
Copy link
Contributor

NickeZ commented Oct 27, 2017

I think you have to use either configure_file or custom_target. But using both of these means that you will have to repeat yourself a lot in the build file.. I think this is a missing feature of meson currently. I also have projects where I have to produce custom targets from pretty obscure source types and I haven't found out a clean way to do it. Especially when you have extra dependencies on your targets..

Using the generator would have been a nice abstraction if it actually was meant to be used like this.

@rom1v
Copy link
Author

rom1v commented Oct 27, 2017

I think you have to use either configure_file or custom_target.

I think that even in configure_file or custom_target, it is not possible to specify an output file which is in a subdirectory, is it?

@NickeZ
Copy link
Contributor

NickeZ commented Oct 27, 2017

Put the meson files in the same directory as the aidl files and use subdir.

@rom1v
Copy link
Author

rom1v commented Oct 30, 2017

@NickeZ I can't get it work (and my meson skills are limited). Could you create a working sample to show how it is possible to build a java program that includes the files generated from AIDL, please?

@NickeZ
Copy link
Contributor

NickeZ commented Oct 30, 2017

Below is a simple example. The meson.build files in the subdirectories are the same. See configure_file for more details on how to generate files from input files instead of capturing the stdout.

niklas @ niklas-tp : /tmp/testprj
$ tree .
.
├── build
│   ├── build.ninja
│   ├── compile_commands.json
│   ├── meson-logs
│   │   └── meson-log.txt
│   ├── meson-private
│   │   ├── build.dat
│   │   ├── coredata.dat
│   │   ├── install.dat
│   │   ├── meson_benchmark_setup.dat
│   │   └── meson_test_setup.dat
│   └── src
│       ├── another
│       │   └── package
│       │       └── file1
│       └── com
│           └── package1
│               └── file1
├── meson.build
└── src
    ├── another
    │   └── package
    │       └── meson.build
    └── com
        └── package1
            └── meson.build
13 directories, 13 files
niklas @ niklas-tp : /tmp/testprj
$ cat meson.build
project('test')
subdir('src/com/package1')
subdir('src/another/package')
niklas @ niklas-tp : /tmp/testprj
$ cat src/com/package1/meson.build
configure_file(capture:true, command: ['echo', 'test'], output: 'file1')

@rom1v
Copy link
Author

rom1v commented Oct 30, 2017

Thank you for the skeleton. I still have many thing to figure out to make it build.

But I think there is a flaw in using configure_file (which seems to be a workaround here for compiling AIDL, this is not its purpose): it's executed on "configure" (when we execute meson mybuilddir), while AIDL should be generated – and regenerated – on build only (on ninja).

What do you think?

@NickeZ
Copy link
Contributor

NickeZ commented Oct 30, 2017

Then custom_target is probably better. You use it in a similar way but the files will be created at build time.

@rom1v
Copy link
Author

rom1v commented Oct 30, 2017

If I create src/com/rom1v/example/meson.build with this content:

custom_target('sample', input: 'Service.aidl', command: [find_program('aidl'), '-o@OUTDIR@', '@INPUT@'], output: 'Service.java')

Then it generates mybuilddir/src/com/rom1v/example/com/rom1v/example/Service.java.

The problem is that aidl generates the file according to the Java package, that meson is not aware of.

So I moved the file to src/meson.build:

custom_target('sample', input: 'com/rom1v/example/Service.aidl', command: [find_program('aidl'), '-o@OUTDIR@', '@INPUT@'], output: 'Service.java')

Here, it generates in mybuilddir/src/com/rom1v/example/Service.java, but meson is not aware of the fullpath, it thinks that the output is mybuilddir/src/Service.java, so it won't correctly manage the dependencies. Cf the relevant lines in the generated build.ninja:

build src/Service.java: CUSTOM_COMMAND ../src/com/rom1v/example/Service.aidl
 COMMAND = '/home/rom/android/sdk/build-tools/26.0.2/aidl' '-osrc' '../src/com/rom1v/example/Service.aidl'

My last attempt was to set the full path of the output:

custom_target('sample', input: 'com/rom1v/example/Service.aidl', command: [find_program('aidl'), '-o@OUTDIR@', '@INPUT@'], output: 'com/rom1v/example/Service.java')

But unfortunately:

Output must not contain a path segment.

So I think meson currently cannot handle this simple case.

IMO, it would require support of hierarchy for outputs.

@NickeZ
Copy link
Contributor

NickeZ commented Oct 30, 2017

What if you don't set @outdir@ in the first example? Set -o to dot (.) Instead maybe?

@rom1v
Copy link
Author

rom1v commented Oct 30, 2017

No, that will only change the directory into which the hierarchy associated to the package will be created.

@NickeZ
Copy link
Contributor

NickeZ commented Oct 30, 2017

Alright, I agree what you need probaly can't be done today. For completeness I link to the other related issue as well: #2320

@jasonszang
Copy link

jasonszang commented Nov 1, 2017

This is quite like my protobuf problem in #2320. Protubuf also has its own way of handling directory structures and meson's way of placing meson.build in sub directories and subdir also won't help. We are on exactly the same boat.
I think these problems can only be solved by removing meson's assumption of flat generated source directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants