From c2604bfecea58641e4b299ae09d7ccb5fe58558c Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Fri, 16 Jul 2021 14:01:40 -0700 Subject: [PATCH] 0.64-only fix: Cherry-picked fix to Podfile.lock changing Taken from https://github.com/facebook/react-native/commit/bdfe2a51791046c4e6836576e08655431373ed67 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 https://github.com/facebook/react-native/issues/31193 Changelog: [Internal] [Codegen] Avoid encoding local path in Podfile.lock Reviewed By: fkgozali Differential Revision: D27754337 fbshipit-source-id: 2f5607d4e1ce21489f28f394cb852c36cace6798 --- .../accumulators/droppable_accumulator.hpp | 328 ++++++++++++++++++ scripts/generate-specs.sh | 55 +-- scripts/react_native_pods.rb | 43 ++- 3 files changed, 380 insertions(+), 46 deletions(-) create mode 100644 RNTester/Pods/boost-for-react-native/boost/accumulators/framework/accumulators/droppable_accumulator.hpp diff --git a/RNTester/Pods/boost-for-react-native/boost/accumulators/framework/accumulators/droppable_accumulator.hpp b/RNTester/Pods/boost-for-react-native/boost/accumulators/framework/accumulators/droppable_accumulator.hpp new file mode 100644 index 00000000000000..0e882b5c35d10e --- /dev/null +++ b/RNTester/Pods/boost-for-react-native/boost/accumulators/framework/accumulators/droppable_accumulator.hpp @@ -0,0 +1,328 @@ +/////////////////////////////////////////////////////////////////////////////// +// droppable_accumulator.hpp +// +// Copyright 2005 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005 +#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005 + +#include +#include +#include +#include +#include // for feature_of +#include // for accumulator + +namespace boost { namespace accumulators +{ + + template + struct droppable_accumulator; + + namespace detail + { + /////////////////////////////////////////////////////////////////////////////// + // add_ref_visitor + // a fusion function object for add_ref'ing accumulators + template + struct add_ref_visitor + { + explicit add_ref_visitor(Args const &args) + : args_(args) + { + } + + template + void operator ()(Accumulator &acc) const + { + typedef typename Accumulator::feature_tag::dependencies dependencies; + + acc.add_ref(this->args_); + + // Also add_ref accumulators that this feature depends on + this->args_[accumulator].template + visit_if >( + *this + ); + } + + private: + add_ref_visitor &operator =(add_ref_visitor const &); + Args const &args_; + }; + + template + add_ref_visitor make_add_ref_visitor(Args const &args) + { + return add_ref_visitor(args); + } + + /////////////////////////////////////////////////////////////////////////////// + // drop_visitor + // a fusion function object for dropping accumulators + template + struct drop_visitor + { + explicit drop_visitor(Args const &args) + : args_(args) + { + } + + template + void operator ()(Accumulator &acc) const + { + if(typename Accumulator::is_droppable()) + { + typedef typename Accumulator::feature_tag::dependencies dependencies; + + acc.drop(this->args_); + // Also drop accumulators that this feature depends on + this->args_[accumulator].template + visit_if >( + *this + ); + } + } + + private: + drop_visitor &operator =(drop_visitor const &); + Args const &args_; + }; + + template + drop_visitor make_drop_visitor(Args const &args) + { + return drop_visitor(args); + } + } + + ////////////////////////////////////////////////////////////////////////// + // droppable_accumulator_base + template + struct droppable_accumulator_base + : Accumulator + { + typedef droppable_accumulator_base base; + typedef mpl::true_ is_droppable; + typedef typename Accumulator::result_type result_type; + + template + droppable_accumulator_base(Args const &args) + : Accumulator(args) + , ref_count_(0) + { + } + + droppable_accumulator_base(droppable_accumulator_base const &that) + : Accumulator(*static_cast(&that)) + , ref_count_(that.ref_count_) + { + } + + template + void operator ()(Args const &args) + { + if(!this->is_dropped()) + { + this->Accumulator::operator ()(args); + } + } + + template + void add_ref(Args const &) + { + ++this->ref_count_; + } + + template + void drop(Args const &args) + { + BOOST_ASSERT(0 < this->ref_count_); + if(1 == this->ref_count_) + { + static_cast *>(this)->on_drop(args); + } + --this->ref_count_; + } + + bool is_dropped() const + { + return 0 == this->ref_count_; + } + + private: + int ref_count_; + }; + + ////////////////////////////////////////////////////////////////////////// + // droppable_accumulator + // this can be specialized for any type that needs special handling + template + struct droppable_accumulator + : droppable_accumulator_base + { + template + droppable_accumulator(Args const &args) + : droppable_accumulator::base(args) + { + } + + droppable_accumulator(droppable_accumulator const &that) + : droppable_accumulator::base(*static_cast(&that)) + { + } + }; + + ////////////////////////////////////////////////////////////////////////// + // with_cached_result + template + struct with_cached_result + : Accumulator + { + typedef typename Accumulator::result_type result_type; + + template + with_cached_result(Args const &args) + : Accumulator(args) + , cache() + { + } + + with_cached_result(with_cached_result const &that) + : Accumulator(*static_cast(&that)) + , cache() + { + if(that.has_result()) + { + this->set(that.get()); + } + } + + ~with_cached_result() + { + // Since this is a base class of droppable_accumulator_base, + // this destructor is called before any of droppable_accumulator_base's + // members get cleaned up, including is_dropped, so the following + // call to has_result() is valid. + if(this->has_result()) + { + this->get().~result_type(); + } + } + + template + void on_drop(Args const &args) + { + // cache the result at the point this calculation was dropped + BOOST_ASSERT(!this->has_result()); + this->set(this->Accumulator::result(args)); + } + + template + result_type result(Args const &args) const + { + return this->has_result() ? this->get() : this->Accumulator::result(args); + } + + private: + with_cached_result &operator =(with_cached_result const &); + + void set(result_type const &r) + { + ::new(this->cache.address()) result_type(r); + } + + result_type const &get() const + { + return *static_cast(this->cache.address()); + } + + bool has_result() const + { + typedef with_cached_result this_type; + typedef droppable_accumulator_base derived_type; + return static_cast(this)->is_dropped(); + } + + aligned_storage cache; + }; + + namespace tag + { + template + struct as_droppable + { + typedef droppable type; + }; + + template + struct as_droppable > + { + typedef droppable type; + }; + + ////////////////////////////////////////////////////////////////////////// + // droppable + template + struct droppable + : as_feature::type + { + typedef typename as_feature::type feature_type; + typedef typename feature_type::dependencies tmp_dependencies_; + + typedef + typename mpl::transform< + typename feature_type::dependencies + , as_droppable + >::type + dependencies; + + struct impl + { + template + struct apply + { + typedef + droppable_accumulator< + typename mpl::apply2::type + > + type; + }; + }; + }; + } + + // make droppable work + template + struct as_feature > + { + typedef tag::droppable::type> type; + }; + + // make droppable work with non-void weights (should become + // droppable + template + struct as_weighted_feature > + { + typedef tag::droppable::type> type; + }; + + // for the purposes of feature-based dependency resolution, + // droppable provides the same feature as Foo + template + struct feature_of > + : feature_of + { + }; + + // Note: Usually, the extractor is pulled into the accumulators namespace with + // a using directive, not the tag. But the droppable<> feature doesn't have an + // extractor, so we can put the droppable tag in the accumulators namespace + // without fear of a name conflict. + using tag::droppable; + +}} // namespace boost::accumulators + +#endif diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index d19a87f6932180..d9c42a73cdd890 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -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 @@ -27,13 +27,13 @@ set -e THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX) RN_DIR=$(cd "$THIS_DIR/.." && pwd) - -# find node path -source "$RN_DIR/scripts/find-node.sh" - NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}" USE_FABRIC="${USE_FABRIC:-0}" +# Find path to Node +# shellcheck source=/dev/null +source "$RN_DIR/scripts/find-node.sh" + cleanup () { set +e rm -rf "$TEMP_DIR" @@ -46,31 +46,40 @@ 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" + CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" + CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen" + 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 + exit 1 + fi + # Make sure we're in the directory where the React Native binary lives. # Works around issues where the user's .bashrc has a "cd XXX" # and should be removable in 0.65 since this script has its logic # changed significantly cd "$RN_DIR/../.." || exit 1 - 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 describe "Building react-native-codegen package" bash "$CODEGEN_PATH/scripts/oss/build.sh" @@ -81,14 +90,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 -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 '{}' "$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.' } diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index db9a34aaa8c77e..7fc2d51a50ec77 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -164,33 +164,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", @@ -201,19 +199,18 @@ 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 # Local method for the Xcode 12.5 fix