mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
basic/log: add a define for path relative to source root
When using build/ directory inside of the source directory: __FILE__: ../src/test/test-log.c RELATIVE_SOURCE_PATH: .. PROJECT_FILE: src/test/test-log.c When using a build directory outside of the source directory: __FILE__: ../../../home/zbyszek/src/systemd-work/src/test/test-log.c RELATIVE_SOURCE_PATH: ../../../home/zbyszek/src/systemd-work PROJECT_FILE: src/test/test-log.c
This commit is contained in:
parent
71b7a6c47e
commit
a0b15b4177
@ -29,6 +29,10 @@ substs.set('PROJECT_VERSION', meson.project_version())
|
||||
# This is to be used instead of meson.source_root(), as the latter will return
|
||||
# the wrong result when systemd is being built as a meson subproject
|
||||
project_source_root = meson.current_source_dir()
|
||||
relative_source_path = run_command('realpath',
|
||||
'--relative-to=@0@'.format(meson.current_build_dir()),
|
||||
project_source_root).stdout().strip()
|
||||
conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
|
||||
|
||||
want_ossfuzz = get_option('oss-fuzz')
|
||||
want_libfuzzer = get_option('llvm-fuzz')
|
||||
|
@ -73,6 +73,9 @@ int log_get_max_level_realm(LogRealm realm) _pure_;
|
||||
* for the application itself.
|
||||
*/
|
||||
|
||||
assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1)
|
||||
#define PROJECT_FILE (__FILE__ + STRLEN(RELATIVE_SOURCE_PATH) + 1)
|
||||
|
||||
int log_open(void);
|
||||
void log_close(void);
|
||||
void log_forget_fds(void);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
|
||||
@ -26,6 +27,14 @@ assert_cc(!IS_SYNTHETIC_ERRNO(0));
|
||||
#define X100(x) X10(X10(x))
|
||||
#define X1000(x) X100(X10(x))
|
||||
|
||||
static void test_file(void) {
|
||||
log_info("__FILE__: %s", __FILE__);
|
||||
log_info("RELATIVE_SOURCE_PATH: %s", RELATIVE_SOURCE_PATH);
|
||||
log_info("PROJECT_FILE: %s", PROJECT_FILE);
|
||||
|
||||
assert(startswith(__FILE__, RELATIVE_SOURCE_PATH "/"));
|
||||
}
|
||||
|
||||
static void test_log_struct(void) {
|
||||
log_struct(LOG_INFO,
|
||||
"MESSAGE=Waldo PID="PID_FMT" (no errno)", getpid_cached(),
|
||||
@ -68,6 +77,8 @@ static void test_log_syntax(void) {
|
||||
int main(int argc, char* argv[]) {
|
||||
int target;
|
||||
|
||||
test_file();
|
||||
|
||||
for (target = 0; target < _LOG_TARGET_MAX; target++) {
|
||||
log_set_target(target);
|
||||
log_open();
|
||||
|
Loading…
Reference in New Issue
Block a user