fixed bugs with the rule checker.
[u/mrichter/AliRoot.git] / cmake / modules / FindRuleChecker.cmake
index 94d1e62fddc3376b27b4bcdb030f882ba34d76ef..6245a3081d1c2f66c5ae4ba5feda30255507dcaa 100644 (file)
@@ -4,35 +4,38 @@
 # Finds if the RuleChecker is installed and sets the following variables:
 #
 # RULE_CHECKER_FOUND = Boolean defining if Rule Checker is available
-# RULE_CHECKER_PATH  = Path to the java class containing the ALICE Rule Checker
-# RULE_CHECKER       = Rules (defaults to ALICE rules!)
-# RULE_CHECKER_PATCH = Perl script to be executed to patch preprocessor files
-#
+# RULE_CHECKER_SRCML = PATH TO src2srcml executable
+# RULE_CHECKER_JAVA  = PATH TO java executable 
+# RULE_CHECKER_JAR   = PATH TO NewRuleChecker.jar 
+# RULE_CHECKER_RULES = Rules (defaults to ALICE rules!)
 
 # We suppose that perl and java are present and working
-
-Find_File(RULE_CHECKER_PATCH patch4alice.prl
-  /usr/local/IRST/patch ${ALICE}/local/IRST/patch /opt/IRST/patch)
-
-If(RULE_CHECKER_PATCH)
-  Set(RULE_CHECKER_FOUND YES)
-  Set(RULE_CHECKER rules.ALICE.ALICERuleChecker)
-  String(REPLACE "/patch/patch4alice.prl" "" 
-    RULE_CHECKER_PATH "${RULE_CHECKER_PATCH}")
-  
-Else(RULE_CHECKER_PATCH)
-  Set(RULE_CHECKER_FOUND NO)
+Find_Program(RULE_CHECKER_SRCML src2srcml $ENV{PATH})
+Find_Program(RULE_CHECKER_JAVA java $ENV{PATH})
+#Message(STATUS "${RULE_CHECKER_SRCML} ${RULE_CHECKER_JAVA}")
+Set(RULE_CHECKER_FOUND NO)
+If(RULE_CHECKER_SRCML AND RULE_CHECKER_JAVA)
+  Find_File(RULE_CHECKER_JAR NAMES NewRuleChecker.jar PATHS $ENV{ALICE}/local/ALICENewRuleChecker/NewRuleChecker)
+  Find_File(RULE_CHECKER_RULES AliceCodingConventions.xml $ENV{ALICE}/local/ALICENewRuleChecker/NewRuleChecker/config)
+  #Message(STATUS "${RULE_CHECKER_JAR} ${RULE_CHECKER_RULES}")
+  If(RULE_CHECKER_JAR AND RULE_CHECKER_RULES)
+    Set(RULE_CHECKER_FOUND YES)
+    Message(STATUS "RuleChecker installed on this system")
+  EndIf(RULE_CHECKER_JAR AND RULE_CHECKER_RULES)
+EndIf(RULE_CHECKER_SRCML AND RULE_CHECKER_JAVA)
+If(NOT RULE_CHECKER_FOUND)
   Message(STATUS "RuleChecker not installed on this system")
-  
-EndIf(RULE_CHECKER_PATCH)
-
+EndIf(NOT RULE_CHECKER_FOUND)
 
-#_______________________________________________________________________________
+#______________________________________________________________________________________________________________
 Function(CheckViols LIB SRCS)
 
   If(RULE_CHECKER_FOUND)
+    Set(_FactExt $ENV{ALICE}/local/ALICENewRuleChecker/FactExtractor/FactExtractor.jar)
+    Set(_RuleCheck ${RULE_CHECKER_JAR})
+
     String(REGEX MATCHALL "[^ ]*.cxx" CXXSRCS "${SRCS}")
-    
+
     Set(_checkDir "${CMAKE_CURRENT_BINARY_DIR}/check")
     
     If(NOT EXISTS ${_checkDir})
