kwindrem / SetupHelper

Helper functions to simplify writing setup scripts that modify VenusOs functionality. The package includes automatic reinstallation of the package after a VenusOs update.
153 stars 18 forks source link

Using patched files #75

Closed drtinaz closed 2 months ago

drtinaz commented 2 months ago

Kevin I have been looking at the documentation for the recent changes to setuphelper and am interested in using the patch function going forward. How would this effect previous versions of the package? Would I need to rebuild the package including previous venus firmware versions? Would updatePackage have a stroke and blow up any previous FileSets?

kwindrem commented 2 months ago

The patch function can be used at the same time as version-dependent and version-independent (replacement) modifications. CommonResources and updatePackage base their activity on which file set specifies the active file. So you do not need to rebuilt any existing packages. But you could change the package over from replacement-based to patcher-based even for just some files. In fact, SetupHelepr uses a patch for one file and version independent in the others.

Note that one specific patch-like modification is done to version independent files: converting from VisibleItemModel to VisualItemModel for .qml files in Venus OS prior to v2.80 (I think). I use 'sed' for this mod.

I also use 'sed' for mods like config.txt on Raspberry PI. And this is always package-specific and done in the setup script itself.

Note that currently, the patch-based install still replaces the active file on install and restores the original on uninstall. This isn't ideal but it's the way it works currently. So patch-based would still have the same package conflicts as simply replacing the file.

Patch-based installs only work if the same .patch file can be used for all supported Venus OS versions. I played around with this a bit and found that was not possible in all cases. Of course, I'm supporting Venus OS back to v2.71 in my packages.

For a patch to modify the active file directly, a reverse patch would be needed and the version of patch included with Venus OS does not support the reverse option.

updatePackage does not automatically generate patch files but does have that option. The .source and .edited files are created manually and provide what is necessary for updatePackage to generate the .patch file. However, I've found that you sometimes need to manually edit the .patch file so it will address more Venus OS versions.

So for now, patch-based install is useful in limited circumstances but is a step closer to version-independent installs.

Glad you are looking at the patch-based installs. I'm all for making it more useful so if you have anything to add, please pass it on.

drtinaz commented 2 months ago

I'm going to give this a go with one of my simpler packages that only replaces one file.

So if I understand correctly, the files that need to be placed in the PatchSource directory are 'somefile.source' (a version of the active or original file) and 'somefile.edited' ( a version of the expected replacement file)? And then when I run updatePackage I will get a prompt to create the ,patch file, which will then also be placed in the PatchSource directory? Or is the .patch file then placed in the specific version fileset? And then I obviously also need to make the other necessary changes to the setup script. Do I have that correct? If the original file is somefile.js then the source file in the PatchSource directory would be somefile.js.source?

kwindrem commented 2 months ago

Exactly. You would also need to add the path to the active file to the fileListPatched file. This is what updatePackge uses to identify patch file creation.

updatePackage will also apply the patch file to each stock file in all fileSets and report if patch reports an error. Note that this isn't necessarily an exhaustive test since doing that would need the expected result for each version which defeats the purpose of patch-based replacements.

drtinaz commented 2 months ago

Kevin I am having an issue with one of the patch files in one of my packages. The first package I rebuilt for using patch files went pretty smooth, as it only patches a single file, and does nothing else. It works great.

Another package I am currently working on patches three files, one of which is fairly large, and is patched in two places (the latter being the problem file). The .patch file (in the PatchFile folder) has been created properly, and I have opened it and verified that the correct added lines of code do exist. The issue is that when setup runs and the active file is patched, only the first part of the patch is being applied, not the second part. Is this a known issue or limitation when patching files? Is there some other step I am missing?

kwindrem commented 2 months ago

I know of no limitations. Have you tried manually applying the patch?

Is the file you are patching the same as the .source file or is it from another Venus OS version?

If it's from a different Venus OS version than the one you created the .patch file from, try running that manually. See if any errors are reported or any reject files created. Might provide a clue.

The BusyBox version of patch is a bit limited so you might transfer the source you are having trouble with and the .patch file to another machine and run it there with verbose enabled.

drtinaz commented 2 months ago

It turns out that the second chunk was being applied, but to the wrong part of the code. I simply re-created the patch file using diff -U6 to include 6 lines before and after the added lines, instead of the default 3. Works now. Thanks for your help.