Skip to content

Commit

Permalink
[CMake] Changed tensorboard.cmake to parse dependencies from Bazel fi…
Browse files Browse the repository at this point in the history
…les.
  • Loading branch information
NORTHAMERICA\vistepan committed Dec 1, 2016
1 parent f0fc6c0 commit 0dbd8ee
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 601 deletions.
87 changes: 86 additions & 1 deletion tensorflow/contrib/cmake/external/tensorboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,91 @@ function(tb_http_file)
set(tensorboard_dependencies ${tensorboard_dependencies} ${_TB_NAME} PARENT_SCOPE)
endfunction()

include(external/tensorboard_deps.cmake)
# Parse TensorBoard dependency names and URLs from Bazel's WORKSPACE file.
set(tb_dep_names)
file(STRINGS ${PROJECT_SOURCE_DIR}/../../../WORKSPACE workspace_contents)
foreach(line ${workspace_contents})
if(line MATCHES "# TENSORBOARD_BOWER_AUTOGENERATED_BELOW_THIS_LINE_DO_NOT_EDIT")
set(tb_deps_started 1)
endif()

if(NOT tb_deps_started)
continue()
endif()

if(line MATCHES "new_http_archive\\(")
set(tb_dep_is_archive 1)
continue()
elseif(line MATCHES "http_file\\(")
set(tb_dep_is_archive 0)
continue()
endif()

string(REGEX MATCH "name.*=.*\"(.*)\"" has_name ${line})
if(has_name)
set(tb_dep_name ${CMAKE_MATCH_1})
continue()
endif()

string(REGEX MATCH "url.*=.*\"(.*)\"" has_url ${line})
if(has_url)
list(APPEND tb_dep_names ${tb_dep_name})
set(${tb_dep_name}_is_archive ${tb_dep_is_archive})
set(${tb_dep_name}_url ${CMAKE_MATCH_1})
endif()
endforeach()

# Parse the files needed for each TensorBoard dependency from Bazel's bower.BUILD file.
# Due to CMAKE quirkiness, cannot use file(strings) with files that contain '[' and ']'.
file(READ ${PROJECT_SOURCE_DIR}/../../../bower.BUILD bower_build_contents)
string(REPLACE "\[" "OB" bower_build_contents "${bower_build_contents}")
string(REPLACE "\]" "CB" bower_build_contents "${bower_build_contents}")
string(REPLACE ";" "\\\\;" bower_build_contents "${bower_build_contents}")
string(REPLACE "\n" "E;" bower_build_contents "${bower_build_contents}")
foreach(line ${bower_build_contents})
string(REGEX MATCH "name.*=.*\"(.*)\"" has_name ${line})
if(has_name)
set(tb_dep_name ${CMAKE_MATCH_1})
set(${tb_dep_name}_files)
continue()
endif()

string(REGEX MATCH "srcs.*=.*\"(.*)\"CB" has_single_line_src ${line})
if(has_single_line_src)
list(APPEND ${tb_dep_name}_files ${CMAKE_MATCH_1})
continue()
endif()

if(line MATCHES "srcs.*=.*OB")
set(inside_files_def 1)
continue()
elseif(line MATCHES "CB,")
set(inside_files_def 0)
continue()
endif()

if(inside_files_def)
string(REGEX MATCH "\"(.*)\"," has_file ${line})
if(has_file)
list(APPEND ${tb_dep_name}_files ${CMAKE_MATCH_1})
endif()
endif()
endforeach()

# Generate a target for each dependency.
foreach(tb_dep_name ${tb_dep_names})
if (${tb_dep_name}_is_archive)
tb_new_http_archive(
NAME ${tb_dep_name}
URL ${${tb_dep_name}_url}
FILES ${${tb_dep_name}_files}
)
else()
tb_http_file(
NAME ${tb_dep_name}
URL ${${tb_dep_name}_url}
)
endif()
endforeach()

add_dependencies(tensorboard_copy_dependencies ${tensorboard_dependencies})
Loading

0 comments on commit 0dbd8ee

Please sign in to comment.