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

[bldr-build] Adds new helper function & default phase implementations. #136

Merged
merged 1 commit into from
Jan 11, 2016

Conversation

fnichol
Copy link
Collaborator

@fnichol fnichol commented Jan 11, 2016

This change introduces several new public-facing helper functions:

  • download_file()
  • verify_file()
  • unpack_file()

This allows a Plan author to use these functions to download, verify, or
unpack additional archives and artifacts. The default phase behavior use
these new functions under the covers and ensures there is one code path
to perfom the above mentioned tasks.

Additionally a new compositional style is unlocked with the creation of
a "default" implementation for each phase function. The first class
phase functions can then be overridden by Plan authors (as before), but
now they can invoke the original implementation before adding more
behavior. The following new public-facing helper functions have been
added:

  • do_default_begin()
  • do_default_download()
  • do_default_verify()
  • do_default_clean()
  • do_default_unpack()
  • do_default_prepare()
  • do_default_build()
  • do_default_install()
  • do_default_build_config()
  • do_default_build_service()
  • do_default_strip()
  • do_default_dockerfile_inline()
  • do_default_docker_image()
  • do_default_end()

For an example that ties both of these concepts together, consider a
slightly non-standard Plan that must download multiple patches to be
applied on top of a base release. Readline is such an example. Here is a
young version of part of a Readline Plan which downloads and verifies a
collection of patches in the appropriate phase callback functions. The
default behavior of downloading, verifying, and unpacking the main
source archive is preserved by augmenting the do_download() and
do_verify() callbacks.

Example:

 # The root URL for all official patch files
