File: CompilerLocatorEosCDT.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (112 lines) | stat: -rw-r--r-- 3,222 bytes parent folder | download | duplicates (2)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "CompilerLocatorEosCDT.h"

#include "file_logger.h"
#include "globals.h"

#include <algorithm>
#include <wx/filename.h>
#include <wx/thread.h>

CompilerLocatorEosCDT::CompilerLocatorEosCDT() {}

CompilerLocatorEosCDT::~CompilerLocatorEosCDT() {}

bool CompilerLocatorEosCDT::Locate()
{
    clDEBUG() << "CompilerLocatorEosCDT locate..." << endl;
    std::vector<wxString> possiblePaths{ "/usr/bin", "/usr/local/bin" };
    std::for_each(possiblePaths.begin(), possiblePaths.end(), [&](const wxString& path) {
        wxString foundPath;
        if(CheckExists(path, foundPath)) {
            m_compilers.push_back(CreateCompiler(foundPath));
        }
    });
    clDEBUG() << "CompilerLocatorEosCDT locate...done" << endl;
    return !m_compilers.empty();
}

CompilerPtr CompilerLocatorEosCDT::Locate(const wxString& folder)
{
    m_compilers.clear();
    wxString foundPath;
    if(!CheckExists(folder, foundPath)) {
        return NULL;
    }

    m_compilers.push_back(CreateCompiler(foundPath));
    return m_compilers[0];
}

void CompilerLocatorEosCDT::AddTool(CompilerPtr compiler, const wxString& toolname, const wxString& path,
                                    const wxString& args) const
{
    wxString tool = path;
    ::WrapWithQuotes(tool);
    if(!args.IsEmpty()) {
        tool << " " << args;
    }
    compiler->SetTool(toolname, tool);
}

bool CompilerLocatorEosCDT::CheckExists(const wxString& path, wxString& foundPath) const
{
    wxFileName eosio_tool(path, "eosio-cc");
    wxFileName tmpfn(path, "");
#ifdef __WXMSW__
    eosio_tool.SetExt("exe");
#endif

    bool found = eosio_tool.FileExists();
    if(!found) {
        // try to see if we have a bin folder here
        eosio_tool.AppendDir("bin");
        found = eosio_tool.FileExists();
        if(found) {
            foundPath = eosio_tool.GetPath();
        }
    } else {
        foundPath = eosio_tool.GetPath();
    }
    return found;
}

CompilerPtr CompilerLocatorEosCDT::CreateCompiler(const wxString& path) const
{

    CompilerPtr compiler(new Compiler(NULL));
    compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);

    // get the compiler version
    compiler->SetName("eosio");
    compiler->SetGenerateDependeciesFile(true);
    compiler->SetInstallationPath(path);

    // Add the tools
    wxFileName eosio_tool(path, "eosio-cc");
#ifdef __WXMSW__
    eosio_tool.SetExt("exe");
#endif
    AddTool(compiler, "CC", eosio_tool.GetFullPath());

    eosio_tool.SetName("eosio-cpp");
    AddTool(compiler, "CXX", eosio_tool.GetFullPath());
    AddTool(compiler, "LinkerName", eosio_tool.GetFullPath());
#ifdef __WXMAC__
    AddTool(compiler, "SharedObjectLinkerName", eosio_tool.GetFullPath(), "-dynamiclib -fPIC");
#else
    AddTool(compiler, "SharedObjectLinkerName", eosio_tool.GetFullPath(), "-shared -fPIC");
#endif
    eosio_tool.SetName("ar");
    AddTool(compiler, "AR", eosio_tool.GetFullPath(), "rcu");
    wxString makeExtraArgs;
    if(wxThread::GetCPUCount() > 1) {
        makeExtraArgs << "-j" << wxThread::GetCPUCount();
    }

#ifdef __WXMSW__
    AddTool(compiler, "MAKE", "mingw32-make.exe", makeExtraArgs);
#else
    AddTool(compiler, "MAKE", "make", makeExtraArgs);
#endif
    return compiler;
}