RPM - Creating Patches
Creating Patches
Patches are text files generated by the diff tool which compares files or directories and records the differences in a certain format. Those differences can then be re-applied to the original source using patch.
To create a patch file, you therefore need the original source and a copy. You can program your changes by editing, adding, or deleting files in the copy. Then use diff to compare the original source with the changes you made in the copy and record those changes in a patch file.
Normally you would want to add your changes to source files to which all previous patches have already been applied. You can obtain
the patched source code by using the -bp
option with rpmbuild, which downloads the code and applies all
patches.
$
rpmbuild -bp ~/rpmbuild/SPECS/adempiere.spec
Then you can copy the source directory to new locations, one ending on .orig
and the other ending on .new
.
$
cp -r ~/rpmbuild/BUILD/adempiere-…/source/custom adempiere.orig
$
cp -r ~/rpmbuild/BUILD/adempiere-…/source/custom adempiere.new
Start hacking your heart out and make any changes you want in adempiere.new
.
3
When you are done, go back to the parent directory and run diff to compare
adempiere.orig
with adempiere.new
$
diff -durNbB adempiere.orig adempiere.new > myPatch.patch
These are the options used in above diff command:
- -d
forces diff to search for smaller sets of changes than it normally would
- -u
generates unified output format, which is required by patch
- -r
recursively compare subdirectories
- -N
if a file is only found in one directory, treat it as present but empty in the other directory
- -b
ignores changes only in whitespace
- -B
ignores changes only in blank lines
The resulting patch file can be added to the SOURCES
directory and listed in the Spec File as
previously explained.
Note that when the patch file was created, you were in the parent directory which contains the source directory tree. But when the
patch is being applied by rpmbuild, you will actually be inside the source directory tree. Therefore, the first
directory component of filenames generated by diff must be ignored when running the patch
command. This is achieved by passing -p1
to patch.
[3]
Be careful not to actually compile the code! You only want to save changes made to the source code. But if you compile the code, many new files will be created which do not exist in the original source, and diff would regard all of those files as additions you made to the source.