Skip to content

Commit

Permalink
plugin: Build native modules automatically
Browse files Browse the repository at this point in the history
Adds a step to try and detect .gyp files inside the nodejs-project
if the NODEJS_MOBILE_BUILD_NATIVE_MODULES environment variable isn't
set, to automatically detect the need to build native modules.
  • Loading branch information
jaimecbernardo committed Feb 15, 2018
1 parent 7ae4dd5 commit 8a7688f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
20 changes: 19 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ tasks.getByPath(":${project.name}:preBuild").dependsOn GenerateNodeProjectAssets

import org.gradle.internal.os.OperatingSystem;

if ("1".equals(System.getenv('NODEJS_MOBILE_BUILD_NATIVE_MODULES'))) {
String shouldRebuildNativeModules = System.getenv('NODEJS_MOBILE_BUILD_NATIVE_MODULES');

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)) {
task ApplyPatchScriptToModules (type:Exec) {
dependsOn "CopyNodeProjectAssetsFolder"
description "Apply patches to modules to improve compatibility."
Expand Down
23 changes: 22 additions & 1 deletion scripts/module-postlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,18 @@ if ( detectedConfigs && detectedConfigs.ios && detectedConfigs.ios.pbxprojPath)
//Adds a build phase to rebuild native modules
var rebuildNativeModulesBuildPhaseName = 'Build NodeJS Mobile Native Modules';
var rebuildNativeModulesBuildPhaseScript = `
if [ "1" != "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then exit 0; fi
set -e
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
# Apply patches to the modules package.json
PATCH_SCRIPT_DIR="$( cd "$PROJECT_DIR" && cd ../node_modules/nodejs-mobile-react-native/scripts/ && pwd )"
NODEJS_PROJECT_MODULES_DIR="$( cd "$CODESIGNING_FOLDER_PATH" && cd nodejs-project/node_modules/ && pwd )"
Expand Down Expand Up @@ -180,6 +190,17 @@ popd
//Adds a build phase to sign native modules
var signNativeModulesBuildPhaseName = 'Sign NodeJS Mobile Native Modules';
var signNativeModulesBuildPhaseScript = `
set -e
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
/usr/bin/codesign --force --sign $EXPANDED_CODE_SIGN_IDENTITY --preserve-metadata=identifier,entitlements,flags --timestamp=none $(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.node")
`
Expand Down

0 comments on commit 8a7688f

Please sign in to comment.