-
Notifications
You must be signed in to change notification settings - Fork 990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Patch scripts #14481
Comments
Hi @iskunk Thanks for your suggestion. That tool is mostly for ConanCenter patches, so this should be also checked with the team. |
Yes, I should have clarified; I am following the "private Conan Center" workflow. Hope the CC folks go for this. I've long used Perl one-liners as a pre-build "patch" mechanism, and it works very well. Patch files, in my view, are better suited for recording and applying hand-crafted edits. |
Alternatively you could solve this by a e.g.
or
|
The point of this is to have patch scripts organized and applied as peers to regular patch files in the existing framework. It would be poor form to have patch files in one place, and patch scripts in another, when they ultimately serve the same purpose. |
Hi @iskunk I have been discussing this proposal with the team, and the main problem is that this is something that we would need to actively forbid in ConanCenter, as patches applied this way could be quite problematic and challenging to review, the team is quite concerned about this, so not allowing this at the moment in ConanCenter. While we understand the use case, it seems this would still be a niche request for adding to So many thanks for your suggestion, but at the moment it will not be considered for addition to the |
Thank you for your consideration @memsharded, I will work on a private implementation of this idea. One thing to note, however:
For certain types of changes, it is entirely possible to have the edits resulting from a find(1)+Perl one-liner yield a multi-megabyte patch. And that patch might need to be regenerated with each new version of the upstream source, as things shift around. Reviewing such a "patch script" is going to be different from reviewing a normal patch, but there is clearly a point where it wins out on time and tedium. Keep that in mind, and I'll be happy to revisit this topic if it comes up again. |
That is exactly the point. If there is a huge patch file, the team want it very evident, and it will be probably rejected. Source code changes are a red flag to be reviewed carefully in ConanCenter, and most other build system patches should be as minimal as possible. It is possible to do large changes in codebases with very small scripts that can be skipped/missed because the reviewers are usually overwhelmed, and the idea is that diffs are more visually impacting than small scripts |
That is a site-policy matter, however. Whether or not ConanCenter would use this feature is distinct from whether it is generally useful enough (for other sites with different policies) to be in Conan proper. In my org's use case, new/updated patch scripts will not be a frequent occurrence, and of course they will be carefully reviewed. (BTW, I've found that bolting on this functionality externally is awkward due to Wanting a large visual impact for a large change is reasonable, but that doesn't necessarily have to come from a physically large patch file. For example, Conan could list all files with updated timestamps after the script is run, or even do a recursive diff against a copy of the original tree. (It'll be slow, for sure---but if a user is really worried about the script not behaving as expected, it could still be a time-saver over maintaining patches.) There are other ways to scratch that itch without having to record the changes explicitly. |
You can already accomplish the same task perfectly well in a def _patch_sources(self):
apply_conandata_patches(self)
for path in self.source_path.rglob("*.[ch]"):
content = path.read_text()
content = re.sub(r"\bclass\b", "klass", content)
path.write_text(content)
# or
def _patch_sources(self):
apply_conandata_patches(self)
count = 0
for path in self.source_path.rglob("*.[ch]"):
content = path.read_text()
content, n = re.subn(r"\bclass\b", "klass", content)
if n > 0:
path.write_text(content)
count += 1
self.output.info(f"Patched 'class' to 'klass' in {count} source files")
def build(self):
self._patch_sources()
... |
Maybe this is something that could make sense, I'll re-open to propose to the team and see what they think. |
Hi @valgur,
The point is not "modify sources programmatically in Conan in some/any way"; the point is "modify sources programmatically in Conan in the same workflow as patch files." This will eventually form part of a process in a larger organization, and in that context, handling patch scripts as peers to patch files/strings (i.e. that they are both recorded in the same place, and can be inventoried/maintained/audited in the same place) is critically important. (Also, note that your sample code doesn't account for different package versions needing different edits. Once you add support for that, you can see that you're starting to recreate the
I am much obliged, @memsharded. A few notes for consideration:
|
I am proposing #14576 to define |
#14576 closed this issue, to be released next 2.0.10 |
Thanks @memsharded. Now I can make my function a supplement to For reference, here are my supplements to
|
What is your suggestion?
Sometimes, the easiest way to patch source code prior to compilation is not with a patch file, nor a patch string, but with a script that has the effect of modifying the source in the desired way.
For example, imagine a C source tree that uses
class
as a variable name, and thus cannot be compiled by a C++ compiler. You need to change every instance ofclass
into e.g.klass
. There are many instances of this variable. A patch would be large and difficult to review. But if you could run a shell command......you could potentially solve the problem in one line. (Perhaps some additional logic is needed to handle exceptions to this replacement, but overall it's still going to weigh in significantly smaller than the patch.)
Being able to specify such a patch script in the
conandata.yml
file would be quite useful. I already have patches with header text like "The modifications in this patch were generated by the following shell command: ...".As I see it, a patch script can take one of three forms:
Security may be a concern, but I don't see this as much different than the Turing-complete logic that is invoked in the course of a build anyway.
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: