diff options
author | Frederic Martinsons <frederic.martinsons@gmail.com> | 2023-08-02 15:16:04 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-08-09 13:22:00 +0100 |
commit | 2dd04232e77c88a251c19e60f148f6a0fe02e691 (patch) | |
tree | 9717f320df7f94e52e2e735f6bea56af04e7fa0f /meta/classes-recipe/cargo_common.bbclass | |
parent | d4c14304c92d76a2bdb612ffa3ca3477cd06cb6e (diff) | |
download | poky-2dd04232e77c88a251c19e60f148f6a0fe02e691.tar.gz |
cargo_common.bbclass: Handle Cargo.lock modifications for git dependencies
Now we use --frozen, Cargo.lock cannot be modified by cargo build.
These patched git dependencies requires that the git url is removed
from Cargo.lock.
Fixes #15104
(From OE-Core rev: b80f756dd480fc92f58d7e10105d3a2427a32795)
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/cargo_common.bbclass')
-rw-r--r-- | meta/classes-recipe/cargo_common.bbclass | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/meta/classes-recipe/cargo_common.bbclass b/meta/classes-recipe/cargo_common.bbclass index db54826ddb..b732a1bd95 100644 --- a/meta/classes-recipe/cargo_common.bbclass +++ b/meta/classes-recipe/cargo_common.bbclass | |||
@@ -117,6 +117,8 @@ cargo_common_do_configure () { | |||
117 | } | 117 | } |
118 | 118 | ||
119 | python cargo_common_do_patch_paths() { | 119 | python cargo_common_do_patch_paths() { |
120 | import shutil | ||
121 | |||
120 | cargo_config = os.path.join(d.getVar("CARGO_HOME"), "config") | 122 | cargo_config = os.path.join(d.getVar("CARGO_HOME"), "config") |
121 | if not os.path.exists(cargo_config): | 123 | if not os.path.exists(cargo_config): |
122 | return | 124 | return |
@@ -146,6 +148,45 @@ python cargo_common_do_patch_paths() { | |||
146 | print('\n[patch."%s"]' % k, file=config) | 148 | print('\n[patch."%s"]' % k, file=config) |
147 | for name in v: | 149 | for name in v: |
148 | print(name, file=config) | 150 | print(name, file=config) |
151 | |||
152 | if not patches: | ||
153 | return | ||
154 | |||
155 | # Cargo.lock file is needed for to be sure that artifacts | ||
156 | # downloaded by the fetch steps are those expected by the | ||
157 | # project and that the possible patches are correctly applied. | ||
158 | # Moreover since we do not want any modification | ||
159 | # of this file (for reproducibility purpose), we prevent it by | ||
160 | # using --frozen flag (in CARGO_BUILD_FLAGS) and raise a clear error | ||
161 | # here is better than letting cargo tell (in case the file is missing) | ||
162 | # "Cargo.lock should be modified but --frozen was given" | ||
163 | |||
164 | manifest_path = d.getVar("MANIFEST_PATH", True) | ||
165 | lockfile = os.path.join(os.path.dirname(manifest_path), "Cargo.lock") | ||
166 | if not os.path.exists(lockfile): | ||
167 | bb.fatal(f"{lockfile} file doesn't exist") | ||
168 | |||
169 | # There are patched files and so Cargo.lock should be modified but we use | ||
170 | # --frozen so let's handle that modifications here. | ||
171 | # | ||
172 | # Note that a "better" (more elegant ?) would have been to use cargo update for | ||
173 | # patched packages: | ||
174 | # cargo update --offline -p package_1 -p package_2 | ||
175 | # But this is not possible since it requires that cargo local git db | ||
176 | # to be populated and this is not the case as we fetch git repo ourself. | ||
177 | |||
178 | lockfile_orig = lockfile + ".orig" | ||
179 | if not os.path.exists(lockfile_orig): | ||
180 | shutil.copy(lockfile, lockfile_orig) | ||
181 | |||
182 | newlines = [] | ||
183 | with open(lockfile_orig, "r") as f: | ||
184 | for line in f.readlines(): | ||
185 | if not line.startswith("source = \"git"): | ||
186 | newlines.append(line) | ||
187 | |||
188 | with open(lockfile, "w") as f: | ||
189 | f.writelines(newlines) | ||
149 | } | 190 | } |
150 | do_configure[postfuncs] += "cargo_common_do_patch_paths" | 191 | do_configure[postfuncs] += "cargo_common_do_patch_paths" |
151 | 192 | ||