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] Prefix public callback functions with do_. #120

Merged
merged 5 commits into from
Dec 19, 2015

Conversation

fnichol
Copy link
Collaborator

@fnichol fnichol commented Dec 18, 2015

Ths addresses an issue where the author of a Plan wants to call the
install(1) command to copy files, create directories, etc. Here's a
short example that happens in an install() callback:

install() {
  make install
  install -D -m644 LICENSE ${pkg_path}/share/LICENSE
}

The call to install on line 3 won't execute the install(1) command,
but will instead recursively call the defined install() shell
function, which recurses into foreverland.

Additionally, now all user-facing callbacks that are designed to be
overwritten are of the naming form do_*(). The following functions are
now part of the public API for Plan files:

  • do_begin() (formerly bldr_begin())
  • do_download() (formerly download())
  • do_verify() (formerly verify())
  • do_clean() (formerly clean_cache())
  • do_unpack() (formerly unpack())
  • do_prepare_wrapper() (formerly prepare_wrapper())
  • do_prepare() (formerly prepare())
  • do_build_wrapper() (formerly build_wrapper())
  • do_build() (formerly build())
  • do_install_wrapper() (formerly install_wrapper())
  • do_install() (formerly install())
  • do_build_config() (formerly config())
  • do_service() (formerly service())
  • do_strip() (formerly strip_binaries())
  • do_docker_image_wrapper() (formerly dockerfile_wrapper())
  • do_dockerfile_inline() (formerly docker_inline())
  • do_docker_image() (formerly dockerfile())
  • do_end() (formerly bldr_end())

@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.

@fnichol
Copy link
Collaborator Author

fnichol commented Dec 18, 2015

gif-keyboard-1738221126833418917

done
$(MAKE) $(addprefix publish-,$(PKGS))

$(PKGS):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know you could do this, that's awesome

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm re-remembering a lot of Makefile-isms after reading them to build our softwares 😄

@reset
Copy link
Collaborator

reset commented Dec 18, 2015

@fnichol works for me. Do you think we perhaps should prefix all of our callbacks with bldr_ to avoid collisions like this? So install() would become bldr_install()?

@fnichol
Copy link
Collaborator Author

fnichol commented Dec 18, 2015

@reset It's something I was wondering about, but I'd rather change them all like that to the following:

  • bldr_begin() -> bldr_begin() (no change)
  • download() -> bldr_download()
  • verify() -> bldr_verify()
  • clean_cache() -> bldr_clean_cache() or bldr_clean()
  • unpack() -> bldr_unpackl()
  • prepare() -> bldr_prepare()
  • build() -> bldr_build()
  • install;() -> bldr_install()
  • config() -> bldr_config()
  • service() -> bldr_service()
  • strip_binaries() -> bldr_strip_binaries() or bldr_strip()
  • dockerfile() -> bldr_dockerfile()
  • bldr_end() -> bldr_end() (no change)

There are few of functions that happen in the build flow (i.e. resolve_deps(), build_environment(), link_libraries(), manifest(), and package) that feel more internal to how bldr-build works that maybe shouldn't be advertised as "public" callback overrides.

Thoughts?

@reset
Copy link
Collaborator

reset commented Dec 18, 2015

@fnichol yeah I'm thinking that we should prefix all of our callbacks/public functions with bldr_ and then I would prefix anything that is private with an underscore or two. _link_libraries(), etc.

@fnichol
Copy link
Collaborator Author

fnichol commented Dec 18, 2015

@reset I wanted to table that idea earlier this week then forgot. You can see that I've started to hint at functions that you probably shouldn't call as a Plan author, but I'd love to make this even more explicit. Otherwise it limits our ability to refactor and extend into the future.

Ths addresses an issue where the author of a Plan wants to call the
`install(1)` command to copy files, create directories, etc. Here's a
short example that happens in an `install()` callback:

```sh
install() {
  make install
  install -D -m644 LICENSE ${pkg_path}/share/LICENSE
}
```

