* [PATCHV3 0/4] Extend cargo based recipe support
@ 2023-03-27 8:12 frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 1/4] cargo_common.bbclass: Support local github repos frederic.martinsons
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: frederic.martinsons @ 2023-03-27 8:12 UTC (permalink / raw)
To: openembedded-core; +Cc: alex.kiernan
From: Frederic Martinsons <frederic.martinsons@gmail.com>
This series brings the support of local git repository inside
a cargo based recipe.
It also enables devtool capacity on it.
The following changes since commit 4876189dd2ae5a04a296b11b537b9f613159c6bf:
xcb-proto: Fix install conflict when enable multilib. (2023-03-23 22:38:41 +0000)
are available in the Git repository at:
https://gitlab.com/fmartinsons/openembedded-core cargo-extend-support-git-and-devtool
Alex Kiernan (1):
cargo_common.bbclass: Support local github repos
Frederic Martinsons (3):
cargo_common.bbclass: add support of user in url for patch
devtool: add support for multiple git url inside a cargo based recipe
patch: support of git patches when the source uri contained subpath
parameter
meta/classes-recipe/cargo_common.bbclass | 33 ++++++++++++++
meta/classes/externalsrc.bbclass | 4 +-
meta/lib/oe/patch.py | 57 ++++++++++++++++++------
3 files changed, 78 insertions(+), 16 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCHV3 1/4] cargo_common.bbclass: Support local github repos
2023-03-27 8:12 [PATCHV3 0/4] Extend cargo based recipe support frederic.martinsons
@ 2023-03-27 8:12 ` frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 2/4] cargo_common.bbclass: add support of user in url for patch frederic.martinsons
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: frederic.martinsons @ 2023-03-27 8:12 UTC (permalink / raw)
To: openembedded-core; +Cc: alex.kiernan
From: Alex Kiernan <alex.kiernan@gmail.com>
Since disable network was added cargo configurations which reference git
repos fail as they attempt to fetch across the network as part of
do_compile, even if EXTRA_OECARGO_PATHS to add them as part of `paths`
is used, as this is documented as only working for packages which exist
in crates.io.
Add parsing of the SRC_URIs for git repos and include `[patch]` sections
to redirect to the checked out source repos which the bitbake fetcher
has already populated.
There are still cases which don't work - if you have multiple copies of
the same repo with different revisions, there's currently no way to
represent that and anything using a repo which has a virtual manifest
will fail to build (see https://github.com/rust-lang/cargo/issues/4934).
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---
meta/classes-recipe/cargo_common.bbclass | 30 ++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/meta/classes-recipe/cargo_common.bbclass b/meta/classes-recipe/cargo_common.bbclass
index f503a001dd..63b1382908 100644
--- a/meta/classes-recipe/cargo_common.bbclass
+++ b/meta/classes-recipe/cargo_common.bbclass
@@ -116,6 +116,36 @@ cargo_common_do_configure () {
EOF
}
+python cargo_common_do_patch_paths() {
+ cargo_config = os.path.join(d.getVar("CARGO_HOME"), "config")
+ if not os.path.exists(cargo_config):
+ return
+
+ src_uri = (d.getVar('SRC_URI') or "").split()
+ if len(src_uri) == 0:
+ return
+
+ patches = dict()
+ workdir = d.getVar('WORKDIR')
+ fetcher = bb.fetch2.Fetch(src_uri, d)
+ for url in fetcher.urls:
+ ud = fetcher.ud[url]
+ if ud.type == 'git':
+ name = ud.parm.get('name')
+ destsuffix = ud.parm.get('destsuffix')
+ if name is not None and destsuffix is not None:
+ repo = '%s://%s%s' % (ud.proto, ud.host, ud.path)
+ path = '%s = { path = "%s" }' % (name, os.path.join(workdir, destsuffix))
+ patches.setdefault(repo, []).append(path)
+
+ with open(cargo_config, "a+") as config:
+ for k, v in patches.items():
+ print('\n[patch."%s"]' % k, file=config)
+ for name in v:
+ print(name, file=config)
+}
+do_configure[postfuncs] += "cargo_common_do_patch_paths"
+
oe_cargo_fix_env () {
export CC="${RUST_TARGET_CC}"
export CXX="${RUST_TARGET_CXX}"
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCHV3 2/4] cargo_common.bbclass: add support of user in url for patch
2023-03-27 8:12 [PATCHV3 0/4] Extend cargo based recipe support frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 1/4] cargo_common.bbclass: Support local github repos frederic.martinsons
@ 2023-03-27 8:12 ` frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 3/4] devtool: add support for multiple git url inside a cargo based recipe frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 4/4] patch: support of git patches when the source uri contained subpath parameter frederic.martinsons
3 siblings, 0 replies; 5+ messages in thread
From: frederic.martinsons @ 2023-03-27 8:12 UTC (permalink / raw)
To: openembedded-core; +Cc: alex.kiernan
From: Frederic Martinsons <frederic.martinsons@gmail.com>
To handle url like git://git@repo/project
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
---
meta/classes-recipe/cargo_common.bbclass | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/meta/classes-recipe/cargo_common.bbclass b/meta/classes-recipe/cargo_common.bbclass
index 63b1382908..82ab25b59c 100644
--- a/meta/classes-recipe/cargo_common.bbclass
+++ b/meta/classes-recipe/cargo_common.bbclass
@@ -134,7 +134,10 @@ python cargo_common_do_patch_paths() {
name = ud.parm.get('name')
destsuffix = ud.parm.get('destsuffix')
if name is not None and destsuffix is not None:
- repo = '%s://%s%s' % (ud.proto, ud.host, ud.path)
+ if ud.user:
+ repo = '%s://%s@%s%s' % (ud.proto, ud.user, ud.host, ud.path)
+ else:
+ repo = '%s://%s%s' % (ud.proto, ud.host, ud.path)
path = '%s = { path = "%s" }' % (name, os.path.join(workdir, destsuffix))
patches.setdefault(repo, []).append(path)
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCHV3 3/4] devtool: add support for multiple git url inside a cargo based recipe
2023-03-27 8:12 [PATCHV3 0/4] Extend cargo based recipe support frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 1/4] cargo_common.bbclass: Support local github repos frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 2/4] cargo_common.bbclass: add support of user in url for patch frederic.martinsons
@ 2023-03-27 8:12 ` frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 4/4] patch: support of git patches when the source uri contained subpath parameter frederic.martinsons
3 siblings, 0 replies; 5+ messages in thread
From: frederic.martinsons @ 2023-03-27 8:12 UTC (permalink / raw)
To: openembedded-core; +Cc: alex.kiernan
From: Frederic Martinsons <frederic.martinsons@gmail.com>
Without that, the possible git urls that are in SRC_URI of a recipe
are removed from SRC_URI during devtool process and so the
cargo_common_do_patch_paths in cargo_common.bbclass cannot
patch these packages to fetch them locally.
I use a generic type name because I foresee this change will
be useful for recipe that used a package manager (cargo but also
npm) see https://bugzilla.yoctoproject.org/show_bug.cgi?id=11015
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
---
meta/classes/externalsrc.bbclass | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/meta/classes/externalsrc.bbclass b/meta/classes/externalsrc.bbclass
index 26c5803ee6..b00fdba8e9 100644
--- a/meta/classes/externalsrc.bbclass
+++ b/meta/classes/externalsrc.bbclass
@@ -68,9 +68,7 @@ python () {
for url in fetch.urls:
url_data = fetch.ud[url]
parm = url_data.parm
- if (url_data.type == 'file' or
- url_data.type == 'npmsw' or url_data.type == 'crate' or
- 'type' in parm and parm['type'] == 'kmeta'):
+ if url_data.type in ['file', 'npmsw', 'crate'] or parm.get('type') in ['kmeta', 'git-dependency']:
local_srcuri.append(url)
d.setVar('SRC_URI', ' '.join(local_srcuri))
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCHV3 4/4] patch: support of git patches when the source uri contained subpath parameter
2023-03-27 8:12 [PATCHV3 0/4] Extend cargo based recipe support frederic.martinsons
` (2 preceding siblings ...)
2023-03-27 8:12 ` [PATCHV3 3/4] devtool: add support for multiple git url inside a cargo based recipe frederic.martinsons
@ 2023-03-27 8:12 ` frederic.martinsons
3 siblings, 0 replies; 5+ messages in thread
From: frederic.martinsons @ 2023-03-27 8:12 UTC (permalink / raw)
To: openembedded-core; +Cc: alex.kiernan
From: Frederic Martinsons <frederic.martinsons@gmail.com>
This is for a specific case where:
- A recipe use a subpath on a git repo (e.g. git://repo.git/projects;subpath=subproject)
- The recipe contains a patch to apply
- a devtool modify is used on this recipe
With these conditions, the patch cannot be applied at all.
GitApplyTree class is used for handling patch under devtool, but
when subpath is present in SRC_URI, the resulting git tree
is dirty (every files and directories which was not in subpath are suppressed)
and so "git am" refuse to apply patches.
That would not be an issue since the GitApplyTree have a fallback
to PatchTree in case of error, but during this error management,
there is a "git reset --hard HEAD" call which suppress the subpath
operation and finally prevents the patch to be applied even with PatchTree.
When devtool is not involved, only PatchTree class is used and the
above problem is irrelevant.
To support git patching during devtool, the presence of subpath and
the dirtyness of the repo are checked. If both conditions are
met, we directly call PatchTree like it was already done
in case of error during git apply.
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
---
meta/lib/oe/patch.py | 57 ++++++++++++++++++++++++++++++++++----------
1 file changed, 44 insertions(+), 13 deletions(-)
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index b2dc8d0a90..d047b3b947 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -499,6 +499,36 @@ class GitApplyTree(PatchTree):
finally:
shutil.rmtree(tempdir)
+ def _need_dirty_check(self):
+ fetch = bb.fetch2.Fetch([], self.d)
+ check_dirtyness = False
+ for url in fetch.urls:
+ url_data = fetch.ud[url]
+ parm = url_data.parm
+ # a git url with subpath param will surely be dirty
+ # since the git tree from which we clone will be emptied
+ # from all files that are not in the subpath
+ if url_data.type == 'git' and parm.get('subpath'):
+ check_dirtyness = True
+ return check_dirtyness
+
+ def _commitpatch(self, patch, patchfilevar):
+ output = ""
+ # Add all files
+ shellcmd = ["git", "add", "-f", "-A", "."]
+ output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ # Exclude the patches directory
+ shellcmd = ["git", "reset", "HEAD", self.patchdir]
+ output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ # Commit the result
+ (tmpfile, shellcmd) = self.prepareCommit(patch['file'], self.commituser, self.commitemail)
+ try:
+ shellcmd.insert(0, patchfilevar)
+ output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ finally:
+ os.remove(tmpfile)
+ return output
+
def _applypatch(self, patch, force = False, reverse = False, run = True):
import shutil
@@ -534,6 +564,19 @@ class GitApplyTree(PatchTree):
shutil.copy2(commithook, applyhook)
try:
patchfilevar = 'PATCHFILE="%s"' % os.path.basename(patch['file'])
+ if self._need_dirty_check():
+ # Check dirtyness of the tree
+ try:
+ output = runcmd(["git", "--work-tree=%s" % reporoot, "status", "--short"])
+ except CmdError:
+ pass
+ else:
+ if output:
+ # The tree is dirty, not need to try to apply patches with git anymore
+ # since they fail, fallback directly to patch
+ output = PatchTree._applypatch(self, patch, force, reverse, run)
+ output += self._commitpatch(patch, patchfilevar)
+ return output
try:
shellcmd = [patchfilevar, "git", "--work-tree=%s" % reporoot]
self.gitCommandUserOptions(shellcmd, self.commituser, self.commitemail)
@@ -560,19 +603,7 @@ class GitApplyTree(PatchTree):
except CmdError:
# Fall back to patch
output = PatchTree._applypatch(self, patch, force, reverse, run)
- # Add all files
- shellcmd = ["git", "add", "-f", "-A", "."]
- output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
- # Exclude the patches directory
- shellcmd = ["git", "reset", "HEAD", self.patchdir]
- output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
- # Commit the result
- (tmpfile, shellcmd) = self.prepareCommit(patch['file'], self.commituser, self.commitemail)
- try:
- shellcmd.insert(0, patchfilevar)
- output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
- finally:
- os.remove(tmpfile)
+ output += self._commitpatch(patch, patchfilevar)
return output
finally:
shutil.rmtree(hooks_dir)
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-27 8:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-27 8:12 [PATCHV3 0/4] Extend cargo based recipe support frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 1/4] cargo_common.bbclass: Support local github repos frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 2/4] cargo_common.bbclass: add support of user in url for patch frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 3/4] devtool: add support for multiple git url inside a cargo based recipe frederic.martinsons
2023-03-27 8:12 ` [PATCHV3 4/4] patch: support of git patches when the source uri contained subpath parameter frederic.martinsons
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox