Add build step to verify json formatting

This will run autojson during the build to verify
that all files are formatted correctly.

Tested: Before this change build failed, after
fixing json file, it passed

Change-Id: I119cc898536a972bb7a248143b40d695f880ff2f
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 214db49..c6f7d8a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,6 +117,19 @@
     target_link_libraries (entityManagerTests ${Boost_LIBRARIES})
     target_link_libraries (entityManagerTests sdbusplus)
 
+    find_package (PythonInterp REQUIRED)
+    find_package (Git REQUIRED)
+    execute_process (COMMAND ${PYTHON_EXECUTABLE}
+                             ${CMAKE_CURRENT_SOURCE_DIR}/scripts/autojson.py
+                             ${CMAKE_CURRENT_SOURCE_DIR}/configurations)
+    execute_process (COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR}
+                             diff
+                             --quiet configurations
+                     RESULT_VARIABLE ret)
+    if (ret EQUAL "1")
+        message (FATAL_ERROR
+                     "Invalid JSON Format, Please rerun scripts/autojson.")
+    endif ()
 endif ()
 
 add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
diff --git a/configurations/NVME P4000.json b/configurations/NVME P4000.json
index a7bdda0..46ea3f5 100644
--- a/configurations/NVME P4000.json
+++ b/configurations/NVME P4000.json
@@ -49,4 +49,4 @@
         "PartNumber": "$PRODUCT_PART_NUMBER",
         "SerialNumber": "$PRODUCT_SERIAL_NUMBER"
     }
-}
+}
\ No newline at end of file
diff --git a/scripts/autojson.py b/scripts/autojson.py
index 582631d..6b14bd5 100755
--- a/scripts/autojson.py
+++ b/scripts/autojson.py
@@ -3,9 +3,18 @@
 # and attempted to be formatted alphabetically
 
 import json
+import os
 from sys import argv
 
-for file in argv[1:]:
+files = argv[1:]
+
+for file in files[:]:
+    if os.path.isdir(file):
+        files.remove(file)
+        for f in os.listdir(file):
+            files.append(os.path.join(file, f))
+
+for file in files:
     print("formatting file {}".format(file))
     with open(file) as f:
         j = json.load(f)