Skip to content

Commit 6127ec8

Browse files
committed
Generate minidump on crashes. Fix some current_path issue. Add print-cpp2 call.
1 parent 38cca3a commit 6127ec8

16 files changed

Lines changed: 517 additions & 41 deletions

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ set(common_src ${common_src}
9393
add_library(common ${common_src})
9494

9595
target_compile_definitions(common
96-
PRIVATE -DVERSION_MAJOR=${VERSION_MAJOR}
97-
PRIVATE -DVERSION_MINOR=${VERSION_MINOR}
98-
PRIVATE -DVERSION_PATCH=${VERSION_PATCH}
96+
PUBLIC -DVERSION_MAJOR=${VERSION_MAJOR}
97+
PUBLIC -DVERSION_MINOR=${VERSION_MINOR}
98+
PUBLIC -DVERSION_PATCH=${VERSION_PATCH}
9999
)
100100
target_include_directories(common
101101
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/common

src/client/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ target_link_libraries(client common
1616
if (UNIX AND NOT APPLE)
1717
target_link_libraries(client -static-libstdc++ -static-libgcc)
1818
endif()
19+
if (WIN32)
20+
target_link_libraries(client dbghelp)
21+
endif()
1922

2023
if (CPPAN_TEST)
2124
add_custom_command(TARGET client POST_BUILD

src/client/build.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
#include <cppan_string.h>
2020
#include <filesystem.h>
2121

22-
int build(path fn = fs::current_path(), const String &config = String());
22+
int build(path fn = ::current_path(), const String &config = String());
2323
int build_only(path fn, const String &config = String());
2424
int build_package(const String &target_name, const path &settings_fn = path(), const String &config = String());

src/client/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void command_init(const Strings &args)
100100
String project_type = "e";
101101
String idir;
102102
Project p;
103-
p.name = fs::current_path().filename().string();
103+
p.name = ::current_path().filename().string();
104104

105105
// interactive mode
106106
if (args.empty())
@@ -216,7 +216,7 @@ void command_init(const Strings &args)
216216
}
217217

218218
boost::system::error_code ec;
219-
auto root = fs::current_path();
219+
auto root = ::current_path();
220220

221221
static const auto err_exist = "File or dir with such name already exist";
222222
static const auto int_main = "int main(int argc, char **argv)\n{\n return 0;\n}\n"s;

src/client/main.cpp

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
#include <iostream>
4343
#include <thread>
4444

45+
#ifdef _WIN32
46+
#include <dbghelp.h>
47+
#include <shellapi.h>
48+
#include <shlobj.h>
49+
#include <Strsafe.h>
50+
#endif
51+
4552
#include <primitives/log.h>
4653
DECLARE_STATIC_LOGGER(logger, "main");
4754

@@ -324,6 +331,14 @@ try
324331
std::cout << c.getDefaultProject().print_cpp();
325332
return 0;
326333
}
334+
if (options().count("print-cpp2"))
335+
{
336+
auto pkg = extractFromString(options["print-cpp2"].as<String>());
337+
Config c(pkg.getDirSrc());
338+
c.getDefaultProject().pkg = pkg;
339+
std::cout << c.getDefaultProject().print_cpp2();
340+
return 0;
341+
}
327342

328343
Settings::get_user_settings().force_server_query = options()[SERVER_QUERY].as<bool>();
329344

@@ -382,7 +397,7 @@ try
382397
Config c;
383398
c.load_current_config();
384399
Projects &projects = c.getProjects();
385-
const auto cwd = fs::current_path();
400+
const auto cwd = ::current_path();
386401
for (auto &ps : projects)
387402
{
388403
auto &project = ps.second;
@@ -392,7 +407,7 @@ try
392407
{
393408
p = t / fs::unique_path();
394409
fs::create_directories(p);
395-
fs::current_path(p);
410+
::current_path(p);
396411

397412
if (!isValidSourceUrl(project.source))
398413
throw std::runtime_error("Source is empty");
@@ -404,7 +419,7 @@ try
404419
{
405420
if (par)
406421
{
407-
fs::current_path(cwd);
422+
::current_path(cwd);
408423
remove_all_from_dir(p);
409424
}
410425
};
@@ -433,16 +448,65 @@ catch (...)
433448
return 1;
434449
}
435450

451+
#ifdef _WIN32
452+
int GenerateDump(EXCEPTION_POINTERS* pExceptionPointers)
453+
{
454+
BOOL bMiniDumpSuccessful;
455+
WCHAR szPath[MAX_PATH];
456+
WCHAR szFileName[MAX_PATH];
457+
WCHAR* szAppName = L"cppan\\dump";
458+
DWORD dwBufferSize = MAX_PATH;
459+
HANDLE hDumpFile;
460+
SYSTEMTIME stLocalTime;
461+
MINIDUMP_EXCEPTION_INFORMATION ExpParam;
462+
463+
GetLocalTime(&stLocalTime);
464+
GetTempPath(dwBufferSize, szPath);
465+
466+
StringCchPrintf(szFileName, MAX_PATH, L"%s%s", szPath, szAppName);
467+
CreateDirectory(szFileName, NULL);
468+
469+
StringCchPrintf(szFileName, MAX_PATH, L"%s%s\\%d.%d.%d-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp",
470+
szPath, szAppName, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH,
471+
stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay,
472+
stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond,
473+
GetCurrentProcessId(), GetCurrentThreadId());
474+
hDumpFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE,
475+
FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
476+
477+
ExpParam.ThreadId = GetCurrentThreadId();
478+
ExpParam.ExceptionPointers = pExceptionPointers;
479+
ExpParam.ClientPointers = TRUE;
480+
481+
bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
482+
hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL);
483+
484+
return EXCEPTION_EXECUTE_HANDLER;
485+
}
486+
#endif
487+
436488
int main(int argc, char *argv[])
437489
{
438-
auto r = main1(argc, argv);
439-
return r;
490+
#ifndef _WIN32
491+
auto r = main1(argc, argv);
492+
return r;
493+
#else
494+
__try
495+
{
496+
auto r = main1(argc, argv);
497+
return r;
498+
}
499+
__except (GenerateDump(GetExceptionInformation()))
500+
{
501+
return 1;
502+
}
503+
#endif
440504
}
441505

442506
void check_spec_file()
443507
{
444508
// no config - cannot do anything more
445-
if (!fs::exists(CPPAN_FILENAME))
509+
if (!fs::exists(::current_path() / CPPAN_FILENAME))
446510
throw std::runtime_error("No spec file found");
447511
}
448512

src/client/options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ProgramOptions::ProgramOptions()
5757
("beautify", po::value<String>(), "beautify yaml script")
5858
("beautify-strict", po::value<String>(), "convert to strict cppan config")
5959
("print-cpp", po::value<String>(), "print config's values in cpp style")
60+
("print-cpp2", po::value<String>(), "print config's values in cpp style 2")
6061
;
6162

6263
// i - internal options

src/common/config.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ DECLARE_STATIC_LOGGER(logger, "config");
3838
Config::Config()
3939
{
4040
addDefaultProject();
41+
dir = ::current_path();
4142
}
4243

4344
Config::Config(const path &p)
@@ -51,20 +52,21 @@ void Config::reload(const path &p)
5152
if (fs::is_directory(p))
5253
{
5354
dir = p;
54-
ScopedCurrentPath cp(p);
55+
ScopedCurrentPath cp(dir);
5556
load_current_config();
5657
}
5758
else
5859
{
5960
dir = p.parent_path();
61+
ScopedCurrentPath cp(dir);
6062
load(p);
6163
}
6264
}
6365

6466
void Config::addDefaultProject()
6567
{
6668
Project p{ ProjectPath() };
67-
p.load(yaml());
69+
p.load(yaml());
6870
p.pkg = pkg;
6971
projects.clear();
7072
projects.emplace("", p);

src/common/package_store.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,11 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
543543
auto f = e.push([&c, &p, &cpp_fn, &ppath]()
544544
{
545545
auto &project = c.getDefaultProject();
546-
auto root_directory = (fs::is_regular_file(p) ? p.parent_path() : p) / project.root_directory;
546+
auto root_directory = fs::is_regular_file(p) ? p.parent_path() : p;
547+
if (project.root_directory.is_absolute())
548+
root_directory = project.root_directory;
549+
else
550+
root_directory /= project.root_directory;
547551

548552
// sources
549553
if (!cpp_fn.empty() && !project.files_loaded)
@@ -556,7 +560,8 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
556560
LOG_INFO(logger, "Finding sources for " + project.pkg.ppath.slice(2).toString());
557561
project.findSources(root_directory);
558562
// maybe remove? let user see cppan.yml in local project
559-
project.files.erase(CPPAN_FILENAME);
563+
project.files.erase(::current_path() / CPPAN_FILENAME);
564+
project.files.erase(CPPAN_FILENAME);
560565
// patch if any
561566
project.patchSources();
562567

0 commit comments

Comments
 (0)