Skip to content

Commit 69275d5

Browse files
committed
ENH: add infrastructure automatically applying patch files
1 parent 223a844 commit 69275d5

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

README.rst

+7
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ run very simply as follows:
3636
To update the version of Boost, give a different Boost version to the
3737
`--boost-version` option in the format: `[major].[minor].[patch]`.
3838
The `-v` option is optional and turns on verbose logging.
39+
40+
Patches
41+
-------
42+
43+
Patches (e.g., from cherry-picking upstream commits) can be applied by placing
44+
`.patch` files generated using `git diff` in the `patches` directory. See
45+
`PATCHES <patches/PATCHES.rst>`_ for more information.

make_headers.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''Generate header files from Boost source distribution.'''
1+
"""Generate header files from Boost source distribution."""
22

33
import argparse
44
import gzip
@@ -78,24 +78,38 @@ def _generate_headers(ver: str, verbose: bool):
7878
logger.info('Updating header files')
7979
if (base / 'boost').exists():
8080
shutil.rmtree(base / 'boost')
81+
for f in pathlib.Path(__file__).parent.glob("Boost_*_README.md"):
82+
f.unlink()
8183
shutil.move(dst / 'boost_tmp_build/include/boost', base / 'boost')
8284
shutil.move(dst / archive_name / 'LICENSE_1_0.txt', base / 'LICENSE_1_0.txt')
8385
shutil.move(dst / archive_name / 'README.md', base / f'Boost_{BOOST_VER_UND}_README.md')
8486
finally:
85-
# We want to save the tar file as a temporary file and simulataneously
87+
# We want to save the tar file as a temporary file and simultaneously
8688
# extract it, meaning it will need to be opened in a context manager
8789
# multiple times. While Linux can handle nested context managers
8890
# using the same file handle, Windows cannot. So we have to mark the
8991
# temporary file "ntf" as delete=False, close its context manager, and
9092
# then ensure cleanup happens in this "finally" statement
9193
ntf.close()
9294

93-
logger.info('Done!')
95+
logger.info('Done creating base Boost headers!')
96+
97+
logger.info("Applying patches...")
98+
patch_dir = pathlib.Path(__file__).parent / "patches"
99+
for f in patch_dir.glob("*.patch"):
100+
if subprocess.run(["git", "apply", str(f)], cwd=base).returncode != 0:
101+
logger.error(f"Failed to apply patch: {f}. Skipping.")
102+
logger.info(f"Applied {f}")
103+
else:
104+
logger.info("Found no patches to apply!")
105+
106+
logger.info("Done!")
94107

95108

96109
if __name__ == '__main__':
97110
parser = argparse.ArgumentParser(__doc__)
98-
parser.add_argument('--boost-version', type=str, help='Boost version to download formatted as [major].[minor].[patch].', default='1.75.0')
111+
parser.add_argument('--boost-version', type=str,
112+
help='Boost version to download formatted as [major].[minor].[patch].', required=True)
99113
parser.add_argument('-v', action='store_true', help='Enable verbose logging.', default=False)
100114
args = parser.parse_args()
101115
_generate_headers(ver=args.boost_version, verbose=args.v)

patches/PATCHES.rst

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Applying Patch Files
2+
--------------------
3+
4+
All `.patch` files found in this directory will be applied to this repository.
5+
Any that fail will be ignored with a logging error message.
6+
7+
To generate patch file, the following command can be used:
8+
9+
::
10+
11+
git diff [commit] [commit] > patches/myCoolPatchFile.patch
12+
13+
Any variation on the `git diff` command should also succeed in producing a
14+
suitable patch file.

0 commit comments

Comments
 (0)