From b93faf9d869d31a7e2caa3e255e2a443db76ec19 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Tue, 27 Aug 2024 13:36:01 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Improved=20logging=20around=20th?= =?UTF-8?q?e=20script=20to=20patch=20the=20`IPHONEOS=5FDEPLOYMENT=5FTARGET?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add additional logging to debug this more efficiently in the future The additional logging is accessed with `--verbose`. While testing this, I realized that `--verbose` would have been helpful in debugging this issue in the first place - it makes is really clear that the `pod install` happens as part of prepare before the compile. Still not sure how it worked locally before! - No verbose: ``` cordova-custom-config: Applied custom config from config.xml to /Users/kshankar/Desktop/data/e-mission/native_code_upgrade/platforms/ios/emission/emission-Info.plist Apply patch to [ 'node_modules/@shopify/flash-list/ios/RNFlashList.xcodeproj/project.pbxproj', 'node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj', 'node_modules/cordova-ios/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj', 'node_modules/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj', 'node_modules/react-native-gesture-handler/ios/RNGestureHandler.xcodeproj/project.pbxproj', 'node_modules/react-native-safe-area-context/ios/RNSafeAreaContext.xcodeproj/project.pbxproj', 'node_modules/react-native-screens/ios/RNScreens.xcodeproj/project.pbxproj', 'node_modules/react-native-vector-icons/RNVectorIcons.xcodeproj/project.pbxproj', 'platforms/ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj', 'platforms/ios/Pods/Pods.xcodeproj/project.pbxproj', 'platforms/ios/emission.xcodeproj/project.pbxproj' ] Done setting IPHONEOS_DEPLOYMENT_TARGET List simulator targets Select last emulator from list as default. List simulator targets No simulator found for ". Falling back to the default target. Building for "iPhone 15 Pro Max" Simulator (com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro-Max, iPhone-15-Pro-Max). Building project: /Users/kshankar/Desktop/data/e-mission/native_code_upgrade/platforms/ios/emission.xcworkspace Configuration: Debug Platform: emulator Target: iPhone 15 Pro Max Command line invocation: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace emission.xcworkspace -scheme emission -configuration Debug -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 15 Pro Max" build SYMROOT=/Users/kshankar/Desktop/data/e-mission/native_code_upgrade/platforms/ios/build ``` - verbose ``` pods.json found in platforms/ios Podfile found in platforms/ios Wrote to Podfile. Running `pod install` (to install plugins) ==== pod install start ==== ==== pod install end ==== Updating resource files at platforms/ios Prepared iOS project successfully Executing script found in config.xml for hook "before_compile": hooks/before_compile/ios/ios_change_deployment.js Context { hook: 'before_compile', opts: { platforms: [ 'ios' ], options: { verbose: true, argv: [] }, verbose: true, silent: false, nohooks: [], searchpath: undefined, projectRoot: '/Users/kshankar/Desktop/data/e-mission/native_code_upgrade', cordova: { platforms: [Array], plugins: [Array], version: '12.0.1' }, save: false, paths: [ '/Users/kshankar/Desktop/data/e-mission/native_code_upgrade/platforms/ios/www' ] }, cmdLine: '/Users/kshankar/.nvm/versions/node/v20.9.0/bin/node /Users/kshankar/Desktop/data/e-mission/native_code_upgrade/node_modules/.bin/cordova build ios --verbose', scriptLocation: '/Users/kshankar/Desktop/data/e-mission/native_code_upgrade/hooks/before_compile/ios/ios_change_deployment.js' } Apply patch to [ 'node_modules/@shopify/flash-list/ios/RNFlashList.xcodeproj/project.pbxproj', 'node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj', 'node_modules/cordova-ios/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj', 'node_modules/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj', 'node_modules/react-native-gesture-handler/ios/RNGestureHandler.xcodeproj/project.pbxproj', 'node_modules/react-native-safe-area-context/ios/RNSafeAreaContext.xcodeproj/project.pbxproj', 'node_modules/react-native-screens/ios/RNScreens.xcodeproj/project.pbxproj', 'node_modules/react-native-vector-icons/RNVectorIcons.xcodeproj/project.pbxproj', 'platforms/ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj', 'platforms/ios/Pods/Pods.xcodeproj/project.pbxproj', 'platforms/ios/emission.xcodeproj/project.pbxproj' ] Done setting IPHONEOS_DEPLOYMENT_TARGET Executing script found in plugin cordova-custom-config for hook "before_compile": plugins/cordova-custom-config/hooks/applyCustomConfig.js ^[[32mcordova-custom-config: Loaded module dependencies^[[39m ^[[32mcordova-custom-config: Running applyCustomConfig.js^[[39m ^[[32mcordova-custom-config: Finished applying platform config^[[39m before patching, grep -r IPHONEOS_DEPLOYMENT_TARGET platforms/ios | sort | uniq: platforms/ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; platforms/ios/Pods/Pods.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 10.0; platforms/ios/Pods/Pods.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; platforms/ios/Pods/Pods.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 8.0; platforms/ios/Pods/Pods.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 9.0; platforms/ios/emission.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; after patching, grep -r IPHONEOS_DEPLOYMENT_TARGET platforms/ios | sort | uniq: platforms/ios/CordovaLib/CordovaLib.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; platforms/ios/Pods/Pods.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; platforms/ios/emission.xcodeproj/project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 13.0; ``` --- .../ios/ios_change_deployment.js | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/hooks/before_compile/ios/ios_change_deployment.js b/hooks/before_compile/ios/ios_change_deployment.js index ad381162d..cb848cef4 100644 --- a/hooks/before_compile/ios/ios_change_deployment.js +++ b/hooks/before_compile/ios/ios_change_deployment.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const { exec } = require('child_process'); function findFilePathsByFilename(directory, filename) { const files = fs.readdirSync(directory); @@ -21,17 +22,39 @@ function findFilePathsByFilename(directory, filename) { return filePaths; } +function logTarget(directory, logmsg) { + const grepstmt = `grep -r IPHONEOS_DEPLOYMENT_TARGET ${directory} | sort | uniq` + exec(grepstmt, (err, stdout, stderr) => { + if (err) { + console.log(`${logmsg}, ${grepstmt}:\n`, stderr) + return; + } + + // the *entire* stdout and stderr (buffered) + console.log(`${logmsg}, ${grepstmt}:\n`, stdout); + }); +} + +module.exports = function(context) { + if (context.opts.verbose) console.log(context); + + if (context.opts.verbose) logTarget("platforms/ios", "before patching"); -const paths1 = findFilePathsByFilename('.', 'project.pbxproj'); -const paths2 = findFilePathsByFilename('.', 'Pods.xcodeproj'); -const paths = paths1.concat(paths2) + const paths1 = findFilePathsByFilename('.', 'project.pbxproj'); + const paths2 = findFilePathsByFilename('.', 'Pods.xcodeproj'); + const paths = paths1.concat(paths2) -console.log('Apply patch to', paths); + console.log('Apply patch to', paths); -for (let path of paths) { - let content = fs.readFileSync(path, { encoding: 'utf-8' }); - content = content.replace(/IPHONEOS_DEPLOYMENT_TARGET = [0-9]+.0;/g, 'IPHONEOS_DEPLOYMENT_TARGET = 13.0;'); - fs.writeFileSync(path, content); + for (let path of paths) { + let content = fs.readFileSync(path, { encoding: 'utf-8' }); + content = content.replace(/IPHONEOS_DEPLOYMENT_TARGET = [0-9]+.0;/g, 'IPHONEOS_DEPLOYMENT_TARGET = 13.0;'); + fs.writeFileSync(path, content); + } + + console.log('Done setting IPHONEOS_DEPLOYMENT_TARGET'); + + if (context.opts.verbose) logTarget("platforms/ios", "after patching"); } -console.log('Done setting IPHONEOS_DEPLOYMENT_TARGET'); +