From 67fa1fbd74298eaffd36afd78c85d6fe221c7745 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 6 Oct 2020 13:37:39 +0800 Subject: [PATCH 1/3] cmake: read $NODE_MIRROR for Node.js mirror in case the offical Node.js https://nodejs.org/dist/ is slow or unreachable. Signed-off-by: Kefu Chai --- src/pybind/mgr/dashboard/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard/CMakeLists.txt b/src/pybind/mgr/dashboard/CMakeLists.txt index d054bea9d4e..adbc6092f02 100644 --- a/src/pybind/mgr/dashboard/CMakeLists.txt +++ b/src/pybind/mgr/dashboard/CMakeLists.txt @@ -24,17 +24,19 @@ if(WITH_SYSTEM_NPM) DEPENDS frontend/node_modules WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/pybind/mgr/dashboard/frontend ) -else() +else(WITH_SYSTEM_NPM) set(mgr-dashboard-nodeenv-dir ${CMAKE_CURRENT_BINARY_DIR}/node-env) set(nodeenv NODEENV) set(mgr-dashboard-userconfig --userconfig ${mgr-dashboard-nodeenv-dir}/.npmrc) set(virt-activate . ${mgr-dashboard-nodeenv-dir}/bin/activate) - + if(DEFINED ENV{NODE_MIRROR}) + set(node_mirror_opt "--mirror=$ENV{NODE_MIRROR}") + endif() add_custom_command( OUTPUT "${mgr-dashboard-nodeenv-dir}/bin/npm" COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python=${MGR_PYTHON_EXECUTABLE} ${mgr-dashboard-nodeenv-dir} COMMAND ${mgr-dashboard-nodeenv-dir}/bin/pip install nodeenv - COMMAND ${mgr-dashboard-nodeenv-dir}/bin/nodeenv -p --node=12.18.2 + COMMAND ${mgr-dashboard-nodeenv-dir}/bin/nodeenv ${node_mirror_opt} -p --node=12.18.2 COMMAND mkdir ${mgr-dashboard-nodeenv-dir}/.npm WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "dashboard nodeenv is being installed" @@ -49,7 +51,7 @@ else() DEPENDS frontend/node_modules mgr-dashboard-nodeenv WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/pybind/mgr/dashboard/frontend ) -endif() +endif(WITH_SYSTEM_NPM) add_npm_command( OUTPUT "${CMAKE_SOURCE_DIR}/src/pybind/mgr/dashboard/frontend/node_modules" From 13f0667e5a0128970d9025f2f59b663f6e1993cd Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 6 Oct 2020 14:14:07 +0800 Subject: [PATCH 2/3] cmake: extract add_npm_options() for better readability Signed-off-by: Kefu Chai --- src/pybind/mgr/dashboard/CMakeLists.txt | 33 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/dashboard/CMakeLists.txt b/src/pybind/mgr/dashboard/CMakeLists.txt index adbc6092f02..cb692cba752 100644 --- a/src/pybind/mgr/dashboard/CMakeLists.txt +++ b/src/pybind/mgr/dashboard/CMakeLists.txt @@ -17,6 +17,25 @@ function(add_npm_command) COMMENT ${NC_COMMENT}) endfunction(add_npm_command) +function(add_npm_options) + set(commands) + cmake_parse_arguments(NC "" "NODEENV_DIR;TARGET" "OPTION" ${ARGN}) + foreach(opt ${NC_OPTION}) + string(REPLACE "=" ";" opt ${opt}) + list(GET opt 0 key) + list(GET opt 1 value) + list(APPEND commands + COMMAND + . ${NC_NODEENV_DIR}/bin/activate && + npm config set ${key} ${value} --userconfig ${NC_NODEENV_DIR}/.npmrc && + deactivate) + endforeach() + add_custom_target(${NC_TARGET} + ${commands} + DEPENDS ${NC_NODEENV_DIR}/bin/npm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endfunction(add_npm_options) + if(WITH_SYSTEM_NPM) set(mgr-dashboard-nodeenv-dir ) set(nodeenv "") @@ -28,7 +47,6 @@ else(WITH_SYSTEM_NPM) set(mgr-dashboard-nodeenv-dir ${CMAKE_CURRENT_BINARY_DIR}/node-env) set(nodeenv NODEENV) set(mgr-dashboard-userconfig --userconfig ${mgr-dashboard-nodeenv-dir}/.npmrc) - set(virt-activate . ${mgr-dashboard-nodeenv-dir}/bin/activate) if(DEFINED ENV{NODE_MIRROR}) set(node_mirror_opt "--mirror=$ENV{NODE_MIRROR}") endif() @@ -40,13 +58,12 @@ else(WITH_SYSTEM_NPM) COMMAND mkdir ${mgr-dashboard-nodeenv-dir}/.npm WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "dashboard nodeenv is being installed" - ) - add_custom_target(mgr-dashboard-nodeenv - COMMAND ${virt-activate} && npm config set python ${MGR_PYTHON_EXECUTABLE} ${mgr-dashboard-userconfig} && deactivate - COMMAND ${virt-activate} && npm config set cache ${mgr-dashboard-nodeenv-dir}/.npm ${mgr-dashboard-userconfig} && deactivate - DEPENDS ${mgr-dashboard-nodeenv-dir}/bin/npm - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) + ) + add_npm_options( + NODEENV_DIR ${mgr-dashboard-nodeenv-dir} + TARGET mgr-dashboard-nodeenv + OPTION python=${MGR_PYTHON_EXECUTABLE} + OPTION cache=${mgr-dashboard-nodeenv-dir}/.npm) add_custom_target(mgr-dashboard-frontend-deps DEPENDS frontend/node_modules mgr-dashboard-nodeenv WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/pybind/mgr/dashboard/frontend From 9a4fe2920460eac076ec2015bd08ba38c3d27aaa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 6 Oct 2020 14:58:55 +0800 Subject: [PATCH 3/3] cmake: read $NPM_REGISTRY for npm registry mirror in case the offical npm registry is slow or unreachable. Signed-off-by: Kefu Chai --- src/pybind/mgr/dashboard/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/CMakeLists.txt b/src/pybind/mgr/dashboard/CMakeLists.txt index cb692cba752..dd6aa9f0e71 100644 --- a/src/pybind/mgr/dashboard/CMakeLists.txt +++ b/src/pybind/mgr/dashboard/CMakeLists.txt @@ -59,11 +59,15 @@ else(WITH_SYSTEM_NPM) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "dashboard nodeenv is being installed" ) + if(DEFINED ENV{NPM_REGISTRY}) + set(npm_registry_opts "OPTION" "registry=$ENV{NPM_REGISTRY}") + endif() add_npm_options( NODEENV_DIR ${mgr-dashboard-nodeenv-dir} TARGET mgr-dashboard-nodeenv OPTION python=${MGR_PYTHON_EXECUTABLE} - OPTION cache=${mgr-dashboard-nodeenv-dir}/.npm) + OPTION cache=${mgr-dashboard-nodeenv-dir}/.npm + ${npm_registry_opts}) add_custom_target(mgr-dashboard-frontend-deps DEPENDS frontend/node_modules mgr-dashboard-nodeenv WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/pybind/mgr/dashboard/frontend