@@ -336,7 +336,7 @@ static void discoverCrosssImportOverlayDependencies(
336336template <typename T>
337337void writeJSONSingleField (llvm::raw_ostream &out, StringRef fieldName,
338338 const T &value, unsigned indentLevel,
339- bool trailingComma);
339+ bool trailingComma, bool nested = false );
340340
341341// / Write a string value as JSON.
342342void writeJSONValue (llvm::raw_ostream &out, StringRef value,
@@ -442,11 +442,31 @@ void writeJSONValue(llvm::raw_ostream &out, const std::vector<T> &values,
442442template <typename T>
443443void writeJSONSingleField (llvm::raw_ostream &out, StringRef fieldName,
444444 const T &value, unsigned indentLevel,
445- bool trailingComma) {
445+ bool trailingComma, bool nested ) {
446446 out.indent (indentLevel * 2 );
447447 writeJSONValue (out, fieldName, indentLevel);
448448 out << " : " ;
449- writeJSONValue (out, value, indentLevel);
449+ auto updatedIndentLevel = indentLevel;
450+
451+ if (nested) {
452+ // This is a hack to "fix" a format for a value that should be a nested
453+ // set of strings. Currently only capturedPCMArgs (clang) is expected to
454+ // in the nested format, which supposedly only contains one set of strings.
455+ // Adjust the indentation to account for the nested brackets.
456+ updatedIndentLevel += 1 ;
457+ out << " [\n " ;
458+ out.indent (updatedIndentLevel * 2 );
459+ }
460+
461+ writeJSONValue (out, value, updatedIndentLevel);
462+
463+ if (nested) {
464+ // If nested, add an extra closing brack with a correct indentation.
465+ out << " \n " ;
466+ out.indent (indentLevel * 2 );
467+ out << " ]" ;
468+ }
469+
450470 if (trailingComma)
451471 out << " ," ;
452472 out << " \n " ;
@@ -720,7 +740,7 @@ static void writeJSON(llvm::raw_ostream &out,
720740
721741 // Captured PCM arguments.
722742 writeJSONSingleField (out, " capturedPCMArgs" , clangDeps->captured_pcm_args , 5 ,
723- /* trailingComma=*/ false );
743+ /* trailingComma=*/ false , /* nested= */ true );
724744 }
725745
726746 out.indent (4 * 2 );
0 commit comments