Skip to content

Automatically handle Xcode CLT install if needed on MacOS #325

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

Closed
zbeekman opened this issue Jan 31, 2017 · 1 comment · Fixed by #419
Closed

Automatically handle Xcode CLT install if needed on MacOS #325

zbeekman opened this issue Jan 31, 2017 · 1 comment · Fixed by #419

Comments

@zbeekman
Copy link
Collaborator

See, for example how the homebrew installer handles this.

I have written a function to test if we need to install the CLT, but am wondering at what point do we call it and do the installation. I'm guessing every single one of our dependencies probably needs the Xcode CLT on MacOS, so, I guess we put it near the beginning of install.sh? Here is a function to detect if CLT are missing:

install_xcodeCLT () {
    if [[ "${OSTYPE}" != [Dd][Aa][Rr][Ww][Ii][Nn]* ]]; then
        echo "false"
    else
        local xcode_dir
        xcode_dir="$(/usr/bin/xcode-select -print-path 2>/dev/null)"
        if [[ -z "${xcode_dir}" ]] || ! [[ -x "${xcode_dir}/usr/bin/make" ]] ; then
            echo "true"
        else
            echo "false"
	fi
    fi
}

Works safely on other systems.

Here is the clever magic that homebrew does to get CLT installed and the EULA signed: (from https://github.com/Homebrew/install/blob/master/install#L259-L285)

if should_install_command_line_tools?
  ohai "Searching online for the Command Line Tools"
  # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
  clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
  sudo "/usr/bin/touch", clt_placeholder
  clt_label = `softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1`.chomp
  ohai "Installing #{clt_label}"
  sudo "/usr/sbin/softwareupdate", "-i", clt_label
  sudo "/bin/rm", "-f", clt_placeholder
  sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
end

# Headless install may have failed, so fallback to original 'xcode-select' method
if should_install_command_line_tools? && STDIN.tty?
  ohai "Installing the Command Line Tools (expect a GUI popup):"
  sudo "/usr/bin/xcode-select", "--install"
  puts "Press any key when the installation has completed."
  getc
  sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
end

abort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success?
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
    sudo xcodebuild -license
EOABORT

My ruby, while poor, is good enough to translate that to bash, I believe... or come up with our own version.

@rouson
Copy link
Member

rouson commented Jul 18, 2017

@zbeekman Possibly we can knock this out relatively quickly in a pair programming session or mark it as "won't fix" and close it. I'll bel glad to help with modifying the installation scripts if we decide to fix this. Thoughts?

zbeekman added a commit that referenced this issue Jul 18, 2017
 On macOS, add logic to install script that will install Xcode command
 line tools. Most logic cribbed from Homebrew installer.

 Fixes #325
zbeekman added a commit that referenced this issue Jul 18, 2017
 On macOS, add logic to install script that will install Xcode command
 line tools. Most logic cribbed from Homebrew installer.

 Fixes #325
zbeekman added a commit that referenced this issue Jul 19, 2017
Add logic to install Xcode-CLT if needed

 - Fixes #325
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants