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

rdmd incorrectly assumes that the D compiler outputs dependency info to stdout #392

Open
Geod24 opened this issue Apr 9, 2020 · 0 comments
Labels
Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd Type.Enhancement An improvement to an existing functionality

Comments

@Geod24
Copy link
Member

Geod24 commented Apr 9, 2020

Transferred from: https://issues.dlang.org/show_bug.cgi?id=18423

User @WebDrake reported (2018-02-11 16:22:46 CET):

When rdmd invokes the D compiler to generate dependencies information, it makes a hardcoded assumption that this information gets written by the compiler to stdout. However, this assumption is not valid for all D compilers. In particular, compiler frontend messages are written out to a configurable stdmsg: dlang/dmd@dc8421f

... and this configurability is used by GDC to output such messages to stderr (reflecting GCC policy that stdout is reserved for -pipe output; see: #297 (comment)).

This means not only that rdmd will not work with more recent GDC releases, but that rdmd's assumptions about stdout are not valid in general (given the configurable stdmsg in the DMD frontend).

The gory details

The getDependencies function inside rdmd.d invokes the D compiler via the run command, passing in options (the depsGetter variable) and the name of a file to which to write the compiler output (depsFilename):

immutable depsExitCode = run(depsGetter, depsFilename);

Internally, run takes this and uses spawnProcess to invoke the D compiler:

private int run(string[] args, string output = null, bool replace = false)
{
    ...

    File outputFile;
    if (output.ptr)
        outputFile = File(output, "wb");
    else
        outputFile = stdout;
    auto process = spawnProcess(args, stdin, outputFile);
    return process.wait();
}

In other words, run opens a file whose name is given by depsFilename, and uses it to replace stdout for the spawned process. The contents of this file are then read using the nested readDepsFile() function defined internally inside getDependencies.

In consequence, if the information parsed by readDepsFile is not written to stdout by the D compiler, it will not get written into outputFile, and therefore not be available to parse.

User @WebDrake responded (2018-02-11 16:30:16 CET):

For context, this issue was observed while trying to update rdmd's integration tests to use gdmd: #307 (comment)

Marking as enhancement since things work at the moment and this is to support a new feature.

@Geod24 Geod24 added Type.Enhancement An improvement to an existing functionality Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd labels Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio.3.Normal A bug that is neither a blocker nor a regression T.RDMD Issues that apply only to rdmd Type.Enhancement An improvement to an existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant