Skip to content

Commit 5742431

Browse files
authored
Merge pull request #2232 from NativeScript/jasssonpet/setup-osx
Updating macOS setup script with latest macOS/package requirements
2 parents a60eabd + 465151e commit 5742431

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

setup/native-script.rb

+26-13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def execute(script, warning_message, run_as_root = false)
4747
unless result
4848
STDERR.puts "WARNING: " + warning_message
4949
end
50+
51+
return result
5052
end
5153

5254
def install(program_name, message, script, run_as_root = false, show_all_option = true)
@@ -73,16 +75,25 @@ def install(program_name, message, script, run_as_root = false, show_all_option
7375
execute(script, program_name + " not installed", run_as_root)
7476
end
7577

78+
def install_environment_variable(name, value)
79+
ENV[name] = value
80+
81+
execute("echo \"export #{name}=#{value}\" >> ~/.profile", "Unable to set #{name}")
82+
83+
if File.exist?(File.expand_path("~/.zshrc"))
84+
execute("echo \"export #{name}=#{value}\" >> ~/.zprofile", "Unable to set #{name}")
85+
end
86+
end
87+
7688
# Actually installing all other dependencies
7789
install("Homebrew", "Installing Homebrew...", 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</dev/null', false, false)
7890

79-
if !(`brew --version`.include? "git revision")
80-
puts "Homebrew is not installed or not configured properly. Download it from http://brew.sh/, install, set it up and run this script again."
91+
if !(execute("brew --version", "Homebrew is not installed or not configured properly. Download it from http://brew.sh/, install, set it up and run this script again."))
8192
exit
8293
end
8394

8495
install("Java SE Development Kit", "Installing the Java SE Development Kit... This might take some time, please, be patient. (You will be prompted for your password)", 'brew cask install java', false, false)
85-
install("Android SDK", "Installing Android SDK", 'brew install android-sdk')
96+
install("Android SDK", "Installing Android SDK", 'brew install android-sdk', false)
8697

8798
unless ENV["ANDROID_HOME"]
8899
require 'pathname'
@@ -98,18 +109,20 @@ def install(program_name, message, script, run_as_root = false, show_all_option
98109
end
99110
end
100111

101-
ENV["ANDROID_HOME"] = android_home
102-
execute('echo "export ANDROID_HOME=%s" >> ~/.profile' % ENV["ANDROID_HOME"], "Unable to set ANDROID_HOME")
112+
install_environment_variable("ANDROID_HOME", android_home)
103113
end
104114

105115
unless ENV["JAVA_HOME"]
106-
execute('echo "export JAVA_HOME=$(/Library/Java/Home)" >> ~/.profile', "Unable to set JAVA_HOME")
116+
install_environment_variable("JAVA_HOME", "/Library/Java/Home")
107117
end
108118

109119
# the -p flag is set in order to ensure zero status code even if the directory exists
110120
execute("mkdir -p ~/.cocoapods", "There was a problem in creating ~/.cocoapods directory")
111-
install("xcodeproj", "Installing xcodeproj... This might take some time, please, be patient.", 'gem install xcodeproj -V', true)
121+
# CocoaPods already has a dependency to xcodeproj and also has a dependency to a lower version of activesupport
122+
# which works with Ruby 2.0 that comes as the macOS default, so these two installations should be in this order.
123+
# For more information see: https://github.com/CocoaPods/Xcodeproj/pull/393#issuecomment-231055159
112124
install("CocoaPods", "Installing CocoaPods... This might take some time, please, be patient.", 'gem install cocoapods -V', true)
125+
install("xcodeproj", "Installing xcodeproj... This might take some time, please, be patient.", 'gem install xcodeproj -V', true)
113126

114127
puts "Configuring your system for Android development... This might take some time, please, be patient."
115128
# Note that multiple license acceptances may be required, hence the multiple commands
@@ -129,17 +142,17 @@ def install(program_name, message, script, run_as_root = false, show_all_option
129142
if gets.chomp.downcase == "y"
130143
puts "Do you want to install HAXM (Hardware accelerated Android emulator)? (y/n)"
131144
if gets.chomp.downcase == "y"
132-
execute("echo y | $ANDROID_HOME/tools/android update sdk --filter extra-intel-Hardware_Accelerated_Execution_Manager --all --no-ui", error_msg)
145+
execute("echo y | #{android_executable} update sdk --filter extra-intel-Hardware_Accelerated_Execution_Manager --all --no-ui", error_msg)
133146

134147
haxm_silent_installer = File.join(ENV["ANDROID_HOME"], "extras", "intel", "Hardware_Accelerated_Execution_Manager", "silent_install.sh")
135148
execute("#{haxm_silent_installer}", "There seem to be some problems with the Android configuration")
136149

137-
execute("echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-x86-android-23 --all --no-ui", error_msg)
138-
execute("echo no | $ANDROID_HOME/tools/android create avd -n Emulator-Api23-Default -t android-23 --abi default/x86 -c 12M -f", error_msg)
150+
execute("echo y | #{android_executable} update sdk --filter sys-img-x86-android-23 --all --no-ui", error_msg)
151+
execute("echo no | #{android_executable} create avd -n Emulator-Api23-Default -t android-23 --abi default/x86 -c 12M -f", error_msg)
139152
else
140-
execute("echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-armeabi-v7a-android-23 --all --no-ui", error_msg)
141-
execute("echo no | $ANDROID_HOME/tools/android create avd -n Emulator-Api23-Default -t android-23 --abi default/armeabi-v7a -c 12M -f", error_msg)
153+
execute("echo y | #{android_executable} update sdk --filter sys-img-armeabi-v7a-android-23 --all --no-ui", error_msg)
154+
execute("echo no | #{android_executable} create avd -n Emulator-Api23-Default -t android-23 --abi default/armeabi-v7a -c 12M -f", error_msg)
142155
end
143156
end
144157

145-
puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile. Restart the terminal to use them."
158+
puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile/.zprofile. Restart the terminal to use them."

0 commit comments

Comments
 (0)