|
| 1 | +--- |
| 2 | +name: update-third-party |
| 3 | +description: 'Update an ITK third-party library to a new version. Use when: bumping a vendored dependency version, updating ThirdParty module, running UpdateFromUpstream.sh. Creates a new branch with the tag-update commit and runs the extraction script.' |
| 4 | +argument-hint: 'Which third-party library to update and the new version/tag' |
| 5 | +--- |
| 6 | + |
| 7 | +# Update ITK Third-Party Library |
| 8 | + |
| 9 | +Creates a new git branch with the commits needed to update a vendored third-party library in `Modules/ThirdParty/`. |
| 10 | + |
| 11 | +## When to Use |
| 12 | + |
| 13 | +- Updating a third-party library (e.g., JPEG, ZLIB, HDF5, GoogleTest) to a new upstream version |
| 14 | +- User says "update <library> to <version>" |
| 15 | + |
| 16 | +## Inputs |
| 17 | + |
| 18 | +Gather these from the user before starting: |
| 19 | + |
| 20 | +| Input | Example | Required | |
| 21 | +|-------|---------|----------| |
| 22 | +| Library name | `JPEG`, `ZLIB`, `GoogleTest` | Yes | |
| 23 | +| New version/tag | `3.1.0`, `v1.18.0`, commit hash | Yes | |
| 24 | +| Branch name | `update_jpeg` | No (auto-generated) | |
| 25 | + |
| 26 | +## Procedure |
| 27 | + |
| 28 | +### 1. Locate the Update Script |
| 29 | + |
| 30 | +Find the module's update script in `Modules/ThirdParty/<NAME>/`. The script name varies: |
| 31 | +- Most modules: `UpdateFromUpstream.sh` |
| 32 | +- DoubleConversion: `UpdateDoubleConversionFromGoogle.sh` |
| 33 | + |
| 34 | +If there is no update script it is an error! STOP. |
| 35 | + |
| 36 | +Read the script to understand the module's configuration (`name`, `tag`, `repo`, `paths`, `extract_source` function). |
| 37 | + |
| 38 | +### 2. Create a New Branch |
| 39 | + |
| 40 | +```bash |
| 41 | +git fetch origin |
| 42 | +git checkout -b update_<lowercase_name> origin/main |
| 43 | +``` |
| 44 | + |
| 45 | +Replace `<lowercase_name>` with a short snake_case identifier (e.g., `update_jpeg`, `update_zlib`, `update_hdf5`). If the user specifies a branch name, use that instead. |
| 46 | + |
| 47 | +### 3. Update the Tag in the Update Script |
| 48 | + |
| 49 | +Edit the `readonly tag="..."` line in the update script to the new version. Only change the `tag` value — nothing else. |
| 50 | + |
| 51 | +Commit this change: |
| 52 | + |
| 53 | +```bash |
| 54 | +git add Modules/ThirdParty/<NAME>/<UpdateScript>.sh |
| 55 | +git commit -m "ENH: Update <library-name> to <version>" |
| 56 | +``` |
| 57 | + |
| 58 | +The commit message body may optionally include links to upstream release notes or changelog. |
| 59 | + |
| 60 | +### 4. Run the Update Script |
| 61 | + |
| 62 | +```bash |
| 63 | +./Modules/ThirdParty/<NAME>/<UpdateScript>.sh |
| 64 | +``` |
| 65 | + |
| 66 | +This script (powered by `Utilities/Maintenance/update-third-party.bash`): |
| 67 | +1. Clones the upstream repository |
| 68 | +2. Checks out the specified tag |
| 69 | +3. Runs `extract_source()` to prepare a clean subtree |
| 70 | +4. Finds the previous import commit via git history |
| 71 | +5. Merges the upstream changes into `Modules/ThirdParty/<NAME>/src/` |
| 72 | +6. Creates a merge commit. |
| 73 | + |
| 74 | + |
| 75 | +### 5. Resolve Any Merge Conflicts |
| 76 | + |
| 77 | +If there are merge conflicts during the extraction step, the script will pause and prompt you to resolve them in the `work/` directory. |
| 78 | + |
| 79 | +Inspect the git history for local changes, and determine ITK's local changes, and the upstream changes. Use your judgment to resolve the conflicts, then stage and commit the resolved files. |
| 80 | + |
| 81 | +```bash |
| 82 | +git add <resolved-files> |
| 83 | +git commit |
| 84 | +``` |
| 85 | + |
| 86 | + |
| 87 | +### 6. Handle Post-Update Steps (if needed) |
| 88 | + |
| 89 | +Some modules require additional work after extraction: |
| 90 | + |
| 91 | +- **Mangling**: If the module uses symbol mangling, you may need to regenerate the mangled headers. This is common for C libraries like JPEG and ZLIB. Follow the instructions in the module's `src/` directory (e.g., `src/itkjpeg/src/itk_jpeg_mangle.h.in`). |
| 92 | +- **Build fixes**: If the upstream CMake changed significantly, the module's outer `CMakeLists.txt` may need updates. Commit these as separate `COMP:` or `ENH:` commits. |
| 93 | + |
| 94 | + |
| 95 | +### 7. Verify the Result |
| 96 | + |
| 97 | +Verify the commit history: |
| 98 | + |
| 99 | +```bash |
| 100 | +git log --oneline -3 |
| 101 | +git diff HEAD~2..HEAD --stat |
| 102 | +``` |
| 103 | + |
| 104 | +### 8. Build and Test the changes locally |
| 105 | + |
| 106 | +Build ITK with the updated module to ensure there are no build errors. |
| 107 | +### 9. Push and Create PR |
| 108 | + |
| 109 | +The branch is ready for pushing and PR creation. The PR should target `main`. |
| 110 | + |
| 111 | +Determine which remote is the user's fork: |
| 112 | + |
| 113 | +```bash |
| 114 | +git remote -v |
| 115 | +``` |
| 116 | + |
| 117 | +Push the branch to the user's fork: |
| 118 | + |
| 119 | +```bash |
| 120 | +git push <remote-name> update_<lowercase_name> |
| 121 | +``` |
| 122 | + |
| 123 | +Use the GitHub MCP to create a PR for `main` with a title like "ENH: Update <library> to <version>". The PR description should include: |
| 124 | +- A summary of the update |
| 125 | +- Links to upstream release notes or changelog |
| 126 | +- Any relevant notes about the update (e.g., if there were significant merge conflicts or build |
| 127 | +fixes needed) |
| 128 | +- That the commit was generated by the `update-third-party` skill |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +## Troubleshooting |
| 133 | + |
| 134 | +| Problem | Solution | |
| 135 | +|---------|----------| |
| 136 | +| `No previous import commit found` | The module may use `exact_tree_match=false`; check the script | |
| 137 | +| Merge conflicts during extraction | Resolve conflicts under the ThridParty directory |
| 138 | +## Reference |
| 139 | + |
| 140 | +- Official documentation: [Updating Third Party Projects](../../../Documentation/docs/contributing/updating_third_party.md) |
| 141 | +- Master update script: [Utilities/Maintenance/update-third-party.bash](../../../Utilities/Maintenance/update-third-party.bash) |
| 142 | +- All third-party modules: [Modules/ThirdParty/](../../../Modules/ThirdParty/) |
0 commit comments