diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-06-24 11:43:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-06-24 11:43:45 +0200 |
commit | 1958b829f22e3b69d4c4c23662e0d1c7c4d2e62b (patch) | |
tree | fb94b1cba0d34e9b4cc6e1834495a9bd1e62a289 /build2/cc/compile.cxx | |
parent | ff8ed209cd80799199e0b2e3d37213d549bc342f (diff) |
Make VC compatible with 'export module M;' by fixing up preprocessed output
Diffstat (limited to 'build2/cc/compile.cxx')
-rw-r--r-- | build2/cc/compile.cxx | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index eddd465..9b8f31b 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -2398,7 +2398,37 @@ namespace build2 // implementation units. // if (cid == compiler_id::msvc && src.is_a (*x_mod)) - tu.mod.iface = true; + { + // It's quite painful to guard the export with an #if/#endif so + // if it is present, "fixup" the (temporary) preprocessed output + // by getting rid of the keyword. + // + // Note: when removing this also remember to remove the test. + // + if (tu.mod.iface) + { + // We can only fixup a temporary file. + // + if (!ps) + fail (relative (src)) << "fixup requires preprocessor"; + + // Stomp out the export keyword with spaces. We are using + // std::fstream since our fdstream does not yet support + // seeking. + // + fstream os (psrc.path ().string (), + fstream::out | fstream::in); + + auto pos (static_cast<fstream::pos_type> (p.export_pos)); + + if (!os.is_open () || + !os.seekp (pos) || + !os.write (" ", 6)) + fail << "unable to overwrite preprocessor output"; + } + else + tu.mod.iface = true; + } return tu; } |