From 9949af2d6aba282bcaff56ab0be607adadd75c64 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 02:05:35 +0100 Subject: [PATCH 1/7] fix: codegen blank files --- .gitignore | 1 - React/FBReactNativeSpec/FBReactNativeSpec.podspec | 1 - .../FBReactNativeSpec/FBReactNativeSpec-generated.mm | 0 .../FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h | 0 scripts/react_native_pods.rb | 5 ----- 5 files changed, 7 deletions(-) create mode 100644 React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm create mode 100644 React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h diff --git a/.gitignore b/.gitignore index 9aea329a6c35fd..4f47d314cfb085 100644 --- a/.gitignore +++ b/.gitignore @@ -100,7 +100,6 @@ package-lock.json !/packages/rn-tester/Pods/__offline_mirrors__ # react-native-codegen -/React/FBReactNativeSpec/FBReactNativeSpec /packages/react-native-codegen/lib /ReactCommon/react/renderer/components/rncore/ diff --git a/React/FBReactNativeSpec/FBReactNativeSpec.podspec b/React/FBReactNativeSpec/FBReactNativeSpec.podspec index f87e08309f225d..41edd7cfc4e0ce 100644 --- a/React/FBReactNativeSpec/FBReactNativeSpec.podspec +++ b/React/FBReactNativeSpec/FBReactNativeSpec.podspec @@ -46,5 +46,4 @@ Pod::Spec.new do |s| s.dependency "React-jsi", version s.dependency "ReactCommon/turbomodule/core", version - use_react_native_codegen! (s) end diff --git a/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index a31c51dbde30c3..3abf70a554ee68 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -162,9 +162,6 @@ def use_react_native_codegen!(spec, options={}) env_vars = "SRCS_DIR=#{srcs_dir}" env_vars += " CODEGEN_MODULES_OUTPUT_DIR=#{codegen_modules_output_dir}" - # Since the generated files are not guaranteed to exist when CocoaPods is run, we need to create - # empty files to ensure the references are included in the resulting Pods Xcode project. - mkdir_command = "mkdir -p #{codegen_modules_output_dir}" generated_filenames = [ "#{codegen_modules_library_name}.h", "#{codegen_modules_library_name}-generated.mm" ] generated_files = generated_filenames.map { |filename| File.join(codegen_modules_output_dir, filename) } @@ -196,6 +193,4 @@ def use_react_native_codegen!(spec, options={}) :execution_position => :before_compile, :show_env_vars_in_log => true } - - spec.prepare_command = "#{mkdir_command} && touch #{generated_files.reduce() { |str, file| str + " " + file }}" end From d49f623421ab02ae39ad7149a40a8ea8ac69319e Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 02:07:27 +0100 Subject: [PATCH 2/7] chore: add codegen script back --- React/FBReactNativeSpec/FBReactNativeSpec.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/React/FBReactNativeSpec/FBReactNativeSpec.podspec b/React/FBReactNativeSpec/FBReactNativeSpec.podspec index 41edd7cfc4e0ce..f87e08309f225d 100644 --- a/React/FBReactNativeSpec/FBReactNativeSpec.podspec +++ b/React/FBReactNativeSpec/FBReactNativeSpec.podspec @@ -46,4 +46,5 @@ Pod::Spec.new do |s| s.dependency "React-jsi", version s.dependency "ReactCommon/turbomodule/core", version + use_react_native_codegen! (s) end From b9781b8416438fd45bf86ce1f3bd9ead3249130a Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 02:10:21 +0100 Subject: [PATCH 3/7] chore: restore react_native_pods, prepare_command is still fine --- scripts/react_native_pods.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 3abf70a554ee68..a31c51dbde30c3 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -162,6 +162,9 @@ def use_react_native_codegen!(spec, options={}) env_vars = "SRCS_DIR=#{srcs_dir}" env_vars += " CODEGEN_MODULES_OUTPUT_DIR=#{codegen_modules_output_dir}" + # Since the generated files are not guaranteed to exist when CocoaPods is run, we need to create + # empty files to ensure the references are included in the resulting Pods Xcode project. + mkdir_command = "mkdir -p #{codegen_modules_output_dir}" generated_filenames = [ "#{codegen_modules_library_name}.h", "#{codegen_modules_library_name}-generated.mm" ] generated_files = generated_filenames.map { |filename| File.join(codegen_modules_output_dir, filename) } @@ -193,4 +196,6 @@ def use_react_native_codegen!(spec, options={}) :execution_position => :before_compile, :show_env_vars_in_log => true } + + spec.prepare_command = "#{mkdir_command} && touch #{generated_files.reduce() { |str, file| str + " " + file }}" end From 41954c48b5aeb5d0ecba17f91125c3a03f6773ec Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 03:18:14 +0100 Subject: [PATCH 4/7] feat: rework codegen sh setup --- package.json | 3 ++- scripts/generate-specs.sh | 27 ++++++++++++--------------- template/package.json | 3 +-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 25f41b42b82ce5..e3693f8219befe 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "promise": "^8.0.3", "prop-types": "^15.7.2", "react-devtools-core": "^4.6.0", + "react-native-codegen": "^0.0.7", "react-refresh": "^0.4.0", "regenerator-runtime": "^0.13.2", "scheduler": "^0.20.1", @@ -155,4 +156,4 @@ } } } -} \ No newline at end of file +} diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index ab297fd18d7fb2..fe9e58f7ab0d5f 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -53,33 +53,30 @@ main() { TEMP_OUTPUT_DIR="$TEMP_DIR/out" SCHEMA_FILE="$TEMP_DIR/schema.json" - CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" - CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen" - -if [ -z "$NODE_BINARY" ]; then + if [ -z "$NODE_BINARY" ]; then echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 exit 1 fi - if [ -d "$CODEGEN_REPO_PATH" ]; then - CODEGEN_PATH=$(cd "$CODEGEN_REPO_PATH" && pwd) - elif [ -d "$CODEGEN_NPM_PATH" ]; then - CODEGEN_PATH=$(cd "$CODEGEN_NPM_PATH" && pwd) - else - echo "Error: Could not determine react-native-codegen location. Try running 'yarn install' or 'npm install' in your project root." 1>&2 + # Check if user-defined CODEGEN_PATH is correct + if [[ "$CODEGEN_PATH" && ! -d "$CODEGEN_PATH" ]]; then + echo "error: Could not find react-native-codegen at ${CODEGEN_PATH}. " \ + "Perhaps you need to run npm install or otherwise " \ + "point the CODEGEN_PATH variable to your custom location." >&2 exit 1 fi + # Default value of CODEGEN_PATH is a location of a react-native-codegen package + if [[ -z "$CODEGEN_PATH" ]]; then + CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))") + fi + + # Special case for running CodeGen from source: build it if [ ! -d "$CODEGEN_PATH/lib" ]; then describe "Building react-native-codegen package" bash "$CODEGEN_PATH/scripts/oss/build.sh" fi - if [ -z "$NODE_BINARY" ]; then - echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 - exit 1 - fi - describe "Generating schema from flow types" "$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR" diff --git a/template/package.json b/template/package.json index e4bde1985d64a2..199212703205fa 100644 --- a/template/package.json +++ b/template/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "react": "17.0.1", - "react-native": "0.64.0-rc.3" + "react-native": "file:/Users/grabbou/Repositories/react-native/react-native-0.64.0-rc.420.tgz" }, "devDependencies": { "@babel/core": "^7.12.9", @@ -21,7 +21,6 @@ "eslint": "7.14.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.64.0", - "react-native-codegen": "^0.0.7", "react-test-renderer": "17.0.1" }, "jest": { From 9b3295102837ca49bf36e31ce0ca887f8e390fb7 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 13:29:32 +0100 Subject: [PATCH 5/7] chore: revert unwanted change --- template/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/package.json b/template/package.json index 199212703205fa..5705a7487966f7 100644 --- a/template/package.json +++ b/template/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "react": "17.0.1", - "react-native": "file:/Users/grabbou/Repositories/react-native/react-native-0.64.0-rc.420.tgz" + "react-native": "0.64.0-rc.3" }, "devDependencies": { "@babel/core": "^7.12.9", From 2682701585461ecef4303b4dea2197c664b2cd70 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 14:28:13 +0100 Subject: [PATCH 6/7] chore: can't overwrite CODEGEN_PATH right now, remove this --- .../RNTesterPods.xcodeproj/project.pbxproj | 2 ++ scripts/generate-specs.sh | 13 +------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 98975cb09293ec..0c2a87cb8bd6db 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -751,6 +751,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CODEGEN_PATH = "$(SRCROOT)/../react-native-codegen"; DEVELOPMENT_TEAM = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", @@ -793,6 +794,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CODEGEN_PATH = "$(SRCROOT)/../react-native-codegen"; DEVELOPMENT_TEAM = ""; EXCLUDED_ARCHS = ""; INFOPLIST_FILE = "$(SRCROOT)/RNTester/Info.plist"; diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index fe9e58f7ab0d5f..808830c8bd2008 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -58,18 +58,7 @@ main() { exit 1 fi - # Check if user-defined CODEGEN_PATH is correct - if [[ "$CODEGEN_PATH" && ! -d "$CODEGEN_PATH" ]]; then - echo "error: Could not find react-native-codegen at ${CODEGEN_PATH}. " \ - "Perhaps you need to run npm install or otherwise " \ - "point the CODEGEN_PATH variable to your custom location." >&2 - exit 1 - fi - - # Default value of CODEGEN_PATH is a location of a react-native-codegen package - if [[ -z "$CODEGEN_PATH" ]]; then - CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))") - fi + CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))") # Special case for running CodeGen from source: build it if [ ! -d "$CODEGEN_PATH/lib" ]; then From 5bebd492559fdeddda3f62a777da13e767cb3594 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Feb 2021 14:29:26 +0100 Subject: [PATCH 7/7] chore: remove extra user-defined envs --- packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 0c2a87cb8bd6db..98975cb09293ec 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -751,7 +751,6 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++14"; - CODEGEN_PATH = "$(SRCROOT)/../react-native-codegen"; DEVELOPMENT_TEAM = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", @@ -794,7 +793,6 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++14"; - CODEGEN_PATH = "$(SRCROOT)/../react-native-codegen"; DEVELOPMENT_TEAM = ""; EXCLUDED_ARCHS = ""; INFOPLIST_FILE = "$(SRCROOT)/RNTester/Info.plist";