Project

General

Profile

PathInterposer » History » Version 8

Denis 'GNUtoo' Carikli, 10/18/2021 07:25 PM
Add introduction

1 1 Denis 'GNUtoo' Carikli
h1. PathInterposer
2
3 7 dl lud
h2. Warnings
4 1 Denis 'GNUtoo' Carikli
5
This page is a work in progress, so it might contains mistakes, inaccuracies, etc.
6
7
h2. Introduction
8
9 8 Denis 'GNUtoo' Carikli
Sometimes we need to use host tools for building Replicant.
10
11
This has several consequences:
12
* When the tools that we inherit from AOSP or LineageOS lack certain features (like when the host xz provided for Android was compiled without the ARM BJC filter), we can easily use the host tools that have such features instead. The downside is that it makes the build process potentially less reproducible as the version of the tools provided by the host distributions can change with the distribution updates or when different people use different distributions.
13
* We typically trust the host distributions like Trisquel way better than binaries provided by Google. So even if both are free software, we could chose to trust the distribution tools instead.
14
15
Ideally we could make Replicant build most of the tools we need in a reproducible way to not use the host tools without having to trust prebuilt binaries, but this is not always practical as doing that could take a lot of time. In addition we do need tools to build replacement tools in the first place.
16
17
In any case when using tools from the host distribution, it's a really good idea to not hardcode the path of the tool (like /usr/bin/python) and instead make sure that the host distribution @PATH@ is used instead.
18
19
This has several advantages:
20
* It helps a lot making Replicant compatible with more distributions as:
21
** not all the distributions have the tools in the same path (/usr/bin vs /usr/sbin)
22
** users might need to override tools in some cases (that happened with proguard in Replicant 6)
23
** some distributions (like Guix) do respect the @PATH@ but don't use standard paths (repo could be in /gnu/store/4cw9j7c36cgv37g6bzs2dnygmfc5jxh1-git-repo-2.4.1/share/git-repo/repo or in ~/.guix-profile/bin/repo). And since Guix is reproducible and even bootstrapable we also want not to rule out this option, while also being compatible with other distributions (for simplicity and to not be stuck with Guix).
24
25
This article shows how to use host tools in a way that makes use of the host @PATH@ and also how Android implements (with PathInterposer) the isolation between the tools provided by the host distribution and Android.
26 1 Denis 'GNUtoo' Carikli
27
h2. how it works
28 2 Denis 'GNUtoo' Carikli
29
During the build:
30
* The host path is saved to out/.path_interposer_origpath
31
* The host path is changed to a new one
32
* The path interposer is used to access host binaries. It uses the saved path for that.
33
34 5 Denis 'GNUtoo' Carikli
With Trisquel 8, and Replicant 11, here's an example of how the path looks like for applications being launched through the path interposer[1]:
35 2 Denis 'GNUtoo' Carikli
<pre>
36
/home/replicant/replicant-11/prebuilts/jdk/jdk11/linux-x86/bin
37
/home/replicant/replicant-11/prebuilts/jdk/jdk11/linux-x86/bin
38
/home/replicant/replicant-11/out/soong/host/linux-x86/bin
39
/home/replicant/replicant-11/out/host/linux-x86/bin
40
/home/replicant/replicant-11/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin
41
/home/replicant/replicant-11/development/scripts
42
/home/replicant/replicant-11/prebuilts/devtools/tools
43
/home/replicant/replicant-11/external/selinux/prebuilts/bin
44
/home/replicant/replicant-11/prebuilts/misc/linux-x86/dtc
45
/home/replicant/replicant-11/prebuilts/misc/linux-x86/libufdt
46
/home/replicant/replicant-11/prebuilts/clang/host/linux-x86/llvm-binutils-stable
47
/home/replicant/replicant-11/prebuilts/android-emulator/linux-x86_64
48
/home/replicant/replicant-11/prebuilts/asuite/acloud/linux-x86
49
/home/replicant/replicant-11/prebuilts/asuite/aidegen/linux-x86
50
/home/replicant/replicant-11/prebuilts/asuite/atest/linux-x86
51
/home/replicant/bin
52
/home/replicant/.local/bin
53
/usr/local/sbin
54
/usr/local/bin
55
/usr/sbin
56
/usr/bin
57
/sbin
58
/bin
59
/usr/games
60
</pre>
61
62 6 Denis 'GNUtoo' Carikli
Here we can deduce that the paths set by the Android build system take precedence over the host paths.
63 2 Denis 'GNUtoo' Carikli
64
fn1. This has been deduced by prints with the following patch:
65
<pre>
66
--- a/cmd/path_interposer/main.go
67
+++ b/cmd/path_interposer/main.go
68
@@ -116,6 +116,10 @@ func Main(stdout, stderr io.Writer, interposer string, args []string, opts mainO
69
                return 1, fmt.Errorf("Failed to set PATH env: %v", err)
70
        }
