On 2017-05-11 11:18, Jacob Carlborg wrote:

I'm trying to add a Dub file to DMD. I would like to have a test for this as well. So I've created a minimal Dub project that is using the DMD Dub package as a dependency. This is causing some problems when Dub is building DMD.

In the Dub file for DMD I have a pre generate command looking like this:

preGenerateCommands "pushd src > /dev/null && ./ddmd/idgen.d && popd > /dev/null"

idgen.d will generate the id.d file which is then imported by other modules. The Dub file for DMD is located in the root directory of the project. idgen.d will read the ddmd/id.h file, meaning that the expected working directory is src.

I have a test project located in test/dub_package with the following simple Dub file:

name "dmd-dub-test"
dependency "dmd" path="../../"

When I run dub test inside the test/dub_package directory Dub will need to compile the dependency, DMD. But when it compiles the dependency it fails because the src directory doesn't exist. The reason for that is because the working directory is still test/dub_package instead of ../../, the DMD root project directory, which is what I expected. I confirmed this by invoking pwd in preGenerateCommands in the DMD Dub file. Is this a bug or expected behavior? If it is expected behavior, is there a solution/workaround?

My changes to DMD are available here: https://github.com/jacob-carlborg/dmd/commit/d285db95da7a368d75be3ae18bce13aa13d2fa27

I solved this in a different way by modifying the idgen.d to take a path
as a command line argument. Then use $PACKAGE_DIR as the argument [1].


/Jacob Carlborg