~lattis/muon

ref: f9a8cbad39b665a9496cd3adb4756e85ee5ec97c muon/src/external/samu.c -rw-r--r-- 868 bytes
f9a8cbadStone Tickle print stdout/stderr of failing test 8 months ago
                                                                                
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
#include "posix.h"

#include <limits.h>
#include <samu.h>
#include <unistd.h>

#include "external/samu.h"
#include "platform/filesystem.h"
#include "platform/path.h"

const bool have_samu = true;

bool
muon_samu(uint32_t argc, char *const argv[])
{
	return samu_main(argc, (char **)argv) == 0;
}

bool
muon_samu_compdb(const char *build, const char *compile_commands)
{
	int old_stdout;
	bool ret = false;

	char cwd[PATH_MAX];
	if (!path_cwd(cwd, PATH_MAX)) {
		return false;
	}

	if (!fs_redirect(compile_commands, "w", STDOUT_FILENO, &old_stdout)) {
		return false;
	}

	if (!path_chdir(build)) {
		goto ret;
	} else if (!muon_samu(4, (char *[]){ "samu", "-t", "compdb", "c_COMPILER", NULL })) {
		goto ret;
	} else if (!path_chdir(cwd)) {
		goto ret;
	}

	ret = true;
ret:
	if (!fs_redirect_restore(STDOUT_FILENO, old_stdout)) {
		return false;
	}

	return ret;
}