Skip to content

Commit

Permalink
[CMake] Adds support for node mode with flag CLAVA_NODE
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobispo committed Nov 21, 2024
1 parent 8d5c16f commit b9966d2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMake/ClavaConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ find_package(Java COMPONENTS Runtime REQUIRED)
set(CLAVA_CMAKE_HOME ${CMAKE_CURRENT_LIST_DIR})
message(STATUS "Clava home: ${CLAVA_CMAKE_HOME}")

# Check if Node mode. If so, LOCAL_CLAVA becomes 'npx clava classic'
if(DEFINED CLAVA_NODE AND CLAVA_NODE)
message(STATUS "Enabling Clava Node mode")
set(LOCAL_CLAVA "npx clava classic")
endif()

# Check if installation file with JAR path exists
if(LOCAL_CLAVA)

Expand Down
40 changes: 40 additions & 0 deletions CMake/clava/ClavaWeave.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ function(clava_weave ORIG_TARGET ASPECT)
set(options)
set(oneValueArgs ARGS)
set(multiValueArgs FLAGS JAVA_FLAGS)

# Setup Clava Node mode, if enabled
if(DEFINED CLAVA_NODE AND CLAVA_NODE)
get_filename_component(aspectAbsolutePath "${ASPECT}" ABSOLUTE)
get_filename_component(aspectParentDir "${aspectAbsolutePath}" DIRECTORY)

# If package.json does not exist, create a default one
if(NOT EXISTS "${aspectParentDir}/package.json")
message(STATUS "Clava Node: Creating default package.json")
set(jsonContents "{\n \"type\": \"module\",\n \"dependencies\": {\n \"@specs-feup/clava\": \"^3.0.1\",\n \"@specs-feup/lara\": \"^3.0.2\"\n }\n}\n")

file(WRITE "${aspectParentDir}/package.json" "${jsonContents}")
endif()

# If node_modules does not exist, call npm install
if(NOT EXISTS "${aspectParentDir}/node_modules")
message(STATUS "Clava Node: installing node packages")

if(WIN32)
set(NPM_CMD "npm.cmd")
else()
set(NPM_CMD "npm")
endif()

execute_process(COMMAND ${NPM_CMD} install
WORKING_DIRECTORY "${aspectParentDir}"
OUTPUT_VARIABLE NPM_OUTPUT
ERROR_VARIABLE NPM_ERROR
RESULT_VARIABLE NPM_RESULT
)


if(${NPM_RESULT} STREQUAL "0")
message(STATUS "${NPM_OUTPUT}")
else()
message(STATUS "npm install error: ${NPM_ERROR}")
endif()

endif()
endif()

cmake_parse_arguments(PARSE_ARGV 2 CLAVA_WEAVE "${options}" "${oneValueArgs}" "${multiValueArgs}")

Expand Down

0 comments on commit b9966d2

Please sign in to comment.