InterfaceStubs.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations C++ ---===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "InterfaceStubs.h"
  9. #include "CommonArgs.h"
  10. #include "clang/Driver/Compilation.h"
  11. #include "llvm/Support/Path.h"
  12. namespace clang {
  13. namespace driver {
  14. namespace tools {
  15. namespace ifstool {
  16. void Merger::ConstructJob(Compilation &C, const JobAction &JA,
  17. const InputInfo &Output, const InputInfoList &Inputs,
  18. const llvm::opt::ArgList &Args,
  19. const char *LinkingOutput) const {
  20. std::string Merger = getToolChain().GetProgramPath(getShortName());
  21. // TODO: Use IFS library directly in the future.
  22. llvm::opt::ArgStringList CmdArgs;
  23. CmdArgs.push_back("--input-format=IFS");
  24. const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);
  25. CmdArgs.push_back(WriteBin ? "--output-format=ELF" : "--output-format=IFS");
  26. CmdArgs.push_back("-o");
  27. // Normally we want to write to a side-car file ending in ".ifso" so for
  28. // example if `clang -emit-interface-stubs -shared -o libhello.so` were
  29. // invoked then we would like to get libhello.so and libhello.ifso. If the
  30. // stdout stream is given as the output file (ie `-o -`), that is the one
  31. // exception where we will just append to the same filestream as the normal
  32. // output.
  33. SmallString<128> OutputFilename(Output.getFilename());
  34. if (OutputFilename != "-") {
  35. if (Args.hasArg(options::OPT_shared))
  36. llvm::sys::path::replace_extension(OutputFilename,
  37. (WriteBin ? "ifso" : "ifs"));
  38. else
  39. OutputFilename += (WriteBin ? ".ifso" : ".ifs");
  40. }
  41. CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));
  42. // Here we append the input files. If the input files are object files, then
  43. // we look for .ifs files present in the same location as the object files.
  44. for (const auto &Input : Inputs) {
  45. if (!Input.isFilename())
  46. continue;
  47. SmallString<128> InputFilename(Input.getFilename());
  48. if (Input.getType() == types::TY_Object)
  49. llvm::sys::path::replace_extension(InputFilename, ".ifs");
  50. CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));
  51. }
  52. C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
  53. Args.MakeArgString(Merger), CmdArgs,
  54. Inputs, Output));
  55. }
  56. } // namespace ifstool
  57. } // namespace tools
  58. } // namespace driver
  59. } // namespace clang