Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use environment variables or tilde in module.modulemap?

My module.modulemap file looks like this:

module CompanyInternalSDK {
    header "~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
    export *
}

However, I get this error:

/Users/username/Path/To/Project/CompanyInternalSDK/module.modulemap:2:12: error: header '~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h' not found
    header "~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
           ^

It compiles just fine when I use the absolute path without the tilde, but since this will be distributed like this to all developers, I want to use the tilde. Is there any way to make this work correctly?


I also tried to use an environment variable in the header string, but that didn't work either:

module CompanyInternalSDK {
    header "${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
    export *
}
/Users/username/Path/To/Project/CompanyInternalSDK/module.modulemap:2:12: error: header '${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h' not found
    header "${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
           ^
like image 455
Ky. Avatar asked May 01 '17 18:05

Ky.


1 Answers

No, the modulemap syntax does not expand tildes or environment variables. It ultimately just expects to stat the path you gave it, and if no file's there, it'll gripe.

  • Here's where the header file lookup is kicked off, during lexing of the module map file.
  • It ultimately passes the path to the SourceManager's FileManager to produce a File object, as here for a header in a framework's Headers/ public header folder.
  • getFile ultimately ends up calling out to getStatValue, which does a cache lookup.
  • The FileSystemStatCache::get eventually grounds out in LLVM's filesystem abstraction, where it calls sys::fs::status, which is documented to act like POSIX stat.
  • POSIX stat works with paths as-is, no tilde or environment variable expansion - the common availability of those is due to the shell helping you out, not something that happens automatically most of the time at the system level.

However, it's standard to use relative paths in module maps. The lexer respects this, and all the module map docs demonstrate this. In the common case where your module map file is colocated with your library and installed alongside it, this should suffice to properly resolve the paths.

like image 112
Jeremy W. Sherman Avatar answered Oct 12 '22 19:10

Jeremy W. Sherman