Skip to content

Commit

Permalink
plugin: use original .bin for native modules
Browse files Browse the repository at this point in the history
Uses the original project's .bin folder when building native modules.
Cordova prepare step resolves the symbolic links instead of preserving
them, which causes fails when building modules that depend on linked
modules, such as node-pre-gyp. With this change, the native modules
build step will try to use the original project's linked binaries.
  • Loading branch information
jaimecbernardo committed Jun 29, 2018
1 parent 53a1aeb commit df7df19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions install/hooks/ios/after-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -path "*/*.node/*" -delete
find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -name "*.node" -type d -delete
find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -path "*/*.framework/*" -delete
find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -name "*.framework" -type d -delete
# Symlinks to binaries are resolved by cordova prepare during the copy, causing build time errors.
# The original project's .bin folder will be added to the path before building the native modules.
find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -path "*/.bin/*" -delete
find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -name ".bin" -type d -delete
# Get the nodejs-mobile-gyp location
if [ -d "$PROJECT_DIR/../../plugins/nodejs-mobile-cordova/node_modules/nodejs-mobile-gyp/" ]; then
NODEJS_MOBILE_GYP_DIR="$( cd "$PROJECT_DIR" && cd ../../plugins/nodejs-mobile-cordova/node_modules/nodejs-mobile-gyp/ && pwd )"
Expand All @@ -56,6 +60,12 @@ fi
NODEJS_MOBILE_GYP_BIN_FILE="$NODEJS_MOBILE_GYP_DIR"/bin/node-gyp.js
# Rebuild modules with right environment
NODEJS_HEADERS_DIR="$( cd "$( dirname "$PRODUCT_SETTINGS_PATH" )" && cd Plugins/nodejs-mobile-cordova/ && pwd )"
# Adds the original project .bin to the path. It's a workaround
# to correctly build some modules that depend on symlinked modules,
# like node-pre-gyp.
if [ -d "$PROJECT_DIR/../../www/nodejs-project/node_modules/.bin/" ]; then
PATH="$PROJECT_DIR/../../www/nodejs-project/node_modules/.bin/:$PATH"
fi
pushd $CODESIGNING_FOLDER_PATH/www/nodejs-project/
if [ "$PLATFORM_NAME" == "iphoneos" ]
then
Expand Down
12 changes: 12 additions & 0 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ if ("1".equals(shouldRebuildNativeModules)) {
copy {
from "${project.projectDir}/assets/www/nodejs-project/"
into "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
// Symlinks to binaries are resolved by cordova prepare and Gradle during the copy, causing build time errors.
// The original project's .bin folder will be added to the path while building in the BuildNpmModules tasks.
exclude "**/.bin"
}
if (OperatingSystem.current().isMacOsX()) {
// Copy the helper script for calling npm when building in Android Studio on macOS.
Expand Down Expand Up @@ -221,6 +224,15 @@ if ("1".equals(shouldRebuildNativeModules)) {
environment ('npm_config_arch', temp_arch)
environment ('npm_config_platform', 'android')
environment ('npm_config_format', 'make-android')

// Adds the original project .bin to the path. It's a workaround
// to correctly build some modules that depend on symlinked modules,
// like node-pre-gyp.
String original_project_bin = "${rootProject.projectDir}/../../www/nodejs-project/node_modules/.bin";
if(file(original_project_bin).exists()) {
environment ('PATH', "${original_project_bin}" + System.getProperty("path.separator") + "${System.env.PATH}")
}

environment ('TOOLCHAIN',"${standalone_toolchain}")
environment ('AR',"${npm_toolchain_ar}")
environment ('CC',"${npm_toolchain_cc}")
Expand Down

0 comments on commit df7df19

Please sign in to comment.