Integrated New Rule Checker with the CMake Build
authorjjose <jjose@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Nov 2010 13:46:56 +0000 (13:46 +0000)
committerjjose <jjose@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Nov 2010 13:46:56 +0000 (13:46 +0000)
CMakeLists.txt
README_CMake
cmake/ALICE_CMake.cmake
cmake/FindRuleChecker.cmake

index 1a08b5dc30f13915af3940f37a7089c2d5d0d155..0653fa62f68a19a2b0d5e3f1e1af318073a432d4 100644 (file)
@@ -114,7 +114,7 @@ set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
 
 # Standard Modules
 # ------------------------------
-set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT LHC ESDCheck STAT TTherminator CORRFW DPMJET TDPMjet PWG0 PWG1 PWG2 PWG3 PWG4 TRIGGER PYTHIA8 )
+set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT LHC ESDCheck STAT TTherminator CORRFW DPMJET TDPMjet PWG0 PWG1 PWG2 PWG3 PWG4 TRIGGER PYTHIA8 TAmpt )
 
 if(THydjet)
   list(APPEND ALIROOTMODULES THydjet)
@@ -190,7 +190,7 @@ set(EXPORTFILES)
 add_custom_target(alilibs-static)
 add_custom_target(include-headers)
 add_custom_target(DA-all)
-
+add_custom_target(check-all)
 
 # Add Modules
 # ------------------------------
@@ -198,6 +198,8 @@ foreach(MODULE ${MODDIRS})
   set(${MODULE}ALIBS)
   configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
   add_custom_target(${MODULE}-all ALL)
+  add_custom_target(${MODULE}-check-all)
+  add_dependencies(check-all "${MODULE}-check-all")
   add_custom_target(${MODULE}-all-static)
   add_dependencies(alilibs-static "${MODULE}-static")
   add_subdirectory(${MODULE})
index ad517e09dbca89a3aacf20ed8c856f160e16b7cb..a4a7f6b4ccc585f283644f0aca908d7697985118 100644 (file)
@@ -42,6 +42,14 @@ eg.  make STEER-all STEER-all-static
 
 eg.    make STEERbase STEERbase-static
 
+8. The code can be checked for the ALICE coding conventions on a package or module level using the following targets. 
+
+  make check-all
+  make <Module>-check-all
+  make <Package>-check
+
+  The resulting violations will be written to the folder $ALICE_ROOT/<Module>/check/viols
+
 !IMPORTANT! - Make sure your source folder is clean. If you used the old make system to build aliroot run make clean in the source directory before you run cmake
  
 
index b75fc85658973e53d46f110dc3ff01034683b455..aff924a9a7dbd001c4b112aab5ec6a9f32b4ad5b 100644 (file)
@@ -327,7 +327,6 @@ macro(ALICE_BuildPackage)
       message(STATUS "No dictionary generated for ${PACKAGE}")  
     endif(lib)
   endif(WITHDICT)
-  
   if(PS OR PCS OR PFS)
     if(lib)
       ALICE_BuildLibrary()
@@ -335,6 +334,7 @@ macro(ALICE_BuildPackage)
       ALICE_BuildExecutable()
     endif(lib)
   endif(PS OR PCS OR PFS)
+  ALICE_CheckModule()
 
 endmacro(ALICE_BuildPackage)
 
index e56317f047458e0532bb1baa6f0b24680dfea1c5..5a170a3f84c6a41853d186158b90687d88da9a24 100644 (file)
@@ -13,14 +13,15 @@ message(STATUS "Check for Java: ${JAVA_RUNTIME}")
 set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
 if(NOT IRST_INSTALLDIR)
   if(ALICE)
-    message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/IRST")
+    message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
     set(IRST_INSTALLDIR ${ALICE}/local/ALICENewRuleChecker)
   endif(ALICE)
 endif(NOT IRST_INSTALLDIR)
 
 if(IRST_INSTALLDIR)
-  find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR})
-  find_file(RULECHECKER_RULES NAMES AliceCodingConventions.xml PATHS ${IRST_INSTALLDIR})
+  find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker)
+  find_file(RULECHECKER_RULES NAMES AliceCodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config)
+  find_file(FACTEXTRACTOR_JAR NAME FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor)
   if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
     set(RULECHECKER_FOUND TRUE)
     message(STATUS "RuleChecker found on the system")
@@ -31,3 +32,49 @@ else()
   message(STATUS "RuleChecker not found on this system")
 endif(IRST_INSTALLDIR)
 
+macro(ALICE_CheckModule)
+  if(RULECHECKER_FOUND)
+    set(CHECKDIR ${ALICE_ROOT}/${MODULE}/check)
+    set(violFiles)
+    foreach(_srcfile ${SRCS})
+      string (REGEX REPLACE "cxx$" "h" _header ${_srcfile})
+      get_filename_component(_srcname ${_srcfile} NAME)
+      string (REGEX REPLACE "cxx$" "viol" _viol ${_srcname})
+      string (REGEX REPLACE "cxx$" "cxx.xml" _srcxml ${_srcname})
+      string (REGEX REPLACE "cxx$" "h.xml" _hxml ${_srcname})
+      set(depends)
+      if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
+        list(APPEND depends ${_header})
+        add_custom_command( OUTPUT ${_viol}
+                          COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}
+                          COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}/viols
+                          COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
+                          COMMAND ${RULECHECKER_SRCML} ${_header} ${CHECKDIR}/${_hxml}
+                          COMMAND ${Java_JAVA_EXECUTABLE} -jar ${FACTEXTRACTOR_JAR} ${CHECKDIR} ${CHECKDIR}
+                          COMMAND ${Java_JAVA_EXECUTABLE} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
+                          DEPENDS ${_depends}
+                          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+        list(APPEND violFiles ${_viol})
+      else()
+        add_custom_command( OUTPUT ${_viol}
+                          COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}
+                          COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}/viols
+                          COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
+                          COMMAND ${Java_JAVA_EXECUTABLE} -jar ${FACTEXTRACTOR_JAR} ${CHECKDIR} ${CHECKDIR}
+                          COMMAND ${Java_JAVA_EXECUTABLE} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
+                          DEPENDS ${_depends}
+                          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+        list(APPEND violFiles ${_viol})
+      endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
+      endforeach(_srcfile ${SRCS})
+    if(violFiles)
+      add_custom_target(${PACKAGE}-check DEPENDS ${violFiles})
+      add_dependencies(${PACKAGE}-check ${violFiles})
+      add_dependencies(${MODULE}-check-all ${PACKAGE}-check)
+    endif(violFiles)
+    add_custom_command(TARGET clean
+                       COMMAND ${CMAKE_COMMAND} -E remove_directory ${CHECKDIR})
+
+  endif(RULECHECKER_FOUND)
+endmacro(ALICE_CheckModule)
+