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

preGenerateCommands doesn't work in dub dependency #2238

Closed
atilaneves opened this issue Apr 4, 2022 · 1 comment
Closed

preGenerateCommands doesn't work in dub dependency #2238

atilaneves opened this issue Apr 4, 2022 · 1 comment
Labels

Comments

@atilaneves
Copy link
Contributor

atilaneves commented Apr 4, 2022

When a source file to be built is generated, using preGenerateCommands works, and it gets included in the build, but not if it's a library dependency of another dub package. To reproduce:

// oops/dub.sdl
name "oops"
targetType "library"
preGenerateCommands "cd $PACKAGE_DIR/gen && dub --single gen.d"
// oops/gen/gen.d
#!/usr/bin/env dub
/+ dub.sdl:
name "gen"
targetType "executable"
+/

void main() {
    import std.file : thisExePath, write;
    import std.path : dirName, buildPath;
    const path = buildPath(thisExePath.dirName, "..", "source", "foo.d");
    write(path, "module foo;\nint answer() { return 42; }\n");
}
// oops/source/oops.d
import std.stdio;
import foo;

void stuff() {
    answer.writeln;
}
// ledep/dub.sdl
name "ledep"
dependency "oops" path="../oops"
// ledep/source/app.d
import oops;

void main() {
    stuff;
}

When trying to build "ledep", the preGenerateCommands for "oops" is run, but foo.d isn't included in the oops build, yielding a linker error about the missing symbol foo.answer.

@atilaneves atilaneves changed the title preGenerate preGenerateCommands doesn't work in dub dependency Apr 4, 2022
@WebFreak001 WebFreak001 added the bug label Apr 5, 2022
@WebFreak001
Copy link
Member

hmm the code right here should guard against that: https://github.com/dlang/dub/blob/master/source/dub/generators/generator.d#L171-L173 but it might not be properly run for dependencies

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

No branches or pull requests

2 participants