How do I 'Apply patch'?

I’m following the instructions on building PyTorch from source on this page - PyTorch for Jetson

The instructions say

Apply Patch
Select the patch to apply from below based on the version of JetPack

I can access the correct patch okay.

Excuse my ignorance but how do I then ‘apply the patch’?

Many thanks!
Peter

Here’s a useful article on the topic:
https://www.thegeekstuff.com/2014/12/patch-command-examples/

What it comes down to is that there is another program, diff, which is able to produce a shorthand syntax to describe where lines of text-based files differ. The patch command is able to use that syntax to edit just those lines in another file. One might ask why not just copy the one file over the top of another, but that is because diff and patch can look at specific functions or pieces of files and is not stuck replacing entire files. One can provide the diff for one small subset of a lot of code.

Pay attention to the patch command’s “-p number” argument in that article. You don’t always need this, but basically it is a way to deal with subdirectories. Maybe a patch is provided recursively to a lot of files, and the file being patched is three directories in, but you are applying the patch from fewer directories in. In that case the “-p number” can be used to strip how many subdirectories in the file is looked for.

Examine your patch file with an ordinary text editor. It will name a couple of files. Lines will be listed with --- to remove, and the new version with +++. If the patch command is used correctly, then it will tell you about “hunks” succeeded (those are pieces of files). Once the patch succeeds, then that part of the file will now be an exact match to the lines in the original file the diff generated against.

If it turns out that your source code is a mix of parts which comply and parts which are incorrect, then you will get a mix of success for the parts that differed and were fixed, and a set of fails for the parts which are already correct.

Many thanks for that linuxdev.

I did open the patch file with a text editor, and it all became a bit clearer !

What worked for me was changing all the path instances (which in the file were simply a/ and b/ ) to absolute paths (/home/peter/and_so_on…), and running patch from the root directory (/).

Regarding the -p option - I believe if you don’t include it, it will strip all of the path off, so probably wise to include
-p0 to make sure your intended path stays intact.

All sorted anyway. On to the next problem !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.