Skip to content

Commit

Permalink
Merge pull request #2 from dantegd/use_rapids_cmake
Browse files Browse the repository at this point in the history
Updates to get_raft and setuputils for changes for using rapids-…
  • Loading branch information
robertmaynard authored May 11, 2021
2 parents 52fb964 + 072511a commit 1158f36
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 45 deletions.
35 changes: 23 additions & 12 deletions cpp/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@
# limitations under the License.
#=============================================================================

function(find_and_configure_raft VERSION)
function(find_and_configure_raft)

rapids_cpm_find(raft ${VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET cugraph-exports
INSTALL_EXPORT_SET cugraph-exports
set(oneValueArgs VERSION FORK PINNED_TAG)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET cuml-exports
INSTALL_EXPORT_SET cuml-exports
CPM_ARGS
# GIT_REPOSITORY https://github.com/rapidsai/raft.git
# GIT_TAG branch-${VERSION}
GIT_REPOSITORY https://github.com/robertmaynard/raft.git
GIT_TAG use_rapids_cmake
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS "BUILD_TESTS OFF"

)

message(VERBOSE "CUML: Using RAFT located in ${raft_SOURCE_DIR}")

endfunction()

set(CUGRAPH_MIN_VERSION_raft "${CUGRAPH_VERSION_MAJOR}.${CUGRAPH_VERSION_MINOR}")
set(CUML_MIN_VERSION_raft "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}")

# Change pinned tag and fork here to test a commit in CI
# To use a different RAFT locally, set the CMake variable
# RPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${CUML_MIN_VERSION_raft}
FORK dantegd
PINNED_TAG 020-fea-cpm
)


find_and_configure_raft(${CUGRAPH_MIN_VERSION_raft})
5 changes: 3 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
raft_path = get_environment_option('RAFT_PATH')

# FIXME: This could clone RAFT, even if it's not needed (eg. running --clean).
raft_include_dir = use_raft_package(raft_path, libcugraph_path,
git_info_file='../cpp/CMakeLists.txt')
# deprecated: This functionality will go away after
# https://github.com/rapidsai/raft/issues/83
raft_include_dir = use_raft_package(raft_path, libcugraph_path)


class CleanCommand(Command):
Expand Down
56 changes: 25 additions & 31 deletions python/setuputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def clean_folder(path):


def use_raft_package(raft_path, cpp_build_path,
git_info_file='../cpp/cmake/Dependencies.cmake'):
git_info_file=None):
"""
Function to use the python code in RAFT in package.raft
Expand Down Expand Up @@ -139,10 +139,13 @@ def use_raft_package(raft_path, cpp_build_path,
def clone_repo_if_needed(name, cpp_build_path=None,
git_info_file=None):
if git_info_file is None:
git_info_file = _get_repo_path() + '/cpp/CMakeLists.txt'
git_info_file = \
_get_repo_path() + '/cpp/cmake/thirdparty/get_{}.cmake'.format(
name
)

if cpp_build_path is None or cpp_build_path is False:
cpp_build_path = _get_repo_path() + '/cpp/build/'
cpp_build_path = _get_repo_path() + '/cpp/build/_deps/'

repo_cloned = get_submodule_dependency(name,
cpp_build_path=cpp_build_path,
Expand All @@ -152,7 +155,7 @@ def clone_repo_if_needed(name, cpp_build_path=None,
repo_path = (
_get_repo_path() + '/python/_external_repositories/' + name + '/')
else:
repo_path = os.path.join(cpp_build_path, '_deps', name + '-src')
repo_path = os.path.join(cpp_build_path, name + '-src/')

return repo_path, repo_cloned

Expand Down Expand Up @@ -192,19 +195,19 @@ def get_submodule_dependency(repo,

repo_info = get_repo_cmake_info(repos, git_info_file)

if os.path.exists(cpp_build_path):
if os.path.exists(os.path.join(cpp_build_path, repos[0] + '-src/')):
print("-- Third party modules found succesfully in the libcugraph++ "
"build folder.")

return False

else:

warnings.warn("-- Third party repositories have not been found so they"
"will be cloned. To avoid this set the environment "
"variable CUGRAPH_BUILD_PATH, containing the relative "
"path of the root of the repository to the folder "
"where libcugraph++ was built.")
print("-- Third party repositories have not been found so they"
"will be cloned. To avoid this set the environment "
"variable CUGRAPH_BUILD_PATH, containing the relative "
"path of the root of the repository to the folder "
"where libcugraph++ was built.")

for repo in repos:
clone_repo(repo, repo_info[repo][0], repo_info[repo][1])
Expand Down Expand Up @@ -262,8 +265,8 @@ def get_repo_cmake_info(names, file_path):
`ExternalProject_Add(name`
file_path : String
Relative path of the location of the CMakeLists.txt (or the cmake
module which contains FetchContent_Declare or ExternalProject_Add
definitions) to extract the information.
module which contains ExternalProject_Add definitions) to extract
the information.
Returns
-------
Expand All @@ -272,31 +275,22 @@ def get_repo_cmake_info(names, file_path):
where results[name][0] is the url of the repo and
repo_info[repo][1] is the tag/commit hash to be cloned as
specified by cmake.
"""
with open(file_path, encoding='utf-8') as f:
with open(file_path) as f:
s = f.read()

results = {}

cmake_ext_proj_decls = ["FetchContent_Declare", "ExternalProject_Add"]

for name in names:
res = None
for decl in cmake_ext_proj_decls:
res = re.search(f'{decl}\(\s*' # noqa: W605
+ '(' + re.escape(name) + ')'
+ '\s+.*GIT_REPOSITORY\s+(\S+)\s+.+' # noqa: W605
+ '\s+.*GIT_TAG\s+(\S+)', # noqa: W605
s)
if res:
break
if res is None:
raise RuntimeError('Could not find any of the following '
f'statements: {cmake_ext_proj_decls}, for '
f'module "{name}" in file "{file_path}" with '
'GIT_REPOSITORY and GIT_TAG settings')

results[res.group(1)] = [res.group(2), res.group(3)]
repo = re.findall(r'\s.*GIT_REPOSITORY.*', s)
repo = repo[-1].split()[-1]
fork = re.findall(r'\s.*FORK.*', s)
fork = fork[-1].split()[-1]
repo = repo.replace("${PKG_FORK}", fork)
tag = re.findall(r'\s.*PINNED_TAG.*', s)
tag = tag[-1].split()[-1]
results[name] = [repo, tag]

return results

Expand Down

0 comments on commit 1158f36

Please sign in to comment.