Skip to content

Commit

Permalink
Avoid encoding local path in Podfile.lock
Browse files Browse the repository at this point in the history
Summary:
The `SPEC CHECKSUM` for `FBReactNativeSpec` in `packages/rn-tester/Podfile.lock` and in standalone apps's `ios/Podfile.lock` varies between development machines. This is caused by local paths in the output of `pod ipc spec FBReactNativeSpec.podspec`, such as `output_files` and `prepare_command`. This causes the Podfile.lock to constantly change when pod install is run on different developers' machines.

The codegen script and CocoaPods configuration have been updated to use relative paths.

Closes #31193

Changelog: [Internal] [Codegen] Avoid encoding local path in Podfile.lock

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
  • Loading branch information
hramos authored and facebook-github-bot committed Apr 16, 2021
1 parent 6971640 commit bdfe2a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
32 changes: 16 additions & 16 deletions scripts/generate-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#
# 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 React/$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
# - MODULES_LIBRARY_NAME: Defaults to FBReactNativeSpec
# - MODULES_OUTPUT_DIR: Defaults to React/$MODULES_LIBRARY_NAME/$MODULES_LIBRARY_NAME
# - COMPONENTS_LIBRARY_NAME: Defaults to rncore
# - COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$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
# SRCS_DIR=myapp/js MODULES_LIBRARY_NAME=MySpecs MODULES_OUTPUT_DIR=myapp/MySpecs ./scripts/generate-specs.sh
#

