Bug 3278 - hg-2.1 on OSX Lion - compile error, xcodebuild
Summary: hg-2.1 on OSX Lion - compile error, xcodebuild
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-18 23:48 UTC by nibbles
Modified: 2012-05-13 04:49 UTC (History)
10 users (show)

See Also:
Python Version: ---


Attachments
(34 bytes, text/x-diff)
2012-02-19 12:05 UTC, Greg Ward
Details

Note You need to log in before you can comment on or make changes to this bug.
Description nibbles 2012-02-18 23:48 UTC
setup.py calls xcodebuild which can return an error or versionless path,
causing compile to fail on OSX Lion, if the user has only the new
command_line_tools_for_xcode.dmg not the full XCode-4.3 (which they don't
need anymore).  A clean install of Lion with only the command line tools
will never work with setup.py.


==> make PREFIX=/usr/local/Cellar/mercurial/2.1 build
python setup.py  build
Traceback (most recent call last):
  File "setup.py", line 455, in <module>
    version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0].splitlines()[0]
IndexError: list index out of range
make: *** [build] Error 1



Here are the details:
======================

On Feb 16, 2012, Apple released XCode-4.3 for OSX Lion, which does not
contain the command line tools (CLT) to build open source software.

An OSX Lion user can get those tools in one of two ways:

1) Install the CLT inside of the XCode-4.3 preferences window.
2) or not install the massive XCode-4.3 at all, but rather only install the
small CLT archive from Apple's developer website,
https://developer.apple.com/downloads/index.action (requires free
registration like this bug tracker does).

When an OSX Lion user only installs the CLT-4.3, xcodebuild -version will
return an error because the path is unset, or it might return a path with no
SDK number in it.  It can never return a path with the version in it because
there is no SDKs folder in this situation where there's no XCode-4.3 full
install.

Hg's setup.py does not handle the error or versionless path.  Compile fails.

The program you call, xcodebuild, reads a text file btw.

    $ ls -l /usr/share/xcode-select/xcode_dir_path
    -rw-r--r--  1 root  wheel      2 Feb 18 21:21 xcode_dir_path

Ok many thanks if you can handle the case where xcodebuild returns garbage.
2bits @ homebrew
Comment 1 Greg Ward 2012-02-19 11:59 UTC
Can you tell us what xcodebuild -version *does* return on your machine? I.e.
is it empty, or just something that setup.py fails to parse?
Comment 2 Greg Ward 2012-02-19 12:05 UTC
Here is an attempt at a patch; completely untested since I don't have access
to a Mac running Lion. Seems pretty straightforward though. Please test and
let me know if it works!
Comment 3 nibbles 2012-02-19 13:00 UTC
Testing your patch.  In the meantime the output you might see would be:

1) If their xcode-select path is unset, meaning the file xcode_dir_path does
not exist:

   $ xcodebuild -version
   xcodebuild: error: developer tools not installed; download from
http://developer.apple.com


2) If their xcode-select path is set to some folder random folder that exists,
   let's say /Developer/some/b0rk4ge/path

   $ xcodebuild -version
   error: can't exec '/Developer/some/b0rk4ge/path/usr/bin/xcodebuild' (No
such file or directory)

3) If their xcode-select path is set to the correct place because they have
the full XCode-4.3,

   $ xcodebuild -version
   /Applications/Xcode.app/Contents/Developer

4) if their xcode-select path is set to the correct place for earlier
XCode-4 on Leopard, Snow Lep, or Lion:

    $ xcodebuild -version
    /Developer/SDKs/MacOSX10.[567].sdk

That last one might be a 5, a 6, or a 7 I suppose, but that's the case you
already handle ok.
I will test your patch now.
Comment 4 nibbles 2012-02-19 14:15 UTC
The patch works, and hg-2.1 compiles again on OSX Lion 10.7.3 using
Clang-3.1.318 or llvm-gcc-4.2.1.5658 from the CLT-4.3.

I'll clarify that no XCode-4.3 user nor CLT-4.3 user will have their
xcode_dir_path set correctly because both Apple installers leave it alone. 
In that respect I guess this widespread in the future.


hg fails a few tests in make check, though.  So I'll make a separate issue
for those without objection.

Failed test-check-code-hg.t: output changed
Failed test-mq.t: output changed
Failed test-subrepo-git.t: output changed

The second one was minor I suppose:

       $ sed -i'' $HGRCPATH -e 's/secret=true/secret=false/'
    +  sed: -i may not be used with stdin

Thank you for your help.
Comment 5 Patrick Mézard 2012-02-19 14:28 UTC
FWIW, the sed error was fixed in stable by 3b9c18ed9985
Comment 6 nibbles 2012-02-19 15:08 UTC
Ok that's good news. I just installed Python-2.7.2 and ran make check on
HEAD.  Similar issues that look cosmetic due to unexpected more thorough
warning messages to the user, but the functionality seems intact.

Failed test-casecollision-merge.t: output changed
Failed test-casefolding.t: output changed
Failed test-check-code-hg.t: output changed  <== That one it can't find .hg
Failed test-subrepo-git.t: output changed

