From 19aaa7936296ae7f71cd47f0d899c6543b2629b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ba=C5=82uta?= Date: Fri, 29 Oct 2021 10:25:20 +0000 Subject: [PATCH] jam: make compile_commands.json valid JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a comma in compile_commands.json after the last entry what prevented from using file directly in some tools. Test plan: verified new compile_commands.json with "python3 -m json.tool compile_commands.json" Change-Id: I6c2582f7285a3409d95081a93f3c05b5cc9322b9 Reviewed-on: https://review.haiku-os.org/c/buildtools/+/4671 Reviewed-by: Jérôme Duval --- jam/jam.c | 2 +- jam/make1.c | 9 ++++++++- jam/patchlevel.h | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/jam/jam.c b/jam/jam.c index 8958c2bbe8..6edf54609a 100644 --- a/jam/jam.c +++ b/jam/jam.c @@ -455,7 +455,7 @@ int main( int argc, char **argv, char **arg_environ ) /* close compilation database output file */ if ( globs.comp_db ) { - fprintf(globs.comp_db, "]\n"); + fprintf(globs.comp_db, "\n]\n"); fclose( globs.comp_db ); } diff --git a/jam/make1.c b/jam/make1.c index 906b41a393..7b8ed24fe1 100644 --- a/jam/make1.c +++ b/jam/make1.c @@ -735,6 +735,9 @@ static void out_json(char const* str, FILE* f) } +static int written_compile_database_objects = 0; + + void out_compile_database ( char const * const action, @@ -750,13 +753,17 @@ void out_compile_database && (strstr(action, "Cc") != NULL || strstr(action, "C++") != NULL)) { char buffer[PATH_MAX]; + if( written_compile_database_objects++ > 0 ) + { + fputs(",\n", globs.comp_db); + } fputs("{ \"directory\": \"", globs.comp_db); out_json(getcwd(buffer, sizeof(buffer)), globs.comp_db); fputs("\", \"command\": \"", globs.comp_db); out_json(command, globs.comp_db); fputs("\", \"file\": \"", globs.comp_db); out_json(source, globs.comp_db); - fputs("\" },\n", globs.comp_db); + fputs("\" }", globs.comp_db); } } diff --git a/jam/patchlevel.h b/jam/patchlevel.h index 14e64538c6..1ffed6bc5c 100644 --- a/jam/patchlevel.h +++ b/jam/patchlevel.h @@ -1,5 +1,5 @@ /* Keep JAMVERSYM in sync with VERSION. */ /* It can be accessed as $(JAMVERSION) in the Jamfile. */ -#define VERSION "2.5-haiku-20211020" -#define JAMVERSYM "JAMVERSION=2.5-haiku-20211020" +#define VERSION "2.5-haiku-20211029" +#define JAMVERSYM "JAMVERSION=2.5-haiku-20211029"