Mir

Merge lp:~vanvugt/mir/fix-1406073 into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2188
Proposed branch: lp:~vanvugt/mir/fix-1406073
Merge into: lp:mir
Diff against target: 112 lines (+59/-17)
3 files modified
cmake/MirCommon.cmake (+4/-11)
src/CMakeLists.txt (+6/-0)
src/wrapper.c (+49/-6)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1406073
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Mir development team Pending
Review via email: mp+245410@code.launchpad.net

Commit message

Make the binary wrapper completely position independent, so it continues
to work after directory renames/moves and on hosts other than the build
machine too. (LP: #1406073)

Description of the change

Part of my daily workflow is to build on one host and rsync binaries to another (e.g. a phone). That workflow no longer works without this fix.

A child branch of this one further improves on what's here...
lp:~vanvugt/mir/fix-1406098

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

This is a blocking issue for me. I'll land it and ask forgiveness later...

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cmake/MirCommon.cmake'
--- cmake/MirCommon.cmake 2014-12-11 06:14:56 +0000
+++ cmake/MirCommon.cmake 2014-12-28 14:37:15 +0000
@@ -174,17 +174,10 @@
174 add_executable(${TARGET} ${ARGN})174 add_executable(${TARGET} ${ARGN})
175 set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${REAL_EXECUTABLE})175 set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${REAL_EXECUTABLE})
176176
177 add_executable(${TARGET}-wrapper ${PROJECT_SOURCE_DIR}/cmake/src/wrapper.c)177 add_custom_target(${TARGET}-wrapped
178 set_property(TARGET ${TARGET}-wrapper178 ln -fs wrapper ${CMAKE_BINARY_DIR}/bin/${TARGET}
179 APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE=\\\"${REAL_EXECUTABLE}\\\"")179 )
180 set_property(TARGET ${TARGET}-wrapper180 add_dependencies(${TARGET} ${TARGET}-wrapped)
181 APPEND_STRING PROPERTY COMPILE_FLAGS " -DBUILD_PREFIX=\\\"${CMAKE_BINARY_DIR}\\\"")
182 set_property(TARGET ${TARGET}-wrapper
183 APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
184 set_property(TARGET ${TARGET}-wrapper
185 PROPERTY OUTPUT_NAME ${TARGET})
186
187 add_dependencies(${TARGET} ${TARGET}-wrapper)
188 181
189 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/${REAL_EXECUTABLE}182 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/${REAL_EXECUTABLE}
190 DESTINATION ${CMAKE_INSTALL_BINDIR}183 DESTINATION ${CMAKE_INSTALL_BINDIR}
191184
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-12-19 21:52:32 +0000
+++ src/CMakeLists.txt 2014-12-28 14:37:15 +0000
@@ -23,6 +23,12 @@
23add_subdirectory(client/)23add_subdirectory(client/)
24add_subdirectory(utils/)24add_subdirectory(utils/)
2525
26add_executable(wrapper wrapper.c)
27set_property(TARGET wrapper
28 APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE_FORMAT=\\\".%s-uninstalled\\\"")
29set_property(TARGET wrapper
30 APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
31
26set(32set(
27 MIR_GENERATED_INCLUDE_DIRECTORIES33 MIR_GENERATED_INCLUDE_DIRECTORIES
28 ${MIR_GENERATED_INCLUDE_DIRECTORIES}34 ${MIR_GENERATED_INCLUDE_DIRECTORIES}
2935
=== renamed file 'cmake/src/wrapper.c' => 'src/wrapper.c'
--- cmake/src/wrapper.c 2014-12-03 00:24:52 +0000
+++ src/wrapper.c 2014-12-28 14:37:15 +0000
@@ -1,16 +1,59 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#include <string.h>
1#include <stdlib.h>20#include <stdlib.h>
2#include <stdio.h>21#include <stdio.h>
3#include <unistd.h>22#include <unistd.h>
4#include <assert.h>
523
6int main(int argc, char** argv)24int main(int argc, char** argv)
7{25{
8 assert(argc > 0);26 char path[1024], *dest = path, *dest_max = path+sizeof(path)-1;
9 setenv("MIR_CLIENT_PLATFORM_PATH", BUILD_PREFIX "/lib/client-modules/", 1);27 char *pivot = path;
1028 size_t pivot_max = 0;
11 argv[0] = BUILD_PREFIX "/bin/" EXECUTABLE;29 const char *src = argv[0], *name = argv[0];
30
31 (void)argc;
32 while (*src && dest < dest_max)
33 {
34 *dest = *src;
35 if (*dest == '/')
36 {
37 pivot = dest + 1;
38 name = src + 1;
39 }
40 ++src;
41 ++dest;
42 }
43 pivot_max = dest_max - pivot;
44
45 strncpy(pivot, "../lib/client-modules/", pivot_max);
46 *dest_max = '\0';
47 setenv("MIR_CLIENT_PLATFORM_PATH", path, 1);
48 printf("MIR_CLIENT_PLATFORM_PATH=%s\n", path);
49
50 snprintf(pivot, pivot_max, EXECUTABLE_FORMAT, name);
51 *dest_max = '\0';
52 printf("exec=%s\n", path);
53
54 argv[0] = path;
12 execv(argv[0], argv);55 execv(argv[0], argv);
1356
14 perror("Failed to execute real binary " EXECUTABLE);57 fprintf(stderr, "Failed to execute: %s\n", path);
15 return 1;58 return 1;
16}59}

Subscribers

People subscribed via source and target branches