diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 9af165313093d9..35822c377965e2 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -798,7 +798,7 @@ SPEC CHECKSUMS: CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f DoubleConversion: cde416483dac037923206447da6e1454df403714 FBLazyVector: fe973c09b2299b5e8154186ecf1f6554b4f70987 - FBReactNativeSpec: cc83b1f9c1a764577c37a7009d002b8afb36f192 + FBReactNativeSpec: d0504078deb2ffa0fbee5032382f4ef165a1c8a8 Flipper: be611d4b742d8c87fbae2ca5f44603a02539e365 Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41 Flipper-Folly: e4493b013c02d9347d5e0cb4d128680239f6c78a diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index 25cf8d255118ff..cd4ef2902d2bdf 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -8,8 +8,16 @@ # native modules and components, then uses react-native-codegen # to generate native code. # +# Optionally, set these envvars to override defaults: +# - SRCS_DIR: Path to JavaScript sources +# - CODEGEN_MODULES_LIBRARY_NAME: Defaults to FBReactNativeSpec +# - CODEGEN_MODULES_OUTPUT_DIR: Defaults to Libraries/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME +# - CODEGEN_COMPONENTS_LIBRARY_NAME: Defaults to rncore +# - CODEGEN_COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$CODEGEN_COMPONENTS_LIBRARY_NAME +# # Usage: # ./scripts/generate-specs.sh +# SRCS_DIR=myapp/js CODEGEN_MODULES_LIBRARY_NAME=MySpecs CODEGEN_MODULES_OUTPUT_DIR=myapp/MySpecs ./scripts/generate-specs.sh # # shellcheck disable=SC2038 @@ -33,12 +41,16 @@ describe () { } main() { - SRCS_DIR=$(cd "$RN_DIR/Libraries" && pwd) + SRCS_DIR=${SRCS_DIR:-$(cd "$RN_DIR/Libraries" && pwd)} + CODEGEN_MODULES_LIBRARY_NAME=${CODEGEN_MODULES_LIBRARY_NAME:-FBReactNativeSpec} - OUTPUT_DIR="$TEMP_DIR/out" - COMPONENTS_DIR="$RN_DIR/ReactCommon/react/renderer/components/rncore" - MODULES_DIR="$RN_DIR/Libraries/FBReactNativeSpec/FBReactNativeSpec" + CODEGEN_COMPONENTS_LIBRARY_NAME=${CODEGEN_COMPONENTS_LIBRARY_NAME:-rncore} + CODEGEN_MODULES_OUTPUT_DIR=${CODEGEN_MODULES_OUTPUT_DIR:-"$RN_DIR/Libraries/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME"} + # TODO: $CODEGEN_COMPONENTS_PATH should be programmatically specified, and may change with use_frameworks! support. + CODEGEN_COMPONENTS_PATH="ReactCommon/react/renderer/components" + CODEGEN_COMPONENTS_OUTPUT_DIR=${CODEGEN_COMPONENTS_OUTPUT_DIR:-"$RN_DIR/$CODEGEN_COMPONENTS_PATH/$CODEGEN_COMPONENTS_LIBRARY_NAME"} + TEMP_OUTPUT_DIR="$TEMP_DIR/out" SCHEMA_FILE="$TEMP_DIR/schema.json" CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" @@ -66,13 +78,13 @@ main() { describe "Generating native code from schema (iOS)" pushd "$RN_DIR" >/dev/null || exit - "$YARN_BINARY" --silent node scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$OUTPUT_DIR" + "$YARN_BINARY" --silent node scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME" popd >/dev/null || exit - mkdir -p "$COMPONENTS_DIR" "$MODULES_DIR" - mv "$OUTPUT_DIR/FBReactNativeSpec.h" "$OUTPUT_DIR/FBReactNativeSpec-generated.mm" "$MODULES_DIR" - find "$OUTPUT_DIR" -type f | xargs sed -i '' 's/FBReactNativeSpec/rncore/g' - cp -R "$OUTPUT_DIR/." "$COMPONENTS_DIR" + mkdir -p "$CODEGEN_COMPONENTS_OUTPUT_DIR" "$CODEGEN_MODULES_OUTPUT_DIR" + mv "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME-generated.mm" "$CODEGEN_MODULES_OUTPUT_DIR" + find "$TEMP_OUTPUT_DIR" -type f | xargs sed -i '' "s/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_COMPONENTS_LIBRARY_NAME/g" + cp -R "$TEMP_OUTPUT_DIR/." "$CODEGEN_COMPONENTS_OUTPUT_DIR" } trap cleanup EXIT diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index f26f587e109def..2e01cfaebfae46 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -153,30 +153,36 @@ def use_react_native_codegen!(spec, options={}) srcs_dir = options[:srcs_dir] ||= File.join(prefix, "Libraries") # Library name (e.g. FBReactNativeSpec) - library_name = spec.name - modules_output_dir = File.join(prefix, "Libraries/#{library_name}/#{library_name}") + codegen_modules_library_name = spec.name + codegen_modules_output_dir = options[:codegen_modules_output_dir] ||= File.join(prefix, "Libraries/#{codegen_modules_library_name}/#{codegen_modules_library_name}") # Run the codegen as part of the Xcode build pipeline. + env_vars = "SRCS_DIR=#{srcs_dir}" + env_vars += " CODEGEN_MODULES_OUTPUT_DIR=#{codegen_modules_output_dir}" + if ENV['USE_FABRIC'] == '1' + # We use a different library name for components, as well as an additional set of files. + # Eventually, we want these to be part of the same library as #{codegen_modules_library_name} above. + codegen_components_library_name = "rncore" + codegen_components_output_dir = File.join(prefix, "ReactCommon/react/renderer/components/#{codegen_components_library_name}") + env_vars += " CODEGEN_COMPONENTS_OUTPUT_DIR=#{codegen_components_output_dir}" + end spec.script_phase = { :name => 'Generate Specs', :input_files => [srcs_dir], - :output_files => ["$(DERIVED_FILE_DIR)/codegen.log"], - :script => "sh '#{File.join(__dir__, "generate-specs.sh")}' | tee \"${SCRIPT_OUTPUT_FILE_0}\"", - :execution_position => :before_compile + :output_files => ["$(DERIVED_FILE_DIR)/codegen-#{codegen_modules_library_name}.log"], + :script => "bash -c '#{env_vars} CODEGEN_MODULES_LIBRARY_NAME=#{codegen_modules_library_name} #{File.join(__dir__, "generate-specs.sh")}' | tee \"${SCRIPT_OUTPUT_FILE_0}\"", + :execution_position => :before_compile, + :show_env_vars_in_log => true } # 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 #{modules_output_dir}" - generated_filenames = [ "#{library_name}.h", "#{library_name}-generated.mm" ] - generated_files = generated_filenames.map { |filename| File.join(modules_output_dir, filename) } + 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) } if ENV['USE_FABRIC'] == '1' - # We use a different library name for components, as well as an additional set of files. - # Eventually, we want these to be part of the same library as #{library_name} above. - components_library_name = "rncore" - components_output_dir = File.join(prefix, "ReactCommon/react/renderer/components/#{components_library_name}") - mkdir_command += " #{components_output_dir}" + mkdir_command += " #{codegen_components_output_dir}" components_generated_filenames = [ "ComponentDescriptors.h", "EventEmitters.cpp", @@ -187,7 +193,7 @@ def use_react_native_codegen!(spec, options={}) "ShadowNodes.cpp", "ShadowNodes.h" ] - generated_files = generated_files.concat(components_generated_filenames.map { |filename| File.join(components_output_dir, filename) }) + generated_files = generated_files.concat(components_generated_filenames.map { |filename| File.join(codegen_components_output_dir, filename) }) end spec.prepare_command = "#{mkdir_command} && touch #{generated_files.reduce() { |str, file| str + " " + file }}"