Apply and commit a patch from bitbake recipe - yocto

I am observing that the yocto build system is just applying my patch instead of applying and committing the patch on the cloned git repo.
Original bitbake (u-boot-ti-staging_2018.01.bb) file.
require u-boot-ti.inc
PR = "r19"
BRANCH = "ti-u-boot-2018.01"
SRCREV = "8b2f1df4b55bc0797399a21d42ac191d44f99227"
Modified bitbake file, added SRC_URI to the file.
require u-boot-ti.inc
PR = "r19"
BRANCH = "ti-u-boot-2018.01"
SRCREV = "8b2f1df4b55bc0797399a21d42ac191d44f99227"
SRC_URI += "file://0001-Stopping-DHCP-server-giving-new-serverip.patch \
"
I have added a patch file under files directory. The content of the patch (0001-Stopping-DHCP-server-giving-new-serverip.patch) file is as follows.
From cf97b6053f00afd496d01a892599cd8f4b254087 Mon Sep 17 00:00:00 2001
From: Sunny Shukla <sunny.shukla#xyz.com>
Date: Wed, 19 Sep 2018 18:23:49 +0530
Subject: [PATCH] Stopping DHCP server giving new serverip
Added CONFIG_BOOTP_SERVERIP in the config file, this
stops the DHCP server gives new "serverip" address and
overrides the current one.
---
include/configs/am335x_evm.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index 01f0277..4b3047d 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
## -18,6 +18,8 ##
#include <configs/ti_am335x_common.h>
+#define CONFIG_BOOTP_SERVERIP
+
#ifndef CONFIG_SPL_BUILD
# define CONFIG_TIMESTAMP
#endif
--
2.7.4
The patch is applying like someone is executing a "git apply 0001-Stopping-DHCP-server-giving-new-serverip.patch" command on top of the cloned git repo as show below. But rather I want that the patch must be applied like someone is executing a "git am 0001-Stopping-DHCP-server-giving-new-serverip.patch" command on top of the cloned git repo.
git status
On branch ti-u-boot-2018.01
Your branch is behind 'origin/ti-u-boot-2018.01' by 23 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: include/configs/am335x_evm.h
no changes added to commit (use "git add" and/or "git commit -a")
I want this patch to be applied and committed on top of the cloned git repo. How to achieve that under a bitbake file?

Yocto by default uses quilt when no patch tool is specified. You can specify
PATCHTOOL = "git"
in your recipe, so that Yocto automatically applies it using "git am".
See here for more details.
NOTE: This functionality will start adding an extra line to the patch's description like "%%original patch: 0001-Stopping-DHCP-server-giving-new-serverip.patch" while applying the patch. To get rid of it, comment the below line under "oe-core/meta/lib/oe/patch.py" file.
https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/lib/oe/patch.py#n519

Related

How to patch remote source code locally in yocto project?

