Skip to content
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

build: improve sed robustness by not using sed #19761

Merged
merged 11 commits into from Aug 27, 2020

Conversation

fanquake
Copy link
Member

While using sed can be handy to use for a quick-fix, these instances accumulate, and can become unmaintainable. Not only that, but using sed isn't necessarily robust and it can fail silently. Most of our usage is also missing any documentation explaining why something is being done, when it should be updated/removed etc.

Rather than relying on sed going forward, where possible, I've converted our sed usage into patches. These are easier to maintain, contain documentation, and should fail loudly when they don't apply.

The remaining sed usage, (1 in miniupnpc, the rest in qt), are non-trivial to remove, as they are using build-time variables, or some input from the environment.

This also steals 2 related commits out of #19716.

Related to #16838.

@practicalswift
Copy link
Contributor

Concept ACK

@theuni
Copy link
Member

theuni commented Aug 18, 2020

Concept ACK. This will make simple bumps more complicated, but arguably that's a good thing.

Also +1 for self-documentation.

@laanwj
Copy link
Member

laanwj commented Aug 19, 2020

Lovely PR title 😄

Concept ACK. I remember having some discussions about this in the past (with @dongcarl ?). It has always bothered me that sed can fail silently. This is especially problematic because changes can be lost without noticing when bumping versions. This has in the past resulted in losing propagation of hardening flags and such.

@hebasto
Copy link
Member

hebasto commented Aug 19, 2020

Concept ACK.

@dongcarl
Copy link
Contributor

Concept ACK!
All the ways I've tried fixing this before weren't satisfactory, and this is a nice and simple approach.

One q: I often see -N being using in most patch invocations, would we want that?

@fanquake
Copy link
Member Author

I'm glad everyone agrees with the approach. I've pushed a fix the docs in one patch file.

One q: I often see -N being using in most patch invocations, would we want that?

I've done some testing and think it could be a worthwhile addition. It seems if anything it causes patch to "fail faster". i.e chain applying the same patch with and without it:

# no -N
patch -p1 -i a.patch && patch -p1 -i a.patch && patch -p1 -i a.patch
patching file test.cpp
patching file test.cpp
Reversed (or previously applied) patch detected!  Assume -R? [n] n
Apply anyway? [n] n
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file test.cpp.rej

# reset
git stash
Saved working directory and index state WIP on master: cdb5127 init

# Using -N
patch -N -p1 -i a.patch && patch -N -p1 -i a.patch && patch -N -p1 -i a.patch
patching file test.cpp
patching file test.cpp
Reversed (or previously applied) patch detected!  Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file test.cpp.rej

So without -N you'll be asked for input, as opposed to just failing.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 20, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@hebasto
Copy link
Member

hebasto commented Aug 24, 2020

Reviewing commits:

  • 5f98794 "build: use patch rather than sed in bdb package"
  • 53afb71 "build: use patch rather than sed in Boost package"
  • 45f3360 "build: use patch rather than sed in fontconfig package"
  • b214067 "build: use patch rather than sed in native_cctools package"
  • e995635 "build: use patch rather than sed in zeromq package"
  • 6d42439 "build: remove no-longer needed qt configure workaround"
  • 5b121cb "build: remove no-longer needed qt workaround"
  • 5bdea1d "build: replace pwd sed in qt package with a patch"
  • e2b18a4 "build: replace FreeType back-compat sed with a patch in qt package"
  • 37d9898 "build: replace qtranslations ltranslate sed with a patch in qt package"
  • 0b0f480 "build: replace wingenminiupnpcstrings sed with a patch in miniupnpc package"

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK 0b0f480.

I've verified that patch changes are equal to sed changes.
I've verified that dropped workarounds are effectively noop.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@fanquake fanquake deleted the maximum_sed_robustness branch September 22, 2020 23:53
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2020
Summary:
```
While using sed can be handy to use for a quick-fix, these instances
accumulate, and can become unmaintainable. Not only that, but using sed
isn't necessarily robust and it can fail silently. Most of our usage is
also missing any documentation explaining why something is being done,
when it should be updated/removed etc.

Rather than relying on sed going forward, where possible, I've converted
our sed usage into patches. These are easier to maintain, contain
documentation, and should fail loudly when they don't apply.

The remaining sed usage, (1 in miniupnpc, the rest in qt), are
non-trivial to remove, as they are using build-time variables, or some
input from the environment.
```

Backport of core [[bitcoin/bitcoin#19761 | PR19761]], slightly updated to match our depends.

Depends on D7760.

Test Plan:
  make build-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D7763
zkbot added a commit to zcash/zcash that referenced this pull request Oct 12, 2020
depends: Use patch rather than sed in bdb package

This converts a sed command within a makefile into a static patch file in the
`./depends` system for `bdb`. We use `sed` in some dependencies to replace
some "dynamic" stuff, where regular expressions are necessary (such as to
remove build-non-reproducibility, I believe). However, whenever we can use a
patchfile, I feel that's superior because it's easier to manually read a patch
file and it's known that the change is "static".

Equivalent to the first commit in bitcoin/bitcoin#19761
fanquake added a commit that referenced this pull request Nov 22, 2020
e1f2553 build: remove global_init_link_order from mac qt qmake.conf (fanquake)
498fa16 build: document preprocessing steps in qt package (fanquake)
bd5d933 build: don't copy Info.plist.* into mkspec for macOS qt build (fanquake)
bfd7e33 build: remove plugin_no_soname from mac qt qmake.conf (fanquake)
fdde4c7 build: pass XCODE_VERSION through to qt macOS cross compile conf (fanquake)
49473ef build: convert "echo" usage into a patch in qt package (fanquake)

Pull request description:

  Follow up on removing `sed` usage in #19761. Also nice to revisit & cleanup before 5.15.x.

ACKs for top commit:
  laanwj:
    Code review ACK e1f2553

Tree-SHA512: 4e6489d877aaa300f69e091d7117136da49611bd80afd45adfbd7ddeb5b3c9c76fb0f87a3249cbe63ba93129df56281fd4a9389daadc852211325c5ca9ac6567
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 13, 2021
Summary:
```
While using sed can be handy to use for a quick-fix, these instances
accumulate, and can become unmaintainable. Not only that, but using sed
isn't necessarily robust and it can fail silently. Most of our usage is
also missing any documentation explaining why something is being done,
when it should be updated/removed etc.

Rather than relying on sed going forward, where possible, I've converted
our sed usage into patches. These are easier to maintain, contain
documentation, and should fail loudly when they don't apply.

The remaining sed usage, (1 in miniupnpc, the rest in qt), are
non-trivial to remove, as they are using build-time variables, or some
input from the environment.
```

Backport of core [[bitcoin/bitcoin#19761 | PR19761]], slightly updated to match our depends.

Depends on D7760.

Test Plan:
  make build-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D7763
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 24, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 25, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 25, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 26, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 26, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 26, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 27, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Aug 30, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 1, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 1, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 1, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 2, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 3, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 3, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 3, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 4, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants