jam: make compile_commands.json valid JSON

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 <jerome.duval@gmail.com>
This commit is contained in:
Maciej Bałuta 2021-10-29 10:25:20 +00:00 committed by Jérôme Duval
parent 7f682463a1
commit 19aaa79362
3 changed files with 11 additions and 4 deletions

View File

@ -455,7 +455,7 @@ int main( int argc, char **argv, char **arg_environ )
/* close compilation database output file */ /* close compilation database output file */
if ( globs.comp_db ) if ( globs.comp_db )
{ {
fprintf(globs.comp_db, "]\n"); fprintf(globs.comp_db, "\n]\n");
fclose( globs.comp_db ); fclose( globs.comp_db );
} }

View File

@ -735,6 +735,9 @@ static void out_json(char const* str, FILE* f)
} }
static int written_compile_database_objects = 0;
void out_compile_database void out_compile_database
( (
char const * const action, char const * const action,
@ -750,13 +753,17 @@ void out_compile_database
&& (strstr(action, "Cc") != NULL || strstr(action, "C++") != NULL)) && (strstr(action, "Cc") != NULL || strstr(action, "C++") != NULL))
{ {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
if( written_compile_database_objects++ > 0 )
{
fputs(",\n", globs.comp_db);
}
fputs("{ \"directory\": \"", globs.comp_db); fputs("{ \"directory\": \"", globs.comp_db);
out_json(getcwd(buffer, sizeof(buffer)), globs.comp_db); out_json(getcwd(buffer, sizeof(buffer)), globs.comp_db);
fputs("\", \"command\": \"", globs.comp_db); fputs("\", \"command\": \"", globs.comp_db);
out_json(command, globs.comp_db); out_json(command, globs.comp_db);
fputs("\", \"file\": \"", globs.comp_db); fputs("\", \"file\": \"", globs.comp_db);
out_json(source, globs.comp_db); out_json(source, globs.comp_db);
fputs("\" },\n", globs.comp_db); fputs("\" }", globs.comp_db);
} }
} }

View File

@ -1,5 +1,5 @@
/* Keep JAMVERSYM in sync with VERSION. */ /* Keep JAMVERSYM in sync with VERSION. */
/* It can be accessed as $(JAMVERSION) in the Jamfile. */ /* It can be accessed as $(JAMVERSION) in the Jamfile. */
#define VERSION "2.5-haiku-20211020" #define VERSION "2.5-haiku-20211029"
#define JAMVERSYM "JAMVERSION=2.5-haiku-20211020" #define JAMVERSYM "JAMVERSION=2.5-haiku-20211029"