Thanks again.
Comment 7 nibbles 2012-02-19 15:35 UTC
I'm really sorry that I made errors trying to tell you what xcodebuild
-version might return.
I couldn't test the cases where it works as expected, because I don't have
the full XCode anymore.
I suppose you already handle those, but to be thorough I made some corrections:


3) If their xcode-select path is set to the correct place because they have
the full XCode-4.3,

    $ xcode-select -print-path
    /Applications/Xcode.app/Contents/Developer
    $ xcodebuild -version
    ...I don't know what this returns...

4) if their xcode-select path is set to the correct place for earlier
XCode-4 on Leopard, Snow Lep, or Lion:

    $ xcode-select -print-path
    /Developer
    $ xcodebuild -version
    ...I don't know what this returns but you already handle it...
Comment 8 nibbles 2012-02-26 17:34 UTC
The is the expected output on OSX Lion with the full XCode-4.3.

$ xcode-select -print-path
/Applications/Xcode.app

$ xcodebuild -version
Xcode 4.3
Build version 4E109
Comment 9 HG Bot 2012-02-28 22:00 UTC
Fixed by http://selenic.com/repo/hg/rev/82ce91a9fd94
Greg Ward <greg@gerg.ca>
setup: handle output from Apple's Xcode 4.3 better (issue3277)

(please test the fix)
Comment 10 nibbles 2012-02-29 19:55 UTC
It works for the case I asked it to fix, but it breaks another case.
Here the output of the compiler error for 32bit OSX 10.6.8 Snow Leopard,
when 82ce91a9fd94 is applied to v2.1:


==> make PREFIX=/usr/local/Cellar/mercurial/2.1 build
make PREFIX=/usr/local/Cellar/mercurial/2.1 build
python setup.py  build
Traceback (most recent call last):
  File "setup.py", line 457, in <module>
    version = version.splitlines()[0]
AttributeError: 'list' object has no attribute 'splitlines'
make: *** [build] Error 1


He then said he thought it called str.splitplines() one too many times.
Comment 11 nibbles 2012-02-29 20:27 UTC
The failing test system, 32bit 10.6.8 OSX, I asked and got his output for you:


$ xcodebuild -version
Xcode 4.2
Build version 4C199
Comment 12 nibbles 2012-03-01 00:37 UTC
In this issue I've written too many errors.

Problem: On OSX, make setup.py handle errors from "xcodebuild -version"

Possible return values from "xcodebuild -version"

  1) Nothing. It will hang forever (if xcode_dir_path = / )

  2) xcodebuild: error: developer tools not installed; download from
http://developer.apple.com

  3) Xcode 4.3
     Build version 4E109

  4) Xcode 4.2
     Build version 4C199

  5) Xcode 4.0.2
     Build version 4A2002a

  6) Xcode 4.0
     Build version 4A1006

  7) Xcode 4.0
     Build version 4A304a

  8) Xcode 3.2.6
     XcodeComponent versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
     BuildVersion: 10M2518

  9) Xcode 3.2.4
     Component versions: DevToolsCore-1705.0; DevToolsSupport-1591.0
     BuildVersion: 10M2309

It's not exhaustive, but I'm confident it's better.
Comment 13 Christian Ebert 2012-03-01 07:26 UTC
The fix for 10.7 (?) breaks on 10.5.8:

$ make build
python setup.py  build
Traceback (most recent call last):
  File "setup.py", line 457, in <module>
    version = version.splitlines()[0]
AttributeError: 'list' object has no attribute 'splitlines'
make: *** [build] Error 1
$ /usr/bin/xcodebuild -version
Xcode 3.1.4
Component versions: DevToolsCore-1204.0; DevToolsSupport-1186.0
BuildVersion: 9M2809
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.5.8
BuildVersion:	9L30
Comment 14 Matt Mackall 2012-03-01 17:35 UTC
Fix broken, leaked into 2.1.1. Joy.
Comment 15 HG Bot 2012-03-02 15:00 UTC
Fixed by http://selenic.com/repo/hg/rev/5536770b3c88
Brendan Cully <brendan@kublai.com>
setup.py: don't call splitlines twice on the output of xcodebuild (issue3277)

(please test the fix)
Comment 16 Kevin Bullock 2012-03-02 15:06 UTC
Works here (OS X Lion 10.7.3, Xcode 4.2.1 Build version 4D502).
Comment 17 nibbles 2012-03-02 18:26 UTC
Your patch works.  All systems compile Hg again, which is very much appreciated.
Comment 18 Christian Ebert 2012-03-02 18:30 UTC
Positive confirmation of Brendan's fix on 10.5.8 too.
Comment 19 nibbles 2012-03-02 18:32 UTC
Your patch also works for one more odd case I remembered:


  10) $ xcodebuild -version
      error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or
directory)
Comment 20 Dirkjan Ochtman 2012-03-05 01:26 UTC
Would this perhaps be worthy of a quick 2.1.2? It seems like there's going
to be a lot of duplicates flowing in over the coming 26 days.
Comment 21 Bugzilla 2012-05-12 09:28 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:28 EDT  ---

This bug was previously known as _bug_ 3277 at http://mercurial.selenic.com/bts/issue3277
Imported an attachment (id=1640)