@@ -50,17 +53,48 @@ Function(CheckViols LIB SRCS)
       If(NOT EXISTS ${_checkDir}/${_checkFilePath})
        File(MAKE_DIRECTORY ${_checkDir}/${_checkFilePath})
       EndIf(NOT EXISTS ${_checkDir}/${_checkFilePath})
-      String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.viol" _violFile "${_checkFile}")
-      String(REGEX REPLACE "([^;]*).cxx" "\\1.i" _tempFile_in ${_checkFile})
-      Add_Custom_Command(
-       OUTPUT ${_violFile}
-       COMMAND ${CMAKE_CXX_COMPILER} 
-        ARGS -E ${CMAKE_CXX_FLAGS} ${_inc_dirs} -I. ${CMAKE_CURRENT_SOURCE_DIR}/${_checkFile} > ${_tempFile_in}
-       COMMAND ${RULE_CHECKER_PATCH} ARGS ${_tempFile_in}
-       COMMAND CLASSPATH=${RULE_CHECKER_PATH} java ${RULE_CHECKER} 
-        ARGS ${_tempFile_in} ${CMAKE_CURRENT_SOURCE_DIR} > ${_violFile}
-       DEPENDS ${_checkFile}
-       WORKING_DIRECTORY ${_checkDir})
+      String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.cxx.xml" _srcxml "${_checkFile}")
+      String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.h.xml"   _hdrxml "${_checkFile}")
+      String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.viol"    _violFile "${_checkFile}")
+      String(REGEX REPLACE "([^;]*).cxx" "\\1.h" _checkHead "${_checkFile}")
+      get_filename_component(_cxxFile ${_checkFile} ABSOLUTE)
+      string(REGEX REPLACE "([^;]*).cxx" "\\1.h" _hFile "${_cxxFile}")
+      if(EXISTS ${_cxxFile} AND NOT EXISTS ${_hFile})
+       Add_Custom_Command(
+         OUTPUT ${_violFile}
+         COMMAND src2srcml 
+          ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkFile} ${_srcxml}
+         COMMAND java -jar
+         ARGS ${_FactExt} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
+         COMMAND java -Xmx500m -jar ${RULE_CHECKER_JAR} 
+          ARGS ${_srcxml} ${_hdrxml} ${CMAKE_CURRENT_SOURCE_DIR}/factFile.xml ${RULE_CHECKER_RULES} > ${_violFile}
+         DEPENDS ${_checkFile}
+         WORKING_DIRECTORY ${_checkDir})
+      elseif(EXISTS ${_hFile} AND NOT EXISTS ${_cxxFile})
+       Add_Custom_Command(
+         OUTPUT ${_violFile}
+         COMMAND src2srcml 
+          ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkHead} ${_hdrxml}
+         COMMAND java -jar
+         ARGS ${_FactExt} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
+         COMMAND java -Xmx500m -jar ${RULE_CHECKER_JAR} 
+          ARGS ${_srcxml} ${_hdrxml} ${CMAKE_CURRENT_SOURCE_DIR}/factFile.xml ${RULE_CHECKER_RULES} > ${_violFile}
+         DEPENDS ${_checkHead}
+         WORKING_DIRECTORY ${_checkDir})
+      else()
+       Add_Custom_Command(
+         OUTPUT ${_violFile}
+         COMMAND src2srcml 
+          ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkFile} ${_srcxml}
+         COMMAND src2srcml 
+          ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkHead} ${_hdrxml}
+         COMMAND java -jar
+         ARGS ${_FactExt} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
+         COMMAND java -Xmx500m -jar ${RULE_CHECKER_JAR} 
+          ARGS ${_srcxml} ${_hdrxml} ${CMAKE_CURRENT_SOURCE_DIR}/factFile.xml ${RULE_CHECKER_RULES} > ${_violFile}
+         DEPENDS ${_checkFile} ${_checkHead}
+         WORKING_DIRECTORY ${_checkDir})
+      endif(EXISTS ${_cxxFile} AND NOT EXISTS ${_hFile})
       Set(VIOLS ${VIOLS} ${_violFile})
     EndForeach(_checkFile ${CXXSRCS})