File: tool.cpp

package info (click to toggle)
ldc 1%3A0.14.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 29,416 kB
  • ctags: 10,371
  • sloc: ansic: 101,656; cpp: 28,021; sh: 484; makefile: 324; asm: 274
file content (52 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//===-- tool.cpp ----------------------------------------------------------===//
//
//                         LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//

#include "driver/tool.h"
#include "mars.h"
#include "llvm/Support/Program.h"

int executeToolAndWait(const std::string &tool, std::vector<std::string> const &args, bool verbose)
{
    // Construct real argument list.
    // First entry is the tool itself, last entry must be NULL.
    std::vector<const char *> realargs;
    realargs.reserve(args.size() + 2);
    realargs.push_back(tool.c_str());
    for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
    {
        realargs.push_back((*it).c_str());
    }
    realargs.push_back(NULL);

    // Print command line if requested
    if (verbose)
    {
        // Print it
        for (size_t i = 0; i < realargs.size()-1; i++)
            fprintf(global.stdmsg, "%s ", realargs[i]);
        fprintf(global.stdmsg, "\n");
        fflush(global.stdmsg);
    }

    // Execute tool.
    std::string errstr;
#if LDC_LLVM_VER >= 304
    if (int status = llvm::sys::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr))
#else
    llvm::sys::Path toolpath(tool);
    if (int status = llvm::sys::Program::ExecuteAndWait(toolpath, &realargs[0], NULL, NULL, 0, 0, &errstr))
#endif
    {
        error(Loc(), "%s failed with status: %d", tool.c_str(), status);
        if (!errstr.empty())
            error(Loc(), "message: %s", errstr.c_str());
        return status;
    }
    return 0;
}