Coverage Report

Created: 2020-09-15 12:33

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "InterfaceStubs.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "llvm/Support/Path.h"
13
14
namespace clang {
15
namespace driver {
16
namespace tools {
17
namespace ifstool {
18
void Merger::ConstructJob(Compilation &C, const JobAction &JA,
19
                          const InputInfo &Output, const InputInfoList &Inputs,
20
                          const llvm::opt::ArgList &Args,
21
21
                          const char *LinkingOutput) const {
22
21
  std::string Merger = getToolChain().GetProgramPath(getShortName());
23
21
  llvm::opt::ArgStringList CmdArgs;
24
21
  CmdArgs.push_back("-action");
25
21
  const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);
26
14
  CmdArgs.push_back(WriteBin ? "write-bin" : 
"write-ifs"7
);
27
21
  CmdArgs.push_back("-o");
28
21
29
  // Normally we want to write to a side-car file ending in ".ifso" so for
30
  // example if `clang -emit-interface-stubs -shared -o libhello.so` were
31
  // invoked then we would like to get libhello.so and libhello.ifso. If the
32
  // stdout stream is given as the output file (ie `-o -`), that is the one
33
  // exception where we will just append to the same filestream as the normal
34
  // output.
35
21
  SmallString<128> OutputFilename(Output.getFilename());
36
21
  if (OutputFilename != "-") {
37
10
    if (Args.hasArg(options::OPT_shared))
38
0
      llvm::sys::path::replace_extension(OutputFilename,
39
0
                                         (WriteBin ? "ifso" : "ifs"));
40
10
    else
41
10
      OutputFilename += (WriteBin ? ".ifso" : 
".ifs"0
);
42
10
  }
43
21
44
21
  CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));
45
21
46
  // Here we append the input files. If the input files are object files, then
47
  // we look for .ifs files present in the same location as the object files.
48
32
  for (const auto &Input : Inputs) {
49
32
    if (!Input.isFilename())
50
1
      continue;
51
31
    SmallString<128> InputFilename(Input.getFilename());
52
31
    if (Input.getType() == types::TY_Object)
53
3
      llvm::sys::path::replace_extension(InputFilename, ".ifs");
54
31
    CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));
55
31
  }
56
21
57
21
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
58
21
                                         Args.MakeArgString(Merger), CmdArgs,
59
21
                                         Inputs));
60
21
}
61
} // namespace ifstool
62
} // namespace tools
63
} // namespace driver
64
} // namespace clang