[nnfw-cmake] StampTools module (#7595)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 18 Sep 2019 10:29:59 +0000 (19:29 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 18 Sep 2019 10:29:59 +0000 (19:29 +0900)
Extract StampTools module from ExternalSourceTools module (same with nncc)

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
infra/nnfw/cmake/modules/ExternalSourceTools.cmake
infra/nnfw/cmake/modules/StampTools.cmake [new file with mode: 0644]

index 01a0c4d..dea61e8 100644 (file)
@@ -1,4 +1,6 @@
 function(ExternalSource_Download PREFIX URL)
+  nnfw_include(StampTools)
+
   get_filename_component(FILENAME ${URL} NAME)
 
   set(CACHE_DIR "${NNFW_EXTERNALS_DIR}")
@@ -12,16 +14,12 @@ function(ExternalSource_Download PREFIX URL)
     file(MAKE_DIRECTORY "${CACHE_DIR}")
   endif(NOT EXISTS "${CACHE_DIR}")
 
+  # Compare URL in STAMP file and the given URL
+  Stamp_Check(URL_CHECK "${STAMP_PATH}" "${URL}")
+
   # TODO Check MD5 for correctness
-  set(MATCH_URL FALSE)
-  if(EXISTS "${STAMP_PATH}")
-    file(READ "${STAMP_PATH}" SAVED_URL)
-    if("${SAVED_URL}" STREQUAL "${URL}")
-      set(MATCH_URL TRUE)
-    endif("${SAVED_URL}" STREQUAL "${URL}")
-  endif(EXISTS "${STAMP_PATH}")
-
-  if(NOT EXISTS "${STAMP_PATH}" OR NOT EXISTS "${OUT_DIR}" OR NOT MATCH_URL)
+
+  if(NOT EXISTS "${OUT_DIR}" OR NOT URL_CHECK)
     file(REMOVE_RECURSE "${OUT_DIR}")
     file(REMOVE_RECURSE "${TMP_DIR}")
 
@@ -68,6 +66,8 @@ function(ExternalSource_Download PREFIX URL)
 endfunction(ExternalSource_Download)
 
 function(ExternalSource_Get PREFIX DOWNLOAD_FLAG URL)
+  nnfw_include(StampTools)
+
   set(CACHE_DIR "${NNFW_EXTERNALS_DIR}")
   set(OUT_DIR "${CACHE_DIR}/${PREFIX}")
   set(STAMP_PATH "${CACHE_DIR}/${PREFIX}.stamp")
@@ -76,18 +76,14 @@ function(ExternalSource_Get PREFIX DOWNLOAD_FLAG URL)
     file(MAKE_DIRECTORY "${CACHE_DIR}")
   endif(NOT EXISTS "${CACHE_DIR}")
 
+  # Compare URL in STAMP file and the given URL
+  Stamp_Check(URL_CHECK "${STAMP_PATH}" "${URL}")
+
   # TODO Check MD5 for correctness
-  set(MATCH_URL FALSE)
-  if(EXISTS "${STAMP_PATH}")
-    file(READ "${STAMP_PATH}" SAVED_URL)
-    if("${SAVED_URL}" STREQUAL "${URL}")
-      set(MATCH_URL TRUE)
-    endif("${SAVED_URL}" STREQUAL "${URL}")
-  endif(EXISTS "${STAMP_PATH}")
 
   set(SOURCE_GET TRUE)
 
-  if(NOT EXISTS "${STAMP_PATH}" OR NOT EXISTS "${OUT_DIR}" OR NOT MATCH_URL)
+  if(NOT EXISTS "${OUT_DIR}" OR NOT URL_CHECK)
     if(NOT DOWNLOAD_FLAG)
       set(SOURCE_GET FALSE)
     else(NOT DOWNLOAD_FLAG)
diff --git a/infra/nnfw/cmake/modules/StampTools.cmake b/infra/nnfw/cmake/modules/StampTools.cmake
new file mode 100644 (file)
index 0000000..d38e033
--- /dev/null
@@ -0,0 +1,18 @@
+# Stamp_Check(VARNAME PATH CONTENT)
+#  Stamp_Check sets VARNAME as TRUE if a file exists at "PATH", and its content is same as "CONTENT"
+#  Stamp_Check sets VARNAME as FALSE otherwise
+function(Stamp_Check VARNAME PATH EXPECTED_CONTENT)
+  if(NOT EXISTS "${PATH}")
+    set(${VARNAME} FALSE PARENT_SCOPE)
+    return()
+  endif(NOT EXISTS "${PATH}")
+
+  file(READ ${PATH} OBTAINED_CONTENT)
+
+  if(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT)
+    set(${VARNAME} FALSE PARENT_SCOPE)
+    return()
+  endif(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT)
+
+  set(${VARNAME} TRUE PARENT_SCOPE)
+endfunction(Stamp_Check)