Skip to content

Commit 2e30be2

Browse files
committed
Fixed some bugs, added tests, more debug output.
1 parent 8c37aad commit 2e30be2

17 files changed

Lines changed: 231 additions & 192 deletions

‎.travis.yml‎

Lines changed: 0 additions & 70 deletions
This file was deleted.

‎README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export CXX=clang++-9; export CC=clang-9;
5656
export CXXFLAGS="-stdlib=libc++"; export LDFLAGS="-stdlib=libc++ -fuse-ld=lld";
5757
mkdir build && cd build
5858
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../
59-
cmake --build . --parallel
59+
cmake --build .
6060
```
6161
* with ninja / msvc (in a Developer Command Prompt or after running vcvarsall.bat)
6262
``` bash
6363
mkdir build && cd build
6464
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../
65-
cmake --build . --parallel
65+
cmake --build .
6666
```
6767
* with msbuild / msvc (in a Developer Command Prompt or after running vcvarsall.bat)
6868
```bash
@@ -75,7 +75,7 @@ cmake --build . --parallel --config Debug
7575
mkdir build && cd build
7676
set PATH=%PATH%;C:\Program Files\LLVM\bin
7777
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang-cl.exe ../
78-
cmake --build . --parallel
78+
cmake --build .
7979
```
8080
See `/tests/` for examples with more modules, header units, generated headers/sources.
8181

@@ -118,4 +118,7 @@ At the moment clang-scan-deps only really supports clang, the same version that
118118

119119
The ninja extension is currently faster and better tested than the MSBuild extension.
120120

121-
Since currently the targets that generate headers are built before scanning, those targets cannot use modules.
121+
Since currently the targets that generate headers are built before scanning, those targets cannot use modules.
122+
123+
Importing modules from external pre-built libraries is not is not yet supported.
124+

‎appveyor.yml‎

Lines changed: 0 additions & 81 deletions
This file was deleted.

‎build_rules/cpp_modules-config.cmake‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function(target_cpp_modules targets)
8888
endif()
8989
endfunction()
9090

91+
# transform all the paths in 'files_var' to absolute paths
9192
function(cppm_list_transform_to_absolute_path files_var)
9293
set(files_in "${${files_var}}")
9394
set(files_out "")
@@ -99,6 +100,29 @@ function(cppm_list_transform_to_absolute_path files_var)
99100
set(${files_var} "${files_out}" PARENT_SCOPE)
100101
endfunction()
101102

103+
# make all the paths in 'files_var' relative to 'base_path' unless they're absolute paths
104+
function(cppm_list_transform_rel_paths base_path files_var)
105+
set(files_in "${${files_var}}")
106+
set(files_out "")
107+
foreach(in_path ${files_in})
108+
if(IS_ABSOLUTE "${in_path}")
109+
# generated header paths should be passed as absolute paths starting with the binary dir
110+
# but their paths in the ninja manifest ends up being relative to the binary dir
111+
if(in_path MATCHES "^${base_path}")
112+
file(RELATIVE_PATH out_path "${base_path}" "${in_path}")
113+
else()
114+
set(out_path "${in_path}")
115+
endif()
116+
else()
117+
get_filename_component(abs_path "${in_path}"
118+
ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
119+
file(RELATIVE_PATH out_path "${base_path}" "${abs_path}")
120+
endif()
121+
list(APPEND files_out "${out_path}")
122+
endforeach()
123+
set(${files_var} "${files_out}" PARENT_SCOPE)
124+
endfunction()
125+
102126
function(target_cpp_header_units target)
103127
set(headers "${ARGN}")
104128
target_sources(${target} PRIVATE "${headers}")
@@ -111,13 +135,16 @@ function(target_cpp_header_units target)
111135
set_source_files_properties("${header}" COMPILE_FLAGS "-xc++")
112136
endif()
113137
endforeach()
138+
# ninja's path lookup expects relative paths to be relative to the binary dir
139+
# related cmake issue: https://gitlab.kitware.com/cmake/cmake/issues/13894
140+
cppm_list_transform_rel_paths("${CMAKE_BINARY_DIR}" headers)
141+
#message(STATUS "header units: ${headers}")
142+
file(APPEND "${CMAKE_BINARY_DIR}/scanner_config.txt" "header_units ${target} ${headers}\n")
143+
# todo: maybe encode whether it's a header unit as bindings on the edge instead ?
114144
endif()
115145

116-
cppm_list_transform_to_absolute_path(headers)
117146
if(CMAKE_GENERATOR MATCHES "Visual Studio")
147+
cppm_list_transform_to_absolute_path(headers)
118148
set_property(TARGET ${target} PROPERTY VS_GLOBAL_CppM_Header_Units "${headers}")
119149
endif()
120-
if(CMAKE_GENERATOR MATCHES "Ninja")
121-
file(APPEND "${CMAKE_BINARY_DIR}/scanner_config.txt" "header_units ${target} ${headers}\n")
122-
endif()
123150
endfunction()

‎src/scanner/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include(FetchContent)
1111
FetchContent_Declare(
1212
ninja
1313
GIT_REPOSITORY https://github.com/stevencpp/ninja.git
14-
GIT_TAG 09721e35ea78789063d6d3539f21500694b89091
14+
GIT_TAG eb2209086bc41fb2620a7b2cda225c89426d5f17
1515
)
1616

1717
FetchContent_MakeAvailable(ninja)

‎src/scanner/lmdb_path_store.h‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ struct path_store {
164164
component_size = 0;
165165
++in;
166166
} else {
167+
#ifdef _WIN32
168+
// note: ninja doesn't do this, so things should usually work without it
169+
// but e.g the scanner can return paths with a lower/upper case
170+
// drive letter depending on the environment variables
171+
// todo: maybe fix the scanner instead, or only toupper the drive letter ?
172+
// todo: unicode ?
173+
*out++ = toupper(*in++);
174+
#else
167175
*out++ = *in++;
176+
#endif
168177
++component_size;
169178
}
170179
}
@@ -214,8 +223,12 @@ struct path_store {
214223
return itr->second;
215224
}
216225

226+
auto open_paths_db(mdb::mdb_txn<false>& txn_rw) {
227+
return txn_rw.open_db<uint32_t, std::string_view>("paths");
228+
}
229+
217230
void commit_path_changes(mdb::mdb_txn<false>& txn_rw) {
218-
auto db = txn_rw.open_db<uint32_t, std::string_view>("paths");
231+
auto db = open_paths_db(txn_rw);
219232

220233
if (id_to_normal_path_ref.empty())
221234
return;
@@ -239,7 +252,7 @@ struct path_store {
239252
}
240253

241254
void read_paths(mdb::mdb_txn<false>& txn_rw, std::string_view item_root_path) {
242-
auto db = txn_rw.open_db<uint32_t, std::string_view>("paths");
255+
auto db = open_paths_db(txn_rw);
243256

244257
normal_paths.clear();
245258
id_to_normal_path_ref.clear();
@@ -284,10 +297,14 @@ struct path_store {
284297
return normal_paths.get_alloc(id_to_normal_path_ref[file_id]);
285298
}
286299

300+
auto open_file_data_db(mdb::mdb_txn<false>& txn_rw) {
301+
return txn_rw.open_db<file_id_t, file_entry>("file_data");
302+
}
303+
287304
// note: this doesn't work if called after update_file_data
288305
template<typename idx_t, typename F>
289306
void get_file_data(mdb::mdb_txn<false>& txn_rw, const vector_map<idx_t, file_id_t>& files, F&& data_func) {
290-
auto db = txn_rw.open_db<file_id_t, file_entry>("file_data");
307+
auto db = open_file_data_db(txn_rw);
291308

292309
for (auto idx : files.indices()) {
293310
auto file_id = files[idx];
@@ -313,7 +330,7 @@ struct path_store {
313330
}
314331

315332
void commit_file_data_changes(mdb::mdb_txn<false>& txn_rw) {
316-
auto db = txn_rw.open_db<file_id_t, file_entry>("file_data");
333+
auto db = open_file_data_db(txn_rw);
317334

318335
for (auto& [file_id, entry] : new_file_data)
319336
db.put(file_id, entry);
@@ -323,6 +340,25 @@ struct path_store {
323340
commit_path_changes(txn_rw);
324341
commit_file_data_changes(txn_rw);
325342
}
343+
344+
void print_paths(mdb::mdb_txn<false>& txn_rw) {
345+
read_paths(txn_rw, "");
346+
for (auto id = file_id_t { 1 }; id < id_to_normal_path_ref.size(); ++id) {
347+
auto path = normal_paths.get_alloc(id_to_normal_path_ref[id]);
348+
fmt::print("{} - {}\n", id, path);
349+
}
350+
}
351+
352+
void print_file_data(mdb::mdb_txn<false>& txn_rw) {
353+
auto db = open_file_data_db(txn_rw);
354+
// todo:
355+
}
356+
357+
// todo: this should work with a read-only txn as well
358+
void print(mdb::mdb_txn<false>& txn_rw) {
359+
print_paths(txn_rw);
360+
print_file_data(txn_rw);
361+
}
326362
};
327363

328364
} // namespace mdb

‎src/scanner/lmdb_string_store.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ struct string_id_store
108108
db.put(id, str, mdb::flags::put::append);
109109
}
110110
}
111+
112+
// todo: this should work with a read-only txn as well
113+
void print(mdb::mdb_txn<false>& txn_rw) {
114+
auto db = open_db(txn_rw);
115+
bool first = true;
116+
for (auto&& [id, str] : db) {
117+
if (first) { first = false; continue; }
118+
// todo: get fmt to work with strong ids
119+
fmt::print("{} - {}\n", id, str);
120+
}
121+
}
111122
};
112123

113124
} // namespace mdb

‎src/scanner/multi_buffer.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ class reordered_multi_vector_buffer {
183183
template<typename SpanVisitor>
184184
void visit(SpanVisitor&& visitor) {
185185
can_add = false;
186-
if (buf.empty()) return;
186+
if (buf.empty()) {
187+
for (size_type i = {}; i != size(); ++i)
188+
visitor(i, {});
189+
return;
190+
}
187191
T* start = &buf.front();
188192
for (std::size_t i = 0; i < vecs.size() - 1; ++i) {
189193
T* end = &buf.front() + vecs[i + 1].ofs; // note: the ofs could be == buf.size()
@@ -205,11 +209,11 @@ class reordered_multi_vector_buffer {
205209
return ret;
206210
}
207211

208-
void to_vectors(/*inout: */span_map<size_type, tcb::span<T>> vecs) {
209-
if (vecs.size() < size())
212+
void to_vectors(/*inout: */span_map<size_type, tcb::span<T>> to_vecs) {
213+
if (to_vecs.size() < size())
210214
throw std::logic_error("reordered_multi_vector_buffer: size mismatch");
211215
visit([&](size_type idx, tcb::span<T> vec) {
212-
vecs[idx] = vec;
216+
to_vecs[idx] = vec;
213217
});
214218
}
215219

0 commit comments

Comments
 (0)