71
 
72
+       fmt.Fprintln(os.Stderr, "####################################")
73
+       fmt.Fprintln(os.Stderr, os.Getenv("PATH"))
74
+       fmt.Fprintln(os.Stderr, "####################################")
75
+
76
        if config := opts.config(base); config.Log || config.Error {
77
                var procs []paths.LogProcess
78
                if opts.lookupParents != nil {
79
</pre>
80
81
h2. Launching host binaries without touching the prebuilts
82
83
In Replicant 10, we could use out/.path/python3 as python3 interpreter assuming that we enabled it in build/soong/ui/build/paths/config.go
84
85
for instance in the Mesa (external/mesa3d) Android.mk we had:
86
<pre>
87
MESA_PYTHON2 := out/.path/python2
88
MESA_PYTHON3 := out/.path/python3
89
</pre>
90 3 Denis 'GNUtoo' Carikli
91
This worked because 'python2' and 'python3' were only available in the host path:
92
<pre>
93
$ for path in $(echo /home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin:/home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin:/home/replicant/replicant-10/out/soong/host/linux-x86/bin:/home/replicant/replicant-10/out/host/linux-x86/bin:/home/replicant/replicant-10/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin:/home/replicant/replicant-10/development/scripts:/home/replicant/replicant-10/prebuilts/devtools/tools:/home/replicant/replicant-10/external/selinux/prebuilts/bin:/home/replicant/replicant-10/prebuilts/misc/linux-x86/dtc:/home/replicant/replicant-10/prebuilts/misc/linux-x86/libufdt:/home/replicant/replicant-10/prebuilts/android-emulator/linux-x86_64:/home/replicant/replicant-10/prebuilts/asuite/acloud/linux-x86:/home/replicant/replicant-10/prebuilts/asuite/aidegen/linux-x86:/home/replicant/replicant-10/prebuilts/asuite/atest/linux-x86:/home/replicant/bin:/home/replicant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games | sed 's#:#\n#g') ; do ls "${path}/python3" ; done
94
ls: cannot access '/home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin/python3': No such file or directory
95
ls: cannot access '/home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin/python3': No such file or directory
96
ls: cannot access '/home/replicant/replicant-10/out/soong/host/linux-x86/bin/python3': No such file or directory
97
ls: cannot access '/home/replicant/replicant-10/out/host/linux-x86/bin/python3': No such file or directory
98
ls: cannot access '/home/replicant/replicant-10/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/python3': No such file or directory
99
ls: cannot access '/home/replicant/replicant-10/development/scripts/python3': No such file or directory
100
ls: cannot access '/home/replicant/replicant-10/prebuilts/devtools/tools/python3': No such file or directory
101
ls: cannot access '/home/replicant/replicant-10/external/selinux/prebuilts/bin/python3': No such file or directory
102
ls: cannot access '/home/replicant/replicant-10/prebuilts/misc/linux-x86/dtc/python3': No such file or directory
103
ls: cannot access '/home/replicant/replicant-10/prebuilts/misc/linux-x86/libufdt/python3': No such file or directory
104
ls: cannot access '/home/replicant/replicant-10/prebuilts/android-emulator/linux-x86_64/python3': No such file or directory
105
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/acloud/linux-x86/python3': No such file or directory
106
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/aidegen/linux-x86/python3': No such file or directory
107
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/atest/linux-x86/python3': No such file or directory
108
ls: cannot access '/home/replicant/bin/python3': No such file or directory
109
ls: cannot access '/home/replicant/.local/bin/python3': No such file or directory
110
ls: cannot access '/usr/local/sbin/python3': No such file or directory
111
ls: cannot access '/usr/local/bin/python3': No such file or directory
112
ls: cannot access '/usr/sbin/python3': No such file or directory
113
/usr/bin/python3
114
ls: cannot access '/sbin/python3': No such file or directory
115
ls: cannot access '/bin/python3': No such file or directory
116
ls: cannot access '/usr/games/python3': No such file or directory
117
</pre>
118 4 Denis 'GNUtoo' Carikli
119
For instance @prebuilts/python/linux-x86/2.7.5/bin/python@ wasn't in the path.