Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] FBReactNativeSpec pod checksum is not stable (RN 0.64.0) #31193

Closed
thaapasa opened this issue Mar 19, 2021 · 17 comments
Closed

[iOS] FBReactNativeSpec pod checksum is not stable (RN 0.64.0) #31193

thaapasa opened this issue Mar 19, 2021 · 17 comments
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.

Comments

@thaapasa
Copy link

thaapasa commented Mar 19, 2021

Description

The SPEC CHECKSUM for FBReactNativeSpec in 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.

React Native version: 0.64.0

This happens for a clean install of React Native 0.64.0. Previous versions are not affected (pod ipc spec does not include local paths).

System:
    OS: macOS 11.2.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 5.41 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.5 - /var/folders/tq/3s__skh57_300l201pdk9gjh0000gn/T/yarn--1616135350751-0.5787894354182639/node
    Yarn: 1.22.0 - /var/folders/tq/3s__skh57_300l201pdk9gjh0000gn/T/yarn--1616135350751-0.5787894354182639/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0
      System Images: android-21 | Google APIs ARM EABI v7a, android-21 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7042882
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1
    react-native: 0.64.0 => 0.64.0
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
✨  Done in 4.48s.

Steps To Reproduce

  1. npx react-native init TestProject
  2. cd TestProject/ios && pod install

ios/Podfile.lock now has a checksum that matches pod ipc spec FBReactNativeSpec.podspec | openssl sha1 in node_modules/react-native/React/FBReactNativeSpec, and pod ipc spec FBReactNativeSpec.podspec contains local paths, such as:

{
  "script_phases": {
    "name": "Generate Specs",
    "input_files": [
      "/Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../Libraries"
    ],
    "output_files": [
      "$(DERIVED_FILE_DIR)/codegen-FBReactNativeSpec.log",
      "/Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h",
      "/Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm"
    ],
    "script": "set -o pipefail\n\nbash -l -c 'SRCS_DIR=/Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../Libraries CODEGEN_MODULES_OUTPUT_DIR=/Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec CODEGEN_MODULES_LIBRARY_NAME=FBReactNativeSpec /Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/generate-specs.sh' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",
    "execution_position": "before_compile",
    "show_env_vars_in_log": true
  },
  "prepare_command": "mkdir -p /Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec && touch /Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h /Users/thaapasa/rn/PodTestProject/node_modules/react-native/scripts/../React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm"
}

Expected Results

pod ipc spec FBReactNativeSpec.podspec should give identical output on different developer machines; i.e. not containing absolute local paths.

Snack, code example, screenshot, or link to a repository:

@thaapasa thaapasa changed the title FBReactNativeSpec pod checksum on iOS is calculated based on local directories (RN 0.64.0) [iOS] FBReactNativeSpec pod checksum is calculated based on local directories (RN 0.64.0) Mar 19, 2021
@thaapasa thaapasa changed the title [iOS] FBReactNativeSpec pod checksum is calculated based on local directories (RN 0.64.0) [iOS] FBReactNativeSpec pod checksum is not stable (RN 0.64.0) Mar 19, 2021
@thaapasa
Copy link
Author

thaapasa commented Mar 19, 2021

The culprit seems to be line 152 of node_modules/react-native/scripts/react_native_pods.rb:

  prefix = options[:path] ||= File.join(__dir__, "..")

and line 195 with another File.join(__dir__)

__dir__ here resolves to an absolute path that is part of the generated pod spec. Furthermore, prepare command shared the same prefix but runs in a different directory, so that command must also be adjusted.

If I change line 152 to

  prefix = options[:path] ||= "../../node_modules/react-native"

and line 195 to

    :script => "set -o pipefail\n\nbash -l -c '#{env_vars} CODEGEN_MODULES_LIBRARY_NAME=#{codegen_modules_library_name} ../../node_modules/react-native/scripts/generate-specs.sh' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",

and line 200 to

  spec.prepare_command = "cd ../.. && #{mkdir_command} && touch #{generated_files.reduce() { |str, file| str + " " + file }}"

it seems to work.

Generated pod spec now looks like this, and should be stable.

{
  "name": "FBReactNativeSpec",
  "version": "0.64.0",
  "summary": "-",
  "homepage": "https://reactnative.dev/",
  "license": "MIT",
  "authors": "Facebook, Inc. and its affiliates",
  "platforms": {
    "ios": "10.0"
  },
  "compiler_flags": "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32 -Wno-nullability-completeness",
  "source": {
    "git": "https://github.com/facebook/react-native.git",
    "tag": "v0.64.0"
  },
  "source_files": "**/*.{c,h,m,mm,cpp}",
  "header_dir": "FBReactNativeSpec",
  "pod_target_xcconfig": {
    "USE_HEADERMAP": "YES",
    "CLANG_CXX_LANGUAGE_STANDARD": "c++14",
    "HEADER_SEARCH_PATHS": "\"$(PODS_TARGET_SRCROOT)/React/FBReactNativeSpec\" \"$(PODS_ROOT)/RCT-Folly\""
  },
  "dependencies": {
    "RCT-Folly": [
      "2020.01.13.00"
    ],
    "RCTRequired": [
      "0.64.0"
    ],
    "RCTTypeSafety": [
      "0.64.0"
    ],
    "React-Core": [
      "0.64.0"
    ],
    "React-jsi": [
      "0.64.0"
    ],
    "ReactCommon/turbomodule/core": [
      "0.64.0"
    ]
  },
  "script_phases": {
    "name": "Generate Specs",
    "input_files": [
      "../../node_modules/react-native/Libraries"
    ],
    "output_files": [
      "$(DERIVED_FILE_DIR)/codegen-FBReactNativeSpec.log",
      "../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h",
      "../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm"
    ],
    "script": "set -o pipefail\n\nbash -l -c 'SRCS_DIR=../../node_modules/react-native/Libraries CODEGEN_MODULES_OUTPUT_DIR=../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec CODEGEN_MODULES_LIBRARY_NAME=FBReactNativeSpec ../../node_modules/react-native/scripts/generate-specs.sh' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",
    "execution_position": "before_compile",
    "show_env_vars_in_log": true
  },
  "prepare_command": "cd ../.. && mkdir -p ../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec && touch ../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h ../../node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm"
}

@FreekVanDooren
Copy link

Hey! We are running into the same and having failing builds because of this, as the Pods-folder is versioned in our project as recommended here: https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control. We can of course unversion the Pods-folder and add cd ios && pod install as a postinstall script to package.json, which leaves only the checksum to change every time. However, we are hesitant to do so, since this project has survived for a few years with versioned Pods. So can anyone recommend for or against this approach?

@thaapasa is there a way to apply your fix on postinstall? I am unaware if npm offers a different way of doing this, so I'm thinking I could create a shell script to apply your change to the right line that would run post install. That or do it once, run pod install and hope that I never run into an issue because I forgot I did that.

@thaapasa
Copy link
Author

@thaapasa is there a way to apply your fix on postinstall? I am unaware if npm offers a different way of doing this, so I'm thinking I could create a shell script to apply your change to the right line that would run post install. That or do it once, run pod install and hope that I never run into an issue because I forgot I did that.

Someone suggested using patch-package (https://www.npmjs.com/package/patch-package), but I think I'll go with a custom postinstall script with some sort of sed spell or similar to fix that path.

@thaapasa
Copy link
Author

Made a PR for this small fix: #31195

@thaapasa
Copy link
Author

This is a duplicate: #31121 (sorry, did not find that one before)

@thaapasa
Copy link
Author

thaapasa commented Mar 19, 2021

For reference, this is what I now run to fix this bug (and a bug with nvm) in yarn postinstall script:

#!/bin/bash

OS=`uname`

echo "Fixing RN 0.64.0 bugs:"
cd node_modules/react-native/scripts
echo "- unset PREFIX in find-node.sh"
if [ `cat find-node.sh | grep 'unset PREFIX' | wc -l` -lt 1 ]
then
  cp find-node.sh tmp
  head -n 1 tmp >find-node.sh
  echo "unset PREFIX" >>find-node.sh
  tail -n +2 tmp >>find-node.sh
  rm tmp
fi

if [ "$OS" = 'Darwin' ]
then
  # for MacOS; cannot install Pods on Win/Linux
  echo "- switch to relative paths in react_native_pods.rb "
  sed -i '' -e "s/File[.]join[(]__dir__, \"[.][.]\"[)]/\"..\/..\/node_modules\/react-native\"/" react_native_pods.rb
  sed -i '' -e "s/#{File[.]join[(]__dir__, \"generate-specs.sh\"[)]}/..\/..\/node_modules\/react-native\/scripts\/generate-specs.sh/" react_native_pods.rb
  sed -i '' -e "s/spec[.]prepare_command = \"#/spec.prepare_command = \"cd ..\/.. \&\& #/" react_native_pods.rb
fi

cd - >/dev/null

@FreekVanDooren
Copy link

FreekVanDooren commented Mar 19, 2021

@thaapasa I only just noticed when trying to apply the same fix, there is still an absolute path left in the value of "script" all the way towards the end:

/Users/thaapasa/project/telia/dot/app/node_modules/react-native/scripts/generate-specs.sh

But maybe it's not a problem for the way you've constructed your script.

@thaapasa
Copy link
Author

@thaapasa I only just noticed when trying to apply the same fix, there is still an absolute path left in the value of "script" all the way towards the end:

@FreekVanDooren, actually that is a problem, since it's in the podspec and the sha is calculated from that. Thanks for noticing that, I had missed that altogether. I'll see if that can be fixed as well.

@thaapasa
Copy link
Author

I fixed the path to generate-specs.sh now as well (see updated comments here and the linked PR).
@FreekVanDooren this should now create a stable podspec...

@CHNB128
Copy link

CHNB128 commented Mar 24, 2021

Thanks, @thaapasa, this comment was very helpful.
Actually, I made a patch file for react-native, to not replace existing postinstall script.

whyer added a commit to kolplattformen/skolplattformen that referenced this issue May 2, 2021
The hash in Podfile.lock keep changing on different developer machines. That is because the file the hash is based on contains absolute paths.
See facebook/react-native#31193 for more info.

This commit adds a postinstall script that fixes that bug.
pxpeterxu pushed a commit to wanderlog/react-native that referenced this issue May 4, 2021
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
danilobuerger pushed a commit to feastr/react-native that referenced this issue May 13, 2021
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
savv pushed a commit to savv/react-native-savv that referenced this issue May 18, 2021
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798

(cherry picked from commit bdfe2a5)
@zeemyself
Copy link

I have create patch-package for RN version 0.64.2 for doesn't want to use sed and script

https://gist.github.com/zeemyself/69e2dce7cd88b0a1cb6dbcec54d1f265

@milesj
Copy link

milesj commented Jul 15, 2021

Still running into this with 0.64.2. Why was this issue closed if it still persists?

[!] There were changes to the lockfile in deployment mode:
--
  | SPEC CHECKSUMS:
  | FBReactNativeSpec:
  | New Lockfile: 76cc58820784ccba47428a8eac3150f350075fe7
  | Old Lockfile: b2708f0fc27435e1bab6b324e66bd01c99c498b9

Is the only solution to patch over node_modules/react-native?

Ashoat added a commit to CommE2E/comm that referenced this issue Jul 16, 2021
Summary: This fixes [this GitHub issue](facebook/react-native#31193) by pulling in [the commit](facebook/react-native@bdfe2a5) that resolved it.

Test Plan: `pod install`

Reviewers: atul

Reviewed By: atul

Subscribers: KatPo, palys-swm, Adrian

Differential Revision: https://phabricator.ashoat.com/D1739
hsource added a commit to wanderlog/react-native that referenced this issue Jul 16, 2021
Taken from facebook@bdfe2a5

Avoid encoding local path in Podfile.lock

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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
@swushi
Copy link

swushi commented Jul 27, 2021

We are also still running into this issue with our team, and are constantly ping-ponging changes to our Podfile.lock with just this one line.

Kudo pushed a commit to expo/react-native that referenced this issue Aug 9, 2021
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
(cherry picked from commit bdfe2a5)
@plaa
Copy link

plaa commented Aug 27, 2021

We are still facing this in 0.64.2 as others have stated. Can this issue be re-opened or should a new one be created?

@sregg
Copy link

sregg commented Sep 8, 2021

Is this being fixed in 0.65?

@aliwatters
Copy link

#32180
#31121

terribleben pushed a commit to castle-xyz/react-native that referenced this issue Nov 3, 2021
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
voisinhugo pushed a commit to pass-culture/pass-culture-app-native that referenced this issue Nov 17, 2021
douglowder pushed a commit to react-native-tvos/react-native-tvos that referenced this issue Jan 9, 2022
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 facebook/react-native#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
(cherry picked from commit bdfe2a5)
mjgallag pushed a commit to thunkable/react-native that referenced this issue Mar 18, 2022
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 facebook#31193

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

Reviewed By: fkgozali

Differential Revision: D27754337

fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798
@AdamGerthel
Copy link

Is this being fixed in 0.65?

I don't think so. We used this script to fix it as a package.postinstall, but it seems to have stopped working after upgrading to RN 0.66.4 so we're back at square one.

@facebook facebook locked as resolved and limited conversation to collaborators Apr 16, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests