From eb960e02cd64d0a1d4229e249d472c6500eaf67e Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Wed, 27 Jun 2018 19:02:27 +0100 Subject: [PATCH] plugin: add automatic native modules detection Adds automatic detection of native modules by looking for .gyp files inside the nodejs-project modules. --- android/build.gradle | 16 ++++++++++++++++ scripts/module-postlink.js | 32 ++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 6ac672e..bac8903 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -114,6 +114,22 @@ if (shouldRebuildNativeModules==null) { } } +if (shouldRebuildNativeModules==null) { +// If build native modules preference is not set, try to find .gyp files to turn it on. + shouldRebuildNativeModules="0"; + def gyp_files_tree = fileTree( + dir: "${rootProject.projectDir}/../nodejs-assets/nodejs-project", + include: "**/*.gyp" + ); + gyp_files_tree.visit { gypFile -> + if (!gypFile.isDirectory()) { + // It's a .gyp file. + shouldRebuildNativeModules="1"; + gypFile.stopVisiting(); + } + } +} + if ("1".equals(shouldRebuildNativeModules)) { String npmCommandName = 'npm'; diff --git a/scripts/module-postlink.js b/scripts/module-postlink.js index 2dd5e01..419de92 100644 --- a/scripts/module-postlink.js +++ b/scripts/module-postlink.js @@ -186,11 +186,19 @@ if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then #nodejs-assets/BUILD_NATIVE_MODULES.txt file. NODEJS_ASSETS_DIR="$( cd "$PROJECT_DIR" && cd ../nodejs-assets/ && pwd )" PREFERENCE_FILE_PATH="$NODEJS_ASSETS_DIR/BUILD_NATIVE_MODULES.txt" -if [ -f "$PREFERENCE_FILE_PATH" ]; then - NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)" -else - NODEJS_MOBILE_BUILD_NATIVE_MODULES=0 + if [ -f "$PREFERENCE_FILE_PATH" ]; then + NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)" + fi fi +if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then +# If build native modules preference is not set, try to find .gyp files +#to turn it on. + gypfiles=($(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.gyp")) + if [ \${#gypfiles[@]} -gt 0 ]; then + NODEJS_MOBILE_BUILD_NATIVE_MODULES=1 + else + NODEJS_MOBILE_BUILD_NATIVE_MODULES=0 + fi fi if [ "1" != "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then exit 0; fi # Delete object files that may already come from within the npm package. @@ -247,11 +255,19 @@ if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then #nodejs-assets/BUILD_NATIVE_MODULES.txt file. NODEJS_ASSETS_DIR="$( cd "$PROJECT_DIR" && cd ../nodejs-assets/ && pwd )" PREFERENCE_FILE_PATH="$NODEJS_ASSETS_DIR/BUILD_NATIVE_MODULES.txt" -if [ -f "$PREFERENCE_FILE_PATH" ]; then - NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)" -else - NODEJS_MOBILE_BUILD_NATIVE_MODULES=0 + if [ -f "$PREFERENCE_FILE_PATH" ]; then + NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)" + fi fi +if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then +# If build native modules preference is not set, try to find .gyp files +#to turn it on. + gypfiles=($(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.gyp")) + if [ \${#gypfiles[@]} -gt 0 ]; then + NODEJS_MOBILE_BUILD_NATIVE_MODULES=1 + else + NODEJS_MOBILE_BUILD_NATIVE_MODULES=0 + fi fi if [ "1" != "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then exit 0; fi # Delete object files