Sometimes, We meet a situation that remote source code fetched by a recipe need to be modified so that suit a specific machine.
How do we create a patch for remote source code locally? After that everytime we build the recipe (even clean it all) we can patch the remote source code automatically.
For example, I have a special machine with architecture A which is not common, so the remote source code need to be modified so that support architecture A.
Suppose there was a file called utils.h (which is code that we fetched by example.bb from remote git repository)
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) \
#define SOME_FUNCTIONALITY 1
Apparently I need to add archtecture A support in the file.
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__A__) \
#define SOME_FUNCTIONALITY 1
But if we just modified like that, next time we execute
bitbake -c cleanall example
bitbake example
then we get a unchanged copies again(which means we have to modify it again).
How do we create a Add-architecture-A-support.patch locally so that we can patch the remote source code automatically?
This is a simple one from answers.
(Note: If there was no git in the source code directory, before modifying the source code, you need to create a git repository and commit all in the top directory of the source code.)
git init # create a git repository
git add .
git commit -m "First commit" # first commit
After change the utils.h as above, we can check the git status. It usually looks like that.
$ git status
HEAD detached from 87b933c420
Changes not staged for commit:
(use "git add <file>..." to update what will be comitted)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../../utils.h
...
no changes added to commit (use "git add" and/or "git commit -a")
Then we add and commit the change locally (usually we don't have the permission to push to upper stream).
$ git add utils.h
$ git commit -m "Patch test"
After that we can use git to create a patch for the recent commit.
$ git show >Add-architecture-A-support.patch
It will creat a patch in the current directory with contents looks like that
commit a79e523...
Author: 杨...
Date: ...
Patch test
diff --git a/somedir/utils.h b/somedir/utils.h
index 20bfd36c84..
--- a/somedir/utils.h
+++ b/somedir/utils.h
...
+ defined(__A__) \
...
Then we can move the patch to the local layer where the recipe stayed.
recipe-example
|-- example
| |-- Add-architecture-A-support.patch
|-- example.bb
And add the patch in example.bb with this.
SRC_URI += "\
file://Add-architecture-A-support.patch \
"
Work finished. (Also, if want to undo the local commit after creating the patch, you can use git reset HEAD^ utils.h. emmm, I think so, maybe there are some faults, just google it)

Referencing current branch in github readme.md

In my github repo's readme.md file I have a Travis-CI badge. I use the following link:
https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=staging
The obvious problem is that the branch is hardcoded. Is it possible to use some sort of variable so that the branch is the one currently being viewed?
Not that I know of.
GitHub support confirms (through OP Joe Gatt 's comment)
The only way to do this would be to pass the link through my own service which would use the github's http referrer header to determine which branch is being referenced and then fetch the appropriate image from Travis CI
I would rather make one Travis-CI badge per branch, for the reader to choose or consider the appropriate when seeing the README.md.
Update 2016 (3 years later): while nothing has changed on the GitHub side, fedorqui reports in the workaround mentioned in "Get Travis Shield on Github to Reflect Selected Branch Status" by Andrie.
Simply display all the branches and their respective TravisCI badges.
If you have only two or three branches, that could be enough.
I worked around this issue with a git pre-commit hook that re-writes the Travis line in the README.md with the current branch. An example of usage and pre-commit (Python) code (for the question as asked) are below.
Usage
dandye$ git checkout -b feature123 origin/master
Branch feature123 set up to track remote branch master from origin.
Switched to a new branch 'feature123'
dandye$ echo "* Feature123" >> README.md
dandye$ git add README.md
dandye$ git commit -m "Added Feature123"
Starting pre-commit hook...
Replacing:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=master)][travis]
with:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
pre-commit hook complete.
[feature123 54897ee] Added Feature123
1 file changed, 2 insertions(+), 1 deletion(-)
dandye$ cat README.md |grep "Build Status"
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
dandye$
Python code for the pre-commit code
dandye$ cat .git/hooks/pre-commit
#!/usr/bin/python
"""
Referencing current branch in github readme.md[1]
This pre-commit hook[2] updates the README.md file's
Travis badge with the current branch. Gist at[4].
[1] http://stackoverflow.com/questions/18673694/referencing-current-branch-in-github-readme-md
[2] http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
[3] https://docs.travis-ci.com/user/status-images/
[4] https://gist.github.com/dandye/dfe0870a6a1151c89ed9
"""
import subprocess
# Hard-Coded for your repo (ToDo: get from remote?)
GITHUB_USER="joegattnet"
REPO="joegattnet_v3"
print "Starting pre-commit hook..."
BRANCH=subprocess.check_output(["git",
"rev-parse",
"--abbrev-ref",
"HEAD"]).strip()
# String with hard-coded values
# See Embedding Status Images[3] for alternate formats (private repos, svg, etc)
# [![Build Status](https://travis-ci.org/
# joegattnet/joegattnet_v3.png?
# branch=staging)][travis]
# Output String with Variable substitution
travis="[![Build Status](https://travis-ci.org/" \
"{GITHUB_USER}/{REPO}.png?" \
"branch={BRANCH})][travis]\n".format(BRANCH=BRANCH,
GITHUB_USER=GITHUB_USER,
REPO=REPO)
sentinel_str="[![Build Status]"
readmelines=open("README.md").readlines()
with open("README.md", "w") as fh:
for aline in readmelines:
if sentinel_str in aline and travis != aline:
print "Replacing:\n\t{aline}\nwith:\n\t{travis}".format(
aline=aline,
travis=travis)
fh.write(travis)
else:
fh.write(aline)
subprocess.check_output(["git", "add", "README.md" ])
print "pre-commit hook complete."
I updated the work of Dan Dye so it's now able to change any git variable into a readme. It also works now with python 3. For example, handling badges by branch for Github actions:
[![Integration Tests](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml/badge.svg?branch={{ current.branch }})](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml?query=branch%3A{{ current.branch }})
And in your pre-commit file add:
.githooks/replace_by_git_vars.py readme.md README.md -v
-v displays the available variables and more
https://gist.github.com/jclaveau/af2271b9fdf05f7f1983f492af5592f8
Thanks a lot for the solution and inspiration!
The best solution for me was to create a server where I send a query with username and repo's name and get a svg image with the build status for all branches.

How to view a single Mercurial commit from the command line?