_patch_url_base=$_url_base/${pkg_name}-${_base_version}-patches/${pkg_name}${_base_version//.}

 # All official patch file URLs
_patch_files=(
  ${_patch_url_base}-001
  ${_patch_url_base}-002
  ${_patch_url_base}-003
  ${_patch_url_base}-004
  ${_patch_url_base}-005
  ${_patch_url_base}-006
  ${_patch_url_base}-007
  ${_patch_url_base}-008
)

 # All official patch file shasums
_patch_shasums=(
  1a79bbb6eaee750e0d6f7f3d059b30a45fc54e8e388a8e05e9c3ae598590146f
  39e304c7a526888f9e112e733848215736fb7b9d540729b9e31f3347b7a1e0a5
  ec41bdd8b00fd884e847708513df41d51b1243cecb680189e31b7173d01ca52f
  4547b906fb2570866c21887807de5dee19838a60a1afb66385b272155e4355cc
  877788f9228d1a9907a4bcfe3d6dd0439c08d728949458b41208d9bf9060274b
  5c237ab3c6c97c23cf52b2a118adc265b7fb411b57c93a5f7c221d50fafbe556
  4d79b5a2adec3c2e8114cbd3d63c1771f7c6cf64035368624903d257014f5bea
  3bc093cf526ceac23eb80256b0ec87fa1735540d659742107b6284d635c43787
)

do_download() {
  do_default_download

  # Download all patch files, providing the corresponding shasums so we can
  # skip re-downloading if already present and verified
  for i in $(seq 0 $((${#_patch_files[@]} - 1))); do
    p="${_patch_files[$i]}"
    download_file $p $(basename $p) ${_patch_shasums[$i]}
  done; unset i p
}

do_verify() {
  do_default_verify

  # Verify all patch files against their shasums
  for i in $(seq 0 $((${#_patch_files[@]} - 1))); do
    verify_file $(basename ${_patch_files[$i]}) ${_patch_shasums[$i]}
  done; unset i
}

As no external behavior changed, all previous Plans will execute as
before, but there are now options for Plan authors to (hopefully)
delete code to reduce duplication.

This change introduces several new public-facing helper functions:

* `download_file()`
* `verify_file()`
* `unpack_file()`

This allows a Plan author to use these functions to download, verify, or
unpack additional archives and artifacts. The default phase behavior use
these new functions under the covers and ensures there is one code path
to perfom the above mentioned tasks.

Additionally a new compositional style is unlocked with the creation of
a "default" implementation for each phase function. The first class
phase functions can then be overridden by Plan authors (as before), but
now they can invoke the original implementation before **adding** more
behavior. The following new public-facing helper functions have been
added:

* `do_default_begin()`
* `do_default_download()`
* `do_default_verify()`
* `do_default_clean()`
* `do_default_unpack()`
* `do_default_prepare()`
* `do_default_build()`
* `do_default_install()`
* `do_default_build_config()`
* `do_default_build_service()`
* `do_default_strip()`
* `do_default_dockerfile_inline()`
* `do_default_docker_image()`
* `do_default_end()`

For an example that ties both of these concepts together, consider a
slightly non-standard Plan that must download multiple patches to be
applied on top of a base release. Readline is such an example. Here is a
young version of part of a Readline Plan which downloads and verifies a
collection of patches in the appropriate phase callback functions. The
default behavior of downloading, verifying, and unpacking the main
source archive is preserved by augmenting the `do_download()` and
`do_verify()` callbacks.

Example:

```
 # The root URL for all official patch files
_patch_url_base=$_url_base/${pkg_name}-${_base_version}-patches/${pkg_name}${_base_version//.}

 # All official patch file URLs
_patch_files=(
  ${_patch_url_base}-001
  ${_patch_url_base}-002
  ${_patch_url_base}-003
  ${_patch_url_base}-004
  ${_patch_url_base}-005
  ${_patch_url_base}-006
  ${_patch_url_base}-007
  ${_patch_url_base}-008
)

 # All official patch file shasums
_patch_shasums=(
  1a79bbb6eaee750e0d6f7f3d059b30a45fc54e8e388a8e05e9c3ae598590146f
  39e304c7a526888f9e112e733848215736fb7b9d540729b9e31f3347b7a1e0a5
  ec41bdd8b00fd884e847708513df41d51b1243cecb680189e31b7173d01ca52f
  4547b906fb2570866c21887807de5dee19838a60a1afb66385b272155e4355cc
  877788f9228d1a9907a4bcfe3d6dd0439c08d728949458b41208d9bf9060274b
  5c237ab3c6c97c23cf52b2a118adc265b7fb411b57c93a5f7c221d50fafbe556
  4d79b5a2adec3c2e8114cbd3d63c1771f7c6cf64035368624903d257014f5bea
  3bc093cf526ceac23eb80256b0ec87fa1735540d659742107b6284d635c43787
)

do_download() {
  do_default_download

  # Download all patch files, providing the corresponding shasums so we can
  # skip re-downloading if already present and verified
  for i in $(seq 0 $((${#_patch_files[@]} - 1))); do
    p="${_patch_files[$i]}"
    download_file $p $(basename $p) ${_patch_shasums[$i]}
  done; unset i p
}

do_verify() {
  do_default_verify

  # Verify all patch files against their shasums
  for i in $(seq 0 $((${#_patch_files[@]} - 1))); do
    verify_file $(basename ${_patch_files[$i]}) ${_patch_shasums[$i]}
  done; unset i
}
```

As no external behavior changed, all previous Plans will execute as
before, but there are now options for Plan authors to (hopefully)
delete code to reduce duplication.
@fnichol
Copy link
Collaborator Author

fnichol commented Jan 11, 2016

This is going to unlock the functions and behavior I need to finish the chef/readline Plan in a sane(ish) manner.

gif-keyboard-12325577618390006996

Ready for review-and-approve when Delivery gives the word.

@jtimberman
Copy link
Contributor

gif-keyboard-13383420149103616651

@chef-delivery
Copy link
Contributor

This PR has passed 'Verify' and is ready for review and approval!
Use: '@delivery approve' when code review is complete.

@adamhjk
Copy link
Contributor

adamhjk commented Jan 11, 2016

@delivery approve

chef-delivery added a commit that referenced this pull request Jan 11, 2016
Merged change 4850cc70-3870-440a-830e-3b2d338fb920

From review branch fnichol/bldr-build-more-helpers into master

Signed-off-by: adam <[email protected]>
@chef-delivery chef-delivery merged commit cee55c6 into master Jan 11, 2016
@chef-delivery chef-delivery deleted the fnichol/bldr-build-more-helpers branch January 11, 2016 23:48
@chef-delivery
Copy link
Contributor

Change: 4850cc70-3870-440a-830e-3b2d338fb920 approved by: @adamhjk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants