oasis
oasis copied to clipboard
allow InternalModules to depend on flags
This feature request has been migrated from artifact #1445 on forge.ocamlcore.org. It was assigned to user100.
user19696 posted on 2014-12-18 13:54:42:
I need to change the InternalModules field of a library, depending on flags. More precisely, I have a library Foo that can interface with several other libraries Bar1, Bar2, Bar3... (through modules that depend on those other libraries, say FooBar1, FooBar2, FooBar3 that respectively add an interface to Bar1, Bar2, Bar3 to some internal structure).
Each of Bar1, Bar2, Bar3 is optional, using a flag. However, I cannot define the library foo as:
Library foo Path: src/ Modules: Foo if flag(bar1) InternalModules+: FooBar1 if flag(bar2) InternalModules+: FooBar2 if flag(bar3) InternalModules+: FooBar3
Is such a thing possible? Currently I get:
Fatal error: exception Failure("Field 'InternalModules' cannot be conditional")
user102 replied on 2014-12-18 15:22:37:
It also means that you will depends on different libraries and you will have to generate different META files ?
Having a conditional META files is somehow hard to implement and will require to rewrite the META file at compile time and hence depends on OASIS to distribute your package.
A common way to do it -- which will make the META file more natural and static:
Library foo Modules: Foo
Library bar1 Build$: flag(bar1) InternalModules: FooBar1 Path: src/bar1 BuildDepends: bar1 FindlibParent: foo
Library bar2 Build$: flag(bar2) InternalModules: FooBar2 Path: src/bar2 BuildDepends: bar2 FindlibParent: foo
Library bar3 Build$: flag(bar3) InternalModules: FooBar3 Path: src/bar3 BuildDepends: bar3 FindlibParent: foo
In this case, everything is static and should work...
In your other project you will be able to build with packages "foo.bar1", "foo.bar2" or "foo.bar3" depending on what you want.
user19696 replied on 2014-12-18 15:30:51:
I already use sub-libraries quite a bit, and it's a feature oasis truly shines at imho. However my problem is is different: I'm building a single executable, and I want to add internal modules that add features if the corresponding library is present.
user102 replied on 2014-12-18 17:29:04:
I think you may need to do it this way:
Executable baz BuildDepends: camlp4.macro if flag(bar1) NativeOpt+: -ppopt -DHAS_BAR1 ByteOpt+: -ppopt -DHAS_BAR1 if flag(bar2) NativeOpt+: -ppopt -DHAS_BAR2 ByteOpt+: -ppopt -DHAS_BAR2
and change baz.ml to use macro definition:
IFDEF HAS_BAR1 THEN let () = Bar1.init() END
IFDEF HAS_BAR2 THEN let () = Bar2.init() END
move bar1.ml and bar2.ml in the same directory as baz.ml and ocamlbuild will autodetect dependencies and include the file if needed.