I would like to view from the commandline what was changed in given Mercurial commit similar to what one would see from hg status or from the TortoiseHg tool. The closest I can seem to get is hg log --stat but that prints extra symbols (i.e. pluses and minuses) and I cannot specify at which specific revision I want to look.
I need this because I have developers who have check-in comments like "." or ",". >:-(
It turns out that hg status has a --change argument where you can pass the revision number (e.g. 109), relative revision (ie -1 is last commit, -2 is second-last, etc), or the hash of the revision to it and it will print out the changes (i.e. additions, removals, and modification) that revision had.
--change isolates that revision and shows just from that revision, but replacing --change with --rev shows the cumulative effect since that revision to the current state.
hg log -v -r <changeset>
changeset: 563:af4d66e2bc6e
tag: tip
user: David M. Carr <****>
date: Fri Oct 26 22:46:02 2012 -0400
files: hggit/gitrepo.py tests/test-pull.t
description:
pull: don't pull tags as bookmarks
or, using templates, something like
hg log -r tip --template "{node|short} - files: {files}\n"
with output
af4d66e2bc6e - files: hggit/gitrepo.py tests/test-pull.t

How to edit Mercurial commit message after branching?

I have some old commit messages in a Mercurial repository that should be changed (to adjust for some new tools). I already understand that this hacking has to be done on the master repository and all local repositories would have to be re-cloned, because checksums of all subsequent changesets will also change.
I've tried following the recipes in "How to edit incorrect commit messages in Mercurial?", but with MQ extension I got stuck on error message
X:\project>hg qimport -r 2:tip
abort: revision 2 is the root of more than one branch
and with Histedit quite similarly
X:\project>hg histedit 2
abort: cannot edit history that would orphan nodes
The problem seems to be that there have been branches created after the changeset.
I can see how it would become messy if I'd want to change the contents of patch, but perhaps there's a workaround that I've missed for editing the commit message?
I would use a hacked version of the convert extension to do this. The extension can do hg → hg conversions which lets you alter author and branch names. There is not support for changing commit messages yet, but you can hack it.
Specifically, you should change the getcommit method from:
def getcommit(self, rev):
ctx = self.changectx(rev)
parents = [p.hex() for p in self.parents(ctx)]
if self.saverev:
crev = rev
else:
crev = None
return commit(author=ctx.user(), date=util.datestr(ctx.date()),
desc=ctx.description(), rev=crev, parents=parents,
branch=ctx.branch(), extra=ctx.extra(),
sortkey=ctx.rev())
which is responsible for reading the old commits. Change the
desc=ctx.description()
to
desc=adjust(ctx.description())
and then implement the adjust function at the top of the file:
def adjust(text):
return text.upper()
If these are accidental/duplicate branches due to using --amend and push --force then strip them first and try 'histedit' again then wipe the central repo on bitbucket; try the following which worked for me:
Inspect the repository log and look for branches, you can use the GraphlogExtension which you will have to enable first:
# hg log -G | more
...
o changeset: 43:c2fcca731aa5
| parent: 41:59669b9dfa4a
| user: Daniel Sokolowski (https://webdesign.danols.com)
| date: Tue Aug 27 20:14:38 2013 -0400
| summary: Progress snapshot: major content text and model instance ..
...
| o changeset: 42:c50724a6f1c6
|/ user: Daniel Sokolowski (https://webdesign.danols.com)
| date: Tue Aug 27 20:14:38 2013 -0400
| summary: Progress snapshot: major content text and model instance ...
|
o changeset: 41:59669b9dfa4a
| user: Daniel Sokolowski (https://webdesign.danols.com)
...
Enable the MqExtension and strip all branches.
# hg strip --no-backup 42:c50724a6f1c6
# hg strip --no-backup 45:3420dja12jsa
...
If needed change the commit to 'draft' (see Phases) and re-run 'histedit' and all should be good now.
# hg histedit 14:599dfa4a669b
abort: cannot edit immutable changeset: b7cfa2f28bde
# hg phase -f -d 14:599dfa4a669b
# hg hsitedit 14:599dfa4a669ba
I needed something similar so I filed a feature request.

file mask to exclude *.m.swp files in git

When I run git status, *.m.swp files are showing up in the "untracked list" because I currently have these files open in MacVim (The originals are MATLAB files with *.m file extensions).
I have tried adding *.m.swp, and various permutations of this, to my .gitignore file so that the files are ignored, but nothing seems to work for me.
See an example of git status output below:
git status
# On branch mybranch1
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: ../dir1/file1.m
# new file: file2.m
# new file: file3.m
# modified: file4.m
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ../../dir2/.file5.m.swp
# ../dir1/.file6.m.swp
# ../dir1/.file1.m.swp
# ../dir1/.file7.m.swp
# ../dir1/.file8.swp
# .file9.m.swp
# .file4.m.swp
How can I get git to ignore these? Thanks in advance for any help!
.*.m.swp
should work: I have tested it in my msysgit1.7.4 environment.
So: not "*..." but ".*...".
Don't forget to add your modified .gitignore to the index before doing a new git status.
.*\\.m\\.swp
do this instead, since unescaped .'s match anything