HomePhabricator

Fix codesign command with cmake.
AuditedrL250335

Description

Fix codesign command with cmake.

Summary:
Looks like having a space in the Xcode path triggers this bug. We need
to use cmake -E env FOO=bar [COMMAND] to set the environment instead.

I am using cmake 3.3.1 and ninja 1.6.0 and I get this:

[2681/2756] Linking CXX executable bin/debugserver
FAILED: : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -std=c++11 -fcolor-diagnostics -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated-register -Wno-vla-extension  -fno-exceptions -fno-rtti -Wno-gnu-zero-variadic-macro-arguments -Wno-zero-length-array -Wno-extended-offsetof -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ -Wl,-sectcreate,__TEXT,__info_plist,/Users/sas/Source/llvm/tools/lldb/tools/debugserver/source/../resources/lldb-debugserver-Info.plist tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/HasAVX.s.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/CFBundle.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/CFData.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/CFString.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/Genealogy.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachException.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachProcess.mm.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachTask.mm.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachThread.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachThreadList.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachVMMemory.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/MachVMRegion.cpp.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/mach_excServer.c.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/mach_excUser.c.o tools/lldb/tools/debugserver/source/MacOSX/CMakeFiles/debugserver.dir/debugserver_vers.c.o  -o bin/debugserver  lib/liblldbDebugserverCommon.a lib/liblldbUtility.a lib/liblldbDebugserverMacOSX_I386.a lib/liblldbDebugserverMacOSX_X86_64.a -framework Cocoa -Wl,-rpath,@executable_path/../lib && cd /Users/sas/Source/llvm/build/bin && "CODESIGN_ALLOCATE=/Applications/Xcode 6.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate" codesign --force --sign lldb_codesign debugserver
/bin/sh: CODESIGN_ALLOCATE=/Applications/Xcode 6.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: No such file or directory
[2681/2756] Building CXX object tools/lldb/source/Target/CMakeFiles/lldbTarget.dir/Target.cpp.o
ninja: build stopped: subcommand failed.

Reviewers: clayborg, dawn, brucem, tfiala

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D13742

Details

Auditors
dawn
Committed
sasOct 14 2015, 3:25 PM
Differential Revision
D13742: Fix codesign command with cmake.
Parents
rL250334: ELF2: Support --entry=<addr>.
Branches
Unknown
Tags
Unknown

Event Timeline

dawn raised a concern with this commit.EditedOct 21 2015, 5:03 PM
dawn added a subscriber: dawn.

First, sorry for my delay in reviewing your patch, but I've been on vacation and now am at the C++ ANSI meeting in Kona for this week. But...

This broke the build of cmake on OSX. We get:

[...]
[2632/2743] Linking CXX executable bin/debugserver
FAILED: : && /usr/bin/c++   -std=c++11 -stdlib=libc++ [...]
 -o bin/debugserver  lib/liblldbDebugserverCommon.a lib/liblldbUtility.a lib/liblldbDebugserverMacOSX_I386.a lib/liblldbDebugserverMacOSX_X86_64.a -framework Cocoa -Wl,-rpath,@executable_path/../lib && cd /Users/testuser/build/workspace/LLVM-Clang-LLDB_master_release_OSX/llvm/build_ninja/bin && /usr/local/Cellar/cmake/3.0.2/bin/cmake -E env CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate codesign --force --sign lldb_codesign debugserver
CMake Error: cmake version 3.0.2
Usage: /usr/local/Cellar/cmake/3.0.2/bin/cmake -E [command] [arguments ...]
Available commands:
  chdir dir cmd [args]...   - run command in a given directory
[...]

lldb is built on OSX as:

mkdir "$BUILDDIR" && cd "$BUILDDIR"
cmake -G Ninja .. "-DLLVM_TARGETS_TO_BUILD=ARM;X86;AArch64" -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++" -DCMAKE_BUILD_TYPE=Release
security unlock-keychain -p testuser /Users/testuser/Library/Keychains/login.keychain
ninja

I don't know why older cmakes don't like the added "-E env" option, and the usage statement doesn't help. Any help?

Thanks in advance,
-Dawn

brucem added a subscriber: brucem.Oct 21 2015, 8:00 PM

You are correct: `-E env` is new after 3.0. (Not in 3.0, but it is in 3.2.)

I think the minimum supported cmake is actually older then 3.0 (2.8.something) ...

cmake_minimum_required(VERSION 2.8)

in CMakeLists.txt

I believe LLVM requires CMake 2.8.12 or later (at least that was the case
when I looked three weeks ago).

dawn added a comment.Oct 22 2015, 2:25 AM

One resolution would be to check for the cmake version and conditionally enable the new code, but that's beyond my capabilities - anyone know how? If not, can we please revert this commit?

It seems like it should be possible to conditionally enable this using CMAKE_VERSION. However that just means anyone who's silly enough to use an older CMake version may run into the issue this patch attempts to address, so arguably the proper fix is to bump up the CMake version requirement instead. Should probably run this by lldb-dev first.

labath added a subscriber: labath.Oct 22 2015, 5:52 AM

I don't think we should bump the version over a trivial issue like this. cmake 2.8 is still the default on alot of systems.
Wouldn't a well placed quote work also? Like,
FOO="${BAR}" codesign --force --end
Or just putting the command into a separate script file? We already execute a lot of scripts from cmake anyway...

+1 to what @labath said.

dawn added a comment.Oct 22 2015, 2:26 PM

Please review http://reviews.llvm.org/D13995 for a proposed fix.

sas added a comment.Oct 22 2015, 3:16 PM

Adding quotes doesn't work. I think the patch that @dawn linked is good enough even though the issue is still not fixed on older cmake versions.

dawn accepted this commit.Oct 22 2015, 3:53 PM

Breakage with older cmake versions fixed in svn r251073.