1# Copyright (c) Meta Platforms, Inc. and affiliates.
2#
3# This source code is licensed under the MIT license found in the
4# LICENSE file in the root directory of this source tree.
5
6require_relative './utils.rb'
7
8# It sets up the JavaScriptCore and JSI pods.
9#
10# @parameter react_native_path: relative path to react-native
11# @parameter fabric_enabled: whether Fabirc is enabled
12def setup_jsc_ABI48_0_0!(react_native_path: "../node_modules/react-native", fabric_enabled: false)
13    pod 'ABI48_0_0React-jsi', :path => "#{react_native_path}/ReactCommon/jsi", :project_name => 'ABI48_0_0'
14    pod 'ABI48_0_0React-jsc', :path => "#{react_native_path}/ReactCommon/jsc", :project_name => 'ABI48_0_0'
15    if fabric_enabled
16        pod 'ABI48_0_0React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsc", :project_name => 'ABI48_0_0'
17    end
18end
19
20# It sets up the Hermes and JSI pods.
21#
22# @parameter react_native_path: relative path to react-native
23# @parameter fabric_enabled: whether Fabirc is enabled
24def setup_hermes_ABI48_0_0!(react_native_path: "../node_modules/react-native", fabric_enabled: false)
25    # The following captures the output of prepare_hermes for use in tests
26
27    pod 'ABI48_0_0React-jsi', :path => "#{react_native_path}/ReactCommon/jsi", :project_name => 'ABI48_0_0'
28
29    if File.exist?("#{react_native_path}/sdks/hermes-engine/destroot")
30      pod 'ABI48_0_0hermes-engine', :path => "#{react_native_path}/sdks/hermes-engine", :project_name => 'ABI48_0_0'
31    else
32      pod 'ABI48_0_0hermes-engine', :podspec => "#{react_native_path}/sdks/hermes-engine/ABI48_0_0hermes-engine.podspec", :project_name => 'ABI48_0_0'
33    end
34    pod 'ABI48_0_0React-hermes', :path => "#{react_native_path}/ReactCommon/hermes", :project_name => 'ABI48_0_0'
35    pod 'libevent', '~> 2.1.12'
36end
37
38def add_copy_hermes_framework_script_phase(installer, react_native_path)
39    utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
40    phase_name = "[RN] Copy Hermes Framework"
41    project = installer.generated_aggregate_targets.first.user_project
42    target = project.targets.first
43    if target.shell_script_build_phases.none? { |phase| phase.name == phase_name }
44        phase = target.new_shell_script_build_phase(phase_name)
45        phase.shell_script = ". #{utils_dir}/copy-hermes-xcode.sh"
46        project.save()
47    end
48end
49
50def remove_copy_hermes_framework_script_phase(installer, react_native_path)
51    utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
52    phase_name = "[RN] Copy Hermes Framework"
53    project = installer.generated_aggregate_targets.first.user_project
54    target = project.native_targets.first
55    target.shell_script_build_phases.each do |phase|
56        if phase.name == phase_name
57            target.build_phases.delete(phase)
58        end
59    end
60    project.save()
61end
62
63def remove_hermesc_build_dir(react_native_path)
64    %x(rm -rf #{react_native_path}/sdks/hermes-engine/build_host_hermesc)
65end
66
67def is_building_hermes_from_source(react_native_version, react_native_path)
68    if ENV['HERMES_ENGINE_TARBALL_PATH'] != nil
69        return false
70    end
71
72    isInMain = react_native_version.include?('1000.0.0')
73
74    hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
75    isInCI = ENV['REACT_NATIVE_CI'] === 'true'
76
77    isReleaseBranch = File.exist?(hermestag_file) && isInCI
78
79
80    return isInMain || isReleaseBranch
81end
82