Project

General

Profile

PathInterposer » History » Version 12

Denis 'GNUtoo' Carikli, 10/18/2021 07:28 PM
Add toc

1 1 Denis 'GNUtoo' Carikli
h1. PathInterposer
2
3 12 Denis 'GNUtoo' Carikli
{{toc}}
4
5 7 dl lud
h2. Warnings
6 1 Denis 'GNUtoo' Carikli
7
This page is a work in progress, so it might contains mistakes, inaccuracies, etc.
8
9
h2. Introduction
10
11 8 Denis 'GNUtoo' Carikli
Sometimes we need to use host tools for building Replicant.
12
13
This has several consequences:
14
* 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.
15 9 Denis 'GNUtoo' Carikli
* We typically trust the host distributions like Trisquel way better than binaries provided by Google. So even if both are free software, we would prefer to trust the distribution tools instead.
16 8 Denis 'GNUtoo' Carikli
17
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.
18
19
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.
20
21
This has several advantages:
22
* It helps a lot making Replicant compatible with more distributions as:
23
** not all the distributions have the tools in the same path (/usr/bin vs /usr/sbin)
24 1 Denis 'GNUtoo' Carikli
** 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).
25 10 Denis 'GNUtoo' Carikli
* users might need to override tools in some cases (that happened with proguard in Replicant 6)
26 8 Denis 'GNUtoo' Carikli
27
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.
28 1 Denis 'GNUtoo' Carikli
29 11 Denis 'GNUtoo' Carikli
h2. How it works
30 2 Denis 'GNUtoo' Carikli
31
During the build:
32
* The host path is saved to out/.path_interposer_origpath
33
* The host path is changed to a new one
34
* The path interposer is used to access host binaries. It uses the saved path for that.
35
36 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]:
37 2 Denis 'GNUtoo' Carikli
<pre>
38
/home/replicant/replicant-11/prebuilts/jdk/jdk11/linux-x86/bin
39
/home/replicant/replicant-11/prebuilts/jdk/jdk11/linux-x86/bin
40
/home/replicant/replicant-11/out/soong/host/linux-x86/bin
41
/home/replicant/replicant-11/out/host/linux-x86/bin
42
/home/replicant/replicant-11/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin
43
/home/replicant/replicant-11/development/scripts
44
/home/replicant/replicant-11/prebuilts/devtools/tools
45
/home/replicant/replicant-11/external/selinux/prebuilts/bin
46
/home/replicant/replicant-11/prebuilts/misc/linux-x86/dtc
47
/home/replicant/replicant-11/prebuilts/misc/linux-x86/libufdt
48
/home/replicant/replicant-11/prebuilts/clang/host/linux-x86/llvm-binutils-stable
49
/home/replicant/replicant-11/prebuilts/android-emulator/linux-x86_64
50
/home/replicant/replicant-11/prebuilts/asuite/acloud/linux-x86
51
/home/replicant/replicant-11/prebuilts/asuite/aidegen/linux-x86
52
/home/replicant/replicant-11/prebuilts/asuite/atest/linux-x86
53
/home/replicant/bin
54
/home/replicant/.local/bin
55
/usr/local/sbin
56
/usr/local/bin
57
/usr/sbin
58
/usr/bin
59
/sbin
60
/bin
61
/usr/games
62
</pre>
63
64 6 Denis 'GNUtoo' Carikli
Here we can deduce that the paths set by the Android build system take precedence over the host paths.
65 2 Denis 'GNUtoo' Carikli
66
fn1. This has been deduced by prints with the following patch:
67
<pre>
68
--- a/cmd/path_interposer/main.go
69
+++ b/cmd/path_interposer/main.go
70
@@ -116,6 +116,10 @@ func Main(stdout, stderr io.Writer, interposer string, args []string, opts mainO
71
                return 1, fmt.Errorf("Failed to set PATH env: %v", err)
72
        }
73
 
74
+       fmt.Fprintln(os.Stderr, "####################################")
75
+       fmt.Fprintln(os.Stderr, os.Getenv("PATH"))
76
+       fmt.Fprintln(os.Stderr, "####################################")
77
+
78
        if config := opts.config(base); config.Log || config.Error {
79
                var procs []paths.LogProcess
80
                if opts.lookupParents != nil {
81
</pre>
82
83
h2. Launching host binaries without touching the prebuilts
84
85
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
86
87
for instance in the Mesa (external/mesa3d) Android.mk we had:
88
<pre>
89
MESA_PYTHON2 := out/.path/python2
90
MESA_PYTHON3 := out/.path/python3
91
</pre>
92 3 Denis 'GNUtoo' Carikli
93
This worked because 'python2' and 'python3' were only available in the host path:
94
<pre>
95
$ 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
96
ls: cannot access '/home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin/python3': No such file or directory
97
ls: cannot access '/home/replicant/replicant-10/prebuilts/jdk/jdk9/linux-x86/bin/python3': No such file or directory
98
ls: cannot access '/home/replicant/replicant-10/out/soong/host/linux-x86/bin/python3': No such file or directory
99
ls: cannot access '/home/replicant/replicant-10/out/host/linux-x86/bin/python3': No such file or directory
100
ls: cannot access '/home/replicant/replicant-10/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/python3': No such file or directory
101
ls: cannot access '/home/replicant/replicant-10/development/scripts/python3': No such file or directory
102
ls: cannot access '/home/replicant/replicant-10/prebuilts/devtools/tools/python3': No such file or directory
103
ls: cannot access '/home/replicant/replicant-10/external/selinux/prebuilts/bin/python3': No such file or directory
104
ls: cannot access '/home/replicant/replicant-10/prebuilts/misc/linux-x86/dtc/python3': No such file or directory
105
ls: cannot access '/home/replicant/replicant-10/prebuilts/misc/linux-x86/libufdt/python3': No such file or directory
106
ls: cannot access '/home/replicant/replicant-10/prebuilts/android-emulator/linux-x86_64/python3': No such file or directory
107
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/acloud/linux-x86/python3': No such file or directory
108
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/aidegen/linux-x86/python3': No such file or directory
109
ls: cannot access '/home/replicant/replicant-10/prebuilts/asuite/atest/linux-x86/python3': No such file or directory
110
ls: cannot access '/home/replicant/bin/python3': No such file or directory
111
ls: cannot access '/home/replicant/.local/bin/python3': No such file or directory
112
ls: cannot access '/usr/local/sbin/python3': No such file or directory
113
ls: cannot access '/usr/local/bin/python3': No such file or directory
114
ls: cannot access '/usr/sbin/python3': No such file or directory
115
/usr/bin/python3
116
ls: cannot access '/sbin/python3': No such file or directory
117
ls: cannot access '/bin/python3': No such file or directory
118
ls: cannot access '/usr/games/python3': No such file or directory
119
</pre>
120 4 Denis 'GNUtoo' Carikli
121
For instance @prebuilts/python/linux-x86/2.7.5/bin/python@ wasn't in the path.