Skip to content

Commit

Permalink
plugin: add automatic native modules detection
Browse files Browse the repository at this point in the history
Adds automatic detection of native modules by looking for .gyp files
inside the nodejs-project modules.
  • Loading branch information
jaimecbernardo committed Jun 27, 2018
1 parent ded08e5 commit eb960e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
16 changes: 16 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
32 changes: 24 additions & 8 deletions scripts/module-postlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb960e0

Please sign in to comment.