fix an issue where two rules build the same .py files
authorZachary DeVito <zdevito@fb.com>
Fri, 14 Dec 2018 22:50:24 +0000 (14:50 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Dec 2018 22:52:52 +0000 (14:52 -0800)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15230

Differential Revision: D13471625

Pulled By: zdevito

fbshipit-source-id: a982413a308c7a9bb5b6a82fe96fd3de44f555aa

caffe2/CMakeLists.txt
cmake/Codegen.cmake

index 2b110e8..6838be9 100644 (file)
@@ -643,6 +643,11 @@ if (BUILD_PYTHON)
   file(GLOB_RECURSE PYTHON_SRCS RELATIVE ${PROJECT_SOURCE_DIR}
        "${PROJECT_SOURCE_DIR}/caffe2/*.py")
 
+  # generated pb files are copied from build/caffe2 to caffe2
+  # if we copied them back to build this would create a build cycle
+  # consider removing the need for globs
+  filter_list_exclude(PYTHON_SRCS PYTHON_SRCS "proto/.*_pb")
+
   set(build_files)
   foreach(python_src ${PYTHON_SRCS})
     add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${python_src}
index f496313..71be568 100644 (file)
@@ -20,6 +20,18 @@ function(filter_list output input)
     set(${output} ${result} PARENT_SCOPE)
 endfunction()
 
+function(filter_list_exclude output input)
+    unset(result)
+    foreach(filename ${${input}})
+        foreach(pattern ${ARGN})
+            if(NOT "${filename}" MATCHES "${pattern}")
+                list(APPEND result "${filename}")
+            endif()
+        endforeach()
+    endforeach()
+    set(${output} ${result} PARENT_SCOPE)
+endfunction()
+
 ################################################################################
 
 if (DEFINED ENV{PYTORCH_PYTHON})