Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2036f99

Browse files
committed
Added a linux build.
1 parent 7f04ac8 commit 2036f99

16 files changed

+355
-225
lines changed

.travis.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1+
dist: bionic
12
language: cpp
2-
os: windows
3-
3+
compiler:
4+
- clang
5+
before_install:
6+
- wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
7+
- sudo add-apt-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' -y
8+
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add -
9+
- sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' -y
10+
- sudo apt-get update -q
11+
- sudo apt-get install -y
12+
cmake ninja-build
13+
clang-9 lld-9 libc++-9-dev libc++abi-9-dev
14+
- dpkg-query -L cmake
15+
- whereis cmake
16+
- sudo rm /usr/local/cmake
17+
- sudo rm -rf /usr/local/cmake-3.12.4
18+
- cmake --version
19+
- if [ ! -f vcpkg/vcpkg ]; then
20+
git clone https://github.com/microsoft/vcpkg.git;
21+
cd vcpkg;
22+
./bootstrap-vcpkg.sh;
23+
cat /home/travis/build/stevencpp/cpp_modules/vcpkg/toolsrc/build.rel/CMakeFiles/CMakeOutput.log;
24+
cat /home/travis/build/stevencpp/cpp_modules/vcpkg/toolsrc/build.rel/CMakeFiles/CMakeError.log;
25+
cd ..;
26+
fi
27+
- export CXX=clang++-9; export CC=clang-9;
28+
- export CXXFLAGS="-stdlib=libc++"; export LDFLAGS="-stdlib=libc++";
29+
- vcpkg/vcpkg install fmt lmdb nlohmann-json catch2 range-v3 clara reproc
30+
cache:
31+
directories:
32+
/home/travis/build/stevencpp/cpp_modules/vcpkg
433
script:
5-
- git clone https://github.com/microsoft/vcpkg.git || travis_terminate 1
6-
- cd vcpkg
7-
- ./bootstrap-vcpkg.bat || travis_terminate 1
8-
- ./vcpkg.exe install fmt:x86-windows lmdb:x86-windows nlohmann-json:x86-windows catch2:x86-windows || travis_terminate 1
9-
- cd ..
10-
- mkdir build
11-
- cd build
12-
- choco install cmake ninja || travis_terminate 1
13-
- choco upgrade llvm || travis_terminate 1
14-
- cmake .. -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake || travis_terminate 1
15-
- cmake --build . || travis_terminate 1
34+
- mkdir build;
35+
cd build;
36+
cmake -DCMAKE_TOOLCHAIN_FILE="../vcpkg/scripts/buildsystems/vcpkg.cmake"
37+
-G "Ninja" ..;
38+
ninja;

src/scanner/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.15)
33
find_package(fmt CONFIG REQUIRED)
44
find_package(nlohmann_json CONFIG REQUIRED)
55
find_package(lmdb CONFIG REQUIRED)
6+
find_package(reproc CONFIG REQUIRED)
67
#find_package(absl CONFIG REQUIRED)
78

89
#set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
@@ -32,6 +33,7 @@ target_link_libraries(cppm_scanner
3233
PRIVATE fmt::fmt
3334
PRIVATE lmdb
3435
#PRIVATE absl::flat_hash_map absl::hashtablez_sampler
36+
PRIVATE cppm_utils
3537
)
3638

3739
target_include_directories(cppm_scanner
@@ -85,5 +87,6 @@ set_property(TARGET cppm_scanner_cs PROPERTY CXX_STANDARD 17)
8587
install(TARGETS cppm_scanner_cs DESTINATION etc)
8688
install(FILES "$<TARGET_FILE:fmt::fmt>" DESTINATION etc)
8789
install(FILES "$<TARGET_FILE:lmdb>" DESTINATION etc)
90+
install(FILES "$<TARGET_FILE:reproc>" DESTINATION etc)
8891

8992
endif(MSVC)

src/scanner/lmdb_path_store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "strong_id.h"
66

7+
#include <list>
8+
79
//#include <absl/container/flat_hash_map.h>
810

911
namespace mdb {

src/scanner/lmdb_wrapper_impl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ auto to_tuple(T&& object) noexcept {
8383
}
8484
}
8585

86+
template< class T > // todo: should be standard in C++20
87+
struct type_identity {
88+
using type = T;
89+
};
90+
8691
template<typename T>
8792
struct is_string_view : std::false_type {};
8893
template <>
@@ -244,11 +249,6 @@ std::size_t get_val_size(const T& t) {
244249
}
245250
}
246251

247-
template< class T > // todo: should be standard in C++20
248-
struct type_identity {
249-
using type = T;
250-
};
251-
252252
template<typename A, typename... Ts, std::size_t... Is>
253253
decltype(auto) from_val_to_aggregate(MDB_val val, std::tuple<Ts...> tup, std::index_sequence<Is...>) {
254254
auto get_view_size_without_last = [&](auto& elem, auto idx_c) -> std::size_t {

src/scanner/nl_json_schema.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,31 @@ namespace depinfo { // todo: should be e.g nl_json_schema, but it doesn't compil
6161
// leave the default value set for the optional
6262
}
6363

64-
template<typename T>
64+
template<typename ObjT>
6565
struct RW
6666
{
6767
private:
6868
bool to_json = true;
6969
json* j = nullptr;
70-
T* t = nullptr;
70+
ObjT* obj = nullptr;
7171
public:
72-
RW(json& j, const T& t) : to_json(true), j(&j), t(const_cast<T*>(&t)) {}
73-
RW(const json& j, T& t) : to_json(false), j(const_cast<json*>(&j)), t(&t) {}
72+
RW(json& j, const ObjT& obj) : to_json(true), j(&j), obj(const_cast<ObjT*>(&obj)) {}
73+
RW(const json& j, ObjT& obj) : to_json(false), j(const_cast<json*>(&j)), obj(&obj) {}
7474

75-
T* operator->() {
76-
return t;
75+
ObjT* operator->() {
76+
return obj;
7777
}
7878

7979
void json_schema() {}
8080

81-
template<typename T, typename... Ts>
82-
void json_schema(T&& t, const char* key, Ts&&... ts) {
81+
template<typename MemberT, typename... MemberTs>
82+
void json_schema(MemberT&& member, const char* key, MemberTs&&... members) {
8383
if (to_json) {
84-
put_to(*j, key, std::forward<T>(t));
84+
put_to(*j, key, std::forward<MemberT>(member));
8585
} else {
86-
get_to(*j, key, std::forward<T>(t));
86+
get_to(*j, key, std::forward<MemberT>(member));
8787
}
88-
json_schema(std::forward<Ts>(ts)...);
88+
json_schema(std::forward<MemberTs>(members)...);
8989
}
9090
};
9191
}

src/scanner/scanner.cpp

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "strong_id.h"
1616
#include "multi_buffer.h"
1717
#include "trace.h"
18+
#include "cmd_line_utils.h"
1819

1920
namespace cppm {
2021

@@ -577,36 +578,28 @@ struct ScannerImpl {
577578
if (ood_items.empty())
578579
return data;
579580

580-
// code page 65001 is UTF-8, use that for the paths - todo: test this
581-
std::string cmd = fmt::format("chcp 65001 & \"{}\" --compilation-database=\"{}\"", tool_path, comp_db_path);
582-
FILE* cmd_out = _popen(cmd.c_str(), "r");
583-
if (!cmd_out)
584-
throw std::runtime_error("failed to execute scanner tool");
585-
586-
// todo: ideally we should send the up-to-date item information to the observer here, after scanning started
587-
588-
#if 0
589-
auto json_depformat = nlohmann::json::parse(cmd_out);
590-
fclose(cmd_out);
591-
#endif
592-
593581
//std::vector<file_table_idx_t> file_table_indexed_lookup;
594582
std::unordered_map<std::string, file_table_idx_t> file_table_lookup;
595583
std::unordered_map<std::string, module_table_idx_t> module_table_lookup;
596584

597-
auto get_file_table_idx = [&](const std::string& str) {
585+
auto get_file_table_idx = [&](std::string_view file) {
586+
// todo: use heterogeneous lookup when available
587+
auto str = (std::string)file;
598588
auto [itr, inserted] = file_table_lookup.try_emplace(str, file_table_idx_t {});
599589
if (inserted)
600590
itr->second = data.file_table_buf.add(str);
601591
return itr->second;
602592
};
603593

604-
auto get_module_table_idx = [&](const std::string& str) {
594+
auto get_module_table_idx = [&](std::string_view name) {
595+
// todo: use heterogeneous lookup when available
596+
auto str = (std::string)name;
605597
auto [itr, inserted] = module_table_lookup.try_emplace(str, module_table_idx_t {});
606598
if (inserted)
607599
itr->second = data.module_table_buf.add(str);
608600
return itr->second;
609601
};
602+
610603
#if 0
611604
auto get_file_table_idx_2 = [&](std::size_t idx, const std::string& str) {
612605
auto ft_idx = get_file_table_idx(str);
@@ -621,8 +614,22 @@ struct ScannerImpl {
621614
};
622615
#endif
623616

617+
std::unordered_map<std::string, scan_item_idx_t> item_lookup;
618+
for (auto i : items.indices()) {
619+
// note: this doesn't work if there are multiple items with the same file path
620+
item_lookup[get_rooted_path(item_root_path, items[i].path).string()] = i;
621+
}
622+
auto starts_with = [](std::string_view a, std::string_view b) {
623+
return (a.substr(0, b.size()) == b);
624+
};
625+
int nr_lines = 0;
626+
std::string current_file;
627+
scan_item_idx_t current_item_idx = {};
628+
629+
// code page 65001 is UTF-8, use that for the paths - todo: test this
630+
CmdArgs cmd { "chcp 65001 & \"{}\" --compilation-database=\"{}\"", tool_path, comp_db_path };
631+
auto ret = run_cmd_read_lines(cmd, [&](std::string_view line) {
624632
#if 0
625-
for (auto& json_depinfo : json_depformat["sources"]) {
626633
auto input_file = json_depinfo["input"];
627634
auto item_idx = scan_item_idx_t { json_depinfo["_id"].get<std::size_t>() }; // note: otherwise we need to look at the outputs
628635

@@ -636,34 +643,10 @@ struct ScannerImpl {
636643
auto src_path = json_module["source_path"].get<std::string>();
637644
item_deps_buf.add(get_file_table_idx(src_path));
638645
}
639-
}
640-
#else
641-
std::unordered_map<std::string, scan_item_idx_t> item_lookup;
642-
for (auto i : items.indices()) {
643-
// note: this doesn't work if there are multiple items with the same file path
644-
item_lookup[get_rooted_path(item_root_path, items[i].path).string()] = i;
645-
}
646-
constexpr int buf_size = 2 * 1024 * 1024;
647-
std::string line;
648-
line.resize(buf_size);
649-
auto starts_with = [](std::string_view a, std::string_view b) {
650-
return (a.substr(0, b.size()) == b);
651-
};
652-
auto subview = [](const std::string& str, std::size_t ofs) {
653-
std::string_view ret { str };
654-
ret.remove_prefix(ofs);
655-
return ret;
656-
};
657-
int nr_lines = 0;
658-
std::string current_file;
659-
scan_item_idx_t current_item_idx = {};
660-
while (fgets(&line[0], buf_size, cmd_out) != NULL) {
646+
#endif
647+
661648
// skip the first line: active code page ..
662-
if (nr_lines++ == 0) continue;
663-
auto sz = line.find_first_of("\n\r", 0, 3); // include null terminator in the search
664-
if (sz == std::string::npos)
665-
break;
666-
line.resize(sz);
649+
if (nr_lines++ == 0) return true;
667650
//fmt::print("{}\n", line);
668651
if (starts_with(line, ":::: ")) {
669652
if (current_file != "") observer->item_finished();
@@ -678,12 +661,12 @@ struct ScannerImpl {
678661
data.got_result[current_item_idx] = true;
679662
observer->results_for_item(current_item_idx, /*out_of_date=*/true);
680663
} else if (starts_with(line, ":exp ")) {
681-
auto name = subview(line, 5);
682-
data.exports[current_item_idx] = get_module_table_idx((std::string)name);
664+
auto name = line.substr(5);
665+
data.exports[current_item_idx] = get_module_table_idx(name);
683666
observer->export_module(name);
684667
} else if (starts_with(line, ":imp ")) {
685-
auto name = subview(line, 5);
686-
data.imports_buf.add(get_module_table_idx((std::string)name));
668+
auto name = line.substr(5);
669+
data.imports_buf.add(get_module_table_idx(name));
687670
observer->import_module(name);
688671
// todo: import header unit ?
689672
} else {
@@ -694,11 +677,16 @@ struct ScannerImpl {
694677
//observer->other_file_dep();
695678
}
696679
}
697-
line.resize(buf_size);
698-
}
680+
return true;
681+
}, [](std::string_view err_line) {
682+
fmt::print("ERR: {}\n", err_line);
683+
return true;
684+
});
685+
686+
if(ret != 0)
687+
throw std::runtime_error("failed to execute scanner tool");
688+
699689
if (current_file != "") observer->item_finished();
700-
fclose(cmd_out);
701-
#endif
702690

703691
return data;
704692
}

src/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ add_executable(cppm_test
2222
lmdb.cpp
2323
gen_ninja.cpp
2424
util.h
25-
util.cpp
2625
test_config.h
2726
temp_file_test.h
2827
)

src/test/gen_ninja.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "test_config.h"
66
#include "temp_file_test.h"
7-
#include "util.h"
7+
#include "cmd_line_utils.h"
88

99
namespace gen_ninja {
1010

@@ -15,7 +15,7 @@ ConfigString ninja_path { "ninja_path", "ninja", "path to the ninja executable"
1515
ConfigString scanner_tool_path { "scanner_tool_path", "../scanner/Debug/cppm_scanner_tool.exe", "path to scanner_tool.exe" };
1616

1717
void generate_compilation_database() {
18-
CmdArgs gen_cmd;
18+
cppm::CmdArgs gen_cmd;
1919
// set up the paths to ninja and the compiler toolchain
2020
if (vcvarsall_bat != "")
2121
gen_cmd.append("call \"{}\" x64 && ", vcvarsall_bat);
@@ -25,12 +25,12 @@ void generate_compilation_database() {
2525
}
2626

2727
void generate_ninja_from_compilation_database() {
28-
CmdArgs tool_gen_cmd { "{} gen_dynamic", scanner_tool_path };
28+
cppm::CmdArgs tool_gen_cmd { "{} gen_dynamic", scanner_tool_path };
2929
REQUIRE(0 == run_cmd(tool_gen_cmd));
3030
}
3131

3232
void run_ninja() {
33-
CmdArgs ninja_cmd { "{}", ninja_path };
33+
cppm::CmdArgs ninja_cmd { "{}", ninja_path };
3434
REQUIRE(0 == run_cmd(ninja_cmd));
3535
}
3636

src/test/msbuild.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <fmt/color.h>
77

88
#include "test_config.h"
9+
#include "cmd_line_utils.h"
910
#include "util.h"
1011

1112
namespace fs = std::filesystem;
@@ -67,7 +68,7 @@ void run_one(const std::string& test, const run_one_params& p = {}) {
6768

6869
fmt::print(fmt::fg(fmt::color::yellow), "=== running {} ===\n", test);
6970

70-
CmdArgs generate_cmd { "cmake -G \"{}\" -A \"{}\" ", p.generator, p.arch };
71+
cppm::CmdArgs generate_cmd { "cmake -G \"{}\" -A \"{}\" ", p.generator, p.arch };
7172
if(p.toolset != "")
7273
generate_cmd.append("-DCMAKE_GENERATOR_TOOLSET={} ", p.toolset);
7374
generate_cmd.append("../");
@@ -79,7 +80,7 @@ void run_one(const std::string& test, const run_one_params& p = {}) {
7980
std::string verbosity_long = "minimal";
8081
if (p.verbosity == "d") verbosity_long = "diagnostic";
8182
auto log_params = fmt::format("LogFile=build.log;Verbosity={}", verbosity_long);
82-
CmdArgs build_cmd { "cmake --build . --config {} --parallel -- -v:{} \"/p:{}\" -flp:{}",
83+
cppm::CmdArgs build_cmd { "cmake --build . --config {} --parallel -- -v:{} \"/p:{}\" -flp:{}",
8384
p.configuration, p.verbosity, build_params, log_params };
8485
REQUIRE(0 == run_cmd(build_cmd));
8586

src/test/scanner_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ struct TempFileScanTest : public TempFileTest {
238238

239239
void canonicalize(opt_db_vec& result_opt, opt_db_vec& expected_opt) {
240240
for (auto& file : result_opt.value())
241-
file = std::filesystem::canonical(std::get<std::string>(file)).string();
241+
file = fs::canonical(std::get<std::string>(file)).string();
242242
for (auto& file : expected_opt.value())
243-
file = std::filesystem::canonical(tmp_path / std::get<std::string>(file)).string();
243+
file = fs::canonical(tmp_path / std::get<std::string>(file)).string();
244244
}
245245

246246
template<typename T>
@@ -317,7 +317,7 @@ struct TempFileScanTest : public TempFileTest {
317317
}
318318

319319
void touch(const char* file_name) {
320-
std::filesystem::last_write_time(tmp_path / file_name, std::filesystem::file_time_type::clock::now());
320+
fs::last_write_time(tmp_path / file_name, fs::file_time_type::clock::now());
321321
}
322322
};
323323

0 commit comments

Comments
 (0)