# shellcheck disable=SC2038
Expand Down Expand Up @@ -46,13 +46,13 @@ describe () {

main() {
SRCS_DIR=${SRCS_DIR:-$(cd "$RN_DIR/Libraries" && pwd)}
CODEGEN_MODULES_LIBRARY_NAME=${CODEGEN_MODULES_LIBRARY_NAME:-FBReactNativeSpec}
MODULES_LIBRARY_NAME=${MODULES_LIBRARY_NAME:-FBReactNativeSpec}

CODEGEN_COMPONENTS_LIBRARY_NAME=${CODEGEN_COMPONENTS_LIBRARY_NAME:-rncore}
CODEGEN_MODULES_OUTPUT_DIR=${CODEGEN_MODULES_OUTPUT_DIR:-"$RN_DIR/React/$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"}
COMPONENTS_LIBRARY_NAME=${COMPONENTS_LIBRARY_NAME:-rncore}
MODULES_OUTPUT_DIR=${MODULES_OUTPUT_DIR:-"$RN_DIR/React/$MODULES_LIBRARY_NAME/$MODULES_LIBRARY_NAME"}
# TODO: $COMPONENTS_PATH should be programmatically specified, and may change with use_frameworks! support.
COMPONENTS_PATH="ReactCommon/react/renderer/components"
COMPONENTS_OUTPUT_DIR=${COMPONENTS_OUTPUT_DIR:-"$RN_DIR/$COMPONENTS_PATH/$COMPONENTS_LIBRARY_NAME"}

TEMP_OUTPUT_DIR="$TEMP_DIR/out"
SCHEMA_FILE="$TEMP_DIR/schema.json"
Expand Down Expand Up @@ -84,14 +84,14 @@ main() {

describe "Generating native code from schema (iOS)"
pushd "$RN_DIR" >/dev/null || exit 1
"$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME"
"$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$MODULES_LIBRARY_NAME"
popd >/dev/null || exit 1

describe "Copying output to final directory"
mkdir -p "$CODEGEN_COMPONENTS_OUTPUT_DIR" "$CODEGEN_MODULES_OUTPUT_DIR"
cp -v -R "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME-generated.mm" "$CODEGEN_MODULES_OUTPUT_DIR" || exit 1
find "$TEMP_OUTPUT_DIR" -type f | xargs sed -i.bak "s/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_COMPONENTS_LIBRARY_NAME/g" || exit 1
find "$TEMP_OUTPUT_DIR" -type f -not -iname "$CODEGEN_MODULES_LIBRARY_NAME*" -exec cp -v '{}' "$CODEGEN_COMPONENTS_OUTPUT_DIR/" ';' || exit 1
mkdir -p "$COMPONENTS_OUTPUT_DIR" "$MODULES_OUTPUT_DIR"
cp -R "$TEMP_OUTPUT_DIR/$MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$MODULES_LIBRARY_NAME-generated.mm" "$MODULES_OUTPUT_DIR" || exit 1
find "$TEMP_OUTPUT_DIR" -type f | xargs sed -i.bak "s/$MODULES_LIBRARY_NAME/$COMPONENTS_LIBRARY_NAME/g" || exit 1
find "$TEMP_OUTPUT_DIR" -type f -not -iname "$MODULES_LIBRARY_NAME*" -exec cp '{}' "$COMPONENTS_OUTPUT_DIR/" ';' || exit 1

echo >&2 'Done.'
}
Expand Down
43 changes: 20 additions & 23 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,31 @@ def react_native_post_install(installer)
def use_react_native_codegen!(spec, options={})
return if ENV['DISABLE_CODEGEN'] == '1'

# The path to react-native (e.g. react_native_path)
prefix = options[:path] ||= File.join(__dir__, "..")
# The path to react-native
prefix = options[:path] ||= "${PODS_TARGET_SRCROOT}/../.."

# The path to JavaScript files
srcs_dir = options[:srcs_dir] ||= File.join(prefix, "Libraries")
js_srcs = options[:js_srcs_dir] ||= "#{prefix}/Libraries"

# Library name (e.g. FBReactNativeSpec)
codegen_modules_library_name = spec.name
codegen_modules_output_dir = options[:codegen_modules_output_dir] ||= File.join(prefix, "React/#{codegen_modules_library_name}/#{codegen_modules_library_name}")
modules_library_name = spec.name
modules_output_dir = "React/#{modules_library_name}/#{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}"
env_vars = "SRCS_DIR=#{js_srcs}"
env_vars += " MODULES_OUTPUT_DIR=#{prefix}/#{modules_output_dir}"
env_vars += " MODULES_LIBRARY_NAME=#{modules_library_name}"

# 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) }
generated_dirs = [ modules_output_dir ]
generated_filenames = [ "#{modules_library_name}.h", "#{modules_library_name}-generated.mm" ]
generated_files = generated_filenames.map { |filename| "#{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 #{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}"
mkdir_command += " #{codegen_components_output_dir}"
# Eventually, we want these to be part of the same library as #{modules_library_name} above.
components_output_dir = "ReactCommon/react/renderer/components/rncore/"
generated_dirs.push components_output_dir
env_vars += " COMPONENTS_OUTPUT_DIR=#{prefix}/#{components_output_dir}"
components_generated_filenames = [
"ComponentDescriptors.h",
"EventEmitters.cpp",
Expand All @@ -185,17 +183,16 @@ def use_react_native_codegen!(spec, options={})
"ShadowNodes.cpp",
"ShadowNodes.h"
]
generated_files = generated_files.concat(components_generated_filenames.map { |filename| File.join(codegen_components_output_dir, filename) })
generated_files = generated_files.concat(components_generated_filenames.map { |filename| "#{components_output_dir}/#{filename}" })
end

spec.script_phase = {
:name => 'Generate Specs',
:input_files => [srcs_dir],
:output_files => ["$(DERIVED_FILE_DIR)/codegen-#{codegen_modules_library_name}.log"].concat(generated_files),
:script => "set -o pipefail\n\nbash -l -c '#{env_vars} CODEGEN_MODULES_LIBRARY_NAME=#{codegen_modules_library_name} #{File.join(__dir__, "generate-specs.sh")}' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",
:input_files => [js_srcs],
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{modules_library_name}.log"].concat(generated_files.map { |filename| "#{prefix}/#{filename}"} ),
:script => "set -o pipefail\n\nbash -l -c '#{env_vars} ${PODS_TARGET_SRCROOT}/../../scripts/generate-specs.sh' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",
:execution_position => :before_compile,
:show_env_vars_in_log => true
}

spec.prepare_command = "#{mkdir_command} && touch #{generated_files.reduce() { |str, file| str + " " + file }}"
spec.prepare_command = "mkdir -p #{generated_dirs.reduce("") { |str, dir| "#{str} ../../#{dir}" }} && touch #{generated_files.reduce("") { |str, filename| "#{str} ../../#{filename}" }}"
end

0 comments on commit bdfe2a5

Please sign in to comment.