How to Apply Patches?

4,171 views
Skip to first unread message

Gani Bhagavathula

unread,
Apr 21, 2009, 1:07:44 PM4/21/09
to android-porting
Hi all:

I have seen some patches at the site
http://code.google.com/p/patch-hosting-for-android-x86-support/updates/list
- How do I apply those patches?

I have tried patch -p0 < cursor.patch for example, and get the
following query

can't find file to patch at input line 6
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|project frameworks/base/
|diff --git a/core/java/android/view/RawInputEvent.java b/core/java/
android/view/RawInputEvent.java
|index 30da83e..4d9a11a 100644
|--- a/core/java/android/view/RawInputEvent.java
|+++ b/core/java/android/view/RawInputEvent.java
--------------------------

am I supposed to change the lines in the patch file (replace a/ with
my actual path?)

Regards,
Gani

Yi Sun

unread,
Apr 21, 2009, 1:12:05 PM4/21/09
to android...@googlegroups.com
cd frameworks/base
patch -p1 < <where you patch is>

Gani Bhagavathula

unread,
Apr 21, 2009, 1:42:25 PM4/21/09
to android-porting
So, if a file had three patches, then I would move to the base
directory of the files mentioned in the .patch file, and then go

patch -p1 < patchfile.name
patch -p2 < patchfile.name
patch -p3 < patchfile.name

like that?

Regards,
Gani

On Apr 21, 6:12 pm, Yi Sun <beyo...@gmail.com> wrote:
> cd frameworks/base
> patch -p1 < <where you patch is>
>
> On Tue, 2009-04-21 at 10:07 -0700, Gani Bhagavathula wrote:
> > Hi all:
>
> > I have seen some patches at the site
> >http://code.google.com/p/patch-hosting-for-android-x86-support/update...

Michael Trimarchi

unread,
Apr 21, 2009, 1:48:38 PM4/21/09
to android...@googlegroups.com
Hi,

Gani Bhagavathula wrote:
> So, if a file had three patches, then I would move to the base
> directory of the files mentioned in the .patch file, and then go
>
> patch -p1 < patchfile.name
> patch -p2 < patchfile.name
> patch -p3 < patchfile.name
>

the p<x> is not the patch number but the strip on the path as reported
by the
manual (man patch)

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

Michael

PS: the man command can help you

Yi Sun

unread,
Apr 21, 2009, 1:51:12 PM4/21/09
to android...@googlegroups.com
-p1 is good for all the patches.
try read "man patch" and you will get it.

Gani Bhagavathula

unread,
Apr 21, 2009, 2:10:54 PM4/21/09
to android-porting
Guys:

Thanks so much for this. Believe me, I did read the man page, but
could not make sense of it... If I look at it now after you guys have
explained it, it seems so obvious...

Thanks again.

Gani

kewarken

unread,
Apr 22, 2009, 10:04:02 AM4/22/09
to android-porting
If you want to apply them all at once, since the patches follow a
pattern, you can do something like this from your cupcake source dir
with the patches in the directory above it:

for patch in `pwd`/../*patch ; do
project=`awk '/^project /{print $2}' $patch`
(cd $project && patch -p1 < $patch)
done

cheers,

Kris

On Apr 21, 2:10 pm, Gani Bhagavathula <gani.bhagavath...@gmail.com>
wrote:

igame

unread,
Apr 22, 2009, 10:33:54 AM4/22/09
to android-porting
After some attempts, I found that it's a problem around path. I used
the following way to apply these patches:
run patch -p1 < xyz.patch, the return message contains the path info,
it's the working path of patch. e.g.
$patch -p1 < alarm.patch
can't find file to patch at input line 6
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
| project kernel/ <--- enter this directory
to apply patch
| diff -- git a/drivers/rtc/alarm.c b/drivers/rtc/alarm.c
......

So,
1)alarm.patch:
$cd <your android source dir>
$find ./ -name alarm.c
../system/core/toolbox/alarm.c
../kernel/drivers/rtc/alarm.c <-- patch should apply on it!
../bionic/libc/unistd/alarm.c

$cd <your android source dir>/kernel
$patch -p1 < <your android source dir>/patches/alarm.patch

.....

2)cursor.patch
Enter <your android source dir>/frameworks/base to apply it.

3)frameworks.patch
same as cursor.patch

4)e2fsprogs.patch
Enter <your android source dir>/external/e2fsprogs/ to apply it.

Good luck.

On Apr 22, 2:10 am, Gani Bhagavathula <gani.bhagavath...@gmail.com>
wrote:

Yi Sun

unread,
Apr 22, 2009, 1:35:06 PM4/22/09
to android...@googlegroups.com
Nice script, I will add this to the Wiki in you don't mind.
THanks
Yi

Chih-Wei

unread,
Apr 24, 2009, 6:43:23 AM4/24/09
to android-porting

I'd like to suggest to use 'git apply $patch' instead of 'patch -p1
$patch' directly,
as it would apply the patch in atomic way (all success, or all fail).

Kasuko

unread,
May 8, 2009, 5:19:43 PM5/8/09
to android-porting
Also you might want to add the following to certain files before
running Kris's script.

in put "project frameworks/base/" as first line
in "0001-1.-added-mouse-cursor.patch" put "project frameworks/base/"
as first line
in "0001-1.-enabled-power-mgt.patch" put "project vendor/asus/
eee_701/" as first line
in "atl2-2.2.3.patch" put "project kernel/" as first line

that will allow his script to pick up the locations to patch for
the .patch files that do not have this directive.

Also as Chih-Wei mentioned, try

for patch in `pwd`/../*patch ; do
project=`awk '/^project /{print $2}' $patch`
(cd $project && git apply $patch)
done

Kasuko

On Apr 24, 6:43 am, Chih-Wei <cwhu...@linux.org.tw> wrote:
> I'd like to suggest to use 'git apply $patch' instead of 'patch -p1
> $patch' directly,
> as it would apply the patch in atomic way (all success, or all fail).
>
Reply all
Reply to author
Forward
0 new messages