The call to `install` on line 3 won't execute the `install(1)` command,
but will instead recursively call the defined `install()` shell
function, which recurses into foreverland.

Additionally, now all user-facing callbacks that are designed to be
overwritten are of the naming form `do_*()`. The following functions are
now part of the public API for Plan files:

* `do_begin()` (formerly `bldr_begin()`)
* `do_download()` (formerly `download()`)
* `do_verify()` (formerly `verify()`)
* `do_clean()` (formerly `clean_cache()`)
* `do_unpack()` (formerly `unpack()`)
* `do_prepare_wrapper()` (formerly `prepare_wrapper()`)
* `do_prepare()` (formerly `prepare()`)
* `do_build_wrapper()` (formerly `build_wrapper()`)
* `do_build()` (formerly `build()`)
* `do_install_wrapper()` (formerly `install_wrapper()`)
* `do_install()` (formerly `install()`)
* `do_build_config()` (formerly `config()`)
* `do_service()` (formerly `service()`)
* `do_strip()` (formerly `strip_binaries()`)
* `do_docker_image_wrapper()` (formerly `dockerfile_wrapper()`)
* `do_dockerfile_inline()` (formerly `docker_inline()`)
* `do_docker_image()` (formerly `dockerfile()`)
* `do_end()` (formerly `bldr_end()`)
This change changes the names of some internally-facing functions in
order to signal that external users (i.e. Plan authors) should not call
these functions or rely on their current behavior over the long term. A
function which is prefix with a single underscore (`_`) is API/private
visibility.
The `resolve_dep()` function was using `exit_with()`, but since it was
being called from a subshell and the return code was not being checked,
the program would continue after a bad depdency solve.
It turns out that using a shell-style for loop in a Makefile does not
give you the same guarentees as running that same for loop in a shell
script with `set -e` set. The for loop is considered a single line
statement to `make(1)` so any failures inside the loop will not trigger
an abort. This change uses Makefile targets to accomplish the same end
goal.
@fnichol fnichol force-pushed the rename-install-callback branch from 31570c5 to b5a4978 Compare December 19, 2015 00:59
@fnichol
Copy link
Collaborator Author

fnichol commented Dec 19, 2015

Based on feedback from @reset and @adamhjk, I went with a do_*() format for public, user-facing callbacks.

@fnichol fnichol changed the title [bldr-build] Rename install() callback to install_files(). [bldr-build] Prefix public callback functions with do_. Dec 19, 2015
@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.

@fnichol
Copy link
Collaborator Author

fnichol commented Dec 19, 2015

Updated the PR body as well with some context and ready for a review!

gif-keyboard-4826370035262076045

@adamhjk
Copy link
Contributor

adamhjk commented Dec 19, 2015

gif-keyboard-5957172344705402842

@adamhjk
Copy link
Contributor

adamhjk commented Dec 19, 2015

@delivery approve

chef-delivery added a commit that referenced this pull request Dec 19, 2015
Merged change 19030a67-f5c3-4371-806a-c301b1b4765b

From review branch rename-install-callback into master

Signed-off-by: adam <[email protected]>
@chef-delivery chef-delivery merged commit f96a713 into master Dec 19, 2015
@chef-delivery
Copy link
Contributor

Change: 19030a67-f5c3-4371-806a-c301b1b4765b approved by: @adamhjk

@chef-delivery chef-delivery deleted the rename-install-callback branch December 19, 2015 01:04
@reset
Copy link
Collaborator

reset commented Dec 19, 2015

@fnichol @adamhjk perfect!

fnichol added a commit that referenced this pull request Dec 21, 2015
This was a missed oversight with changes made in #120.
fnichol added a commit that referenced this pull request Dec 21, 2015
This was missed when updating variables in #120.
raskchanky pushed a commit that referenced this pull request Apr 16, 2019
[AtomicWriter] fsync() parent directory after rename
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.

4 participants