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

Fix plan build regression in 0.76.0 release #6257

Merged
merged 5 commits into from Mar 4, 2019

Conversation

baumanj
Copy link
Contributor

@baumanj baumanj commented Mar 4, 2019

tl;dr see the fix in 05d3623

Full Details

Reverts #6248
Resolves #6250

Now that we understand the nature of this error, we can re-implement that shellcheck fixes that we previously reverted and add the necessary fix to the problem they uncovered.

The Bugs

  1. In _resolve_scaffolding_dependencies (and other similar usages), changing the code that collects the transitive dependencies from

    sdeps=($(_get_deps_for "$resolved"))

    to

    read -r -a sdeps <<< "$(_get_deps_for "$resolved")"

    as part of Enable clippy and shellcheck linting  #6160 to address shellcheck lint SC2207. This resulted in a defect where because only the first dependency from _get_deps_for was added to sdeps, scaffolding-based builds failed. [plan-build] Avoid reading a newline delimited value to array #6240 was submitted to fix the issue.

  2. The fix in [plan-build] Avoid reading a newline delimited value to array #6240 was correct. It changed

    read -r -a sdeps <<< "$(_get_deps_for "$resolved")"

    to

    mapfile -t sdeps < <(_get_deps_for "$resolved")

    The first command is for populating an array from a single line of input, with entries separated by whitespace. The second command is for populating an array from multiple lines of input, with entries separate by newlines (which is what _get_deps_for does).

    However, a different bug was discovered: unexpected newlines were appearing at the beginning of the TDEPS files for some packages, causing breakages. Eventually, the difference in behavior between

    sdeps=($(_get_deps_for "$resolved"))

    and

    mapfile -t sdeps < <(_get_deps_for "$resolved")

    was traced back to _get_deps_for:

    # **Internal** Returns (on stdout) the `TDEPS` file contents of another locally
    # installed package which contain the set of all direct and transitive run
    # dependencies. An empty set could be returned as whitespace and/or newlines.
    # The lack of a `TDEPS` file in the desired package will be considered an
    # unset, or empty set.
    #
    # ```
    # _get_tdeps_for /hab/pkgs/acme/a/4.2.2/20160113044458
    # # /hab/pkgs/acme/dep-b/1.2.3/20160113033619
    # # /hab/pkgs/acme/dep-c/5.0.1/20160113033507
    # # /hab/pkgs/acme/dep-d/2.0.0/20160113033539
    # # /hab/pkgs/acme/dep-e/10.0.1/20160113033453
    # # /hab/pkgs/acme/dep-f/4.2.2/20160113033338
    # # /hab/pkgs/acme/dep-g/4.2.2/20160113033319
    # ```
    #
    # Will return 0 in any case and the contents of `TDEPS` if the file exists.
    _get_tdeps_for() {
      local pkg_path="$1"
      if [[ -f "$pkg_path/TDEPS" ]]; then
        cat "$pkg_path"/TDEPS
      else
        # No file, meaning an empty set
        echo
      fi
      return 0
    }

    Because _get_tdeps_for returned a newline (rather than nothing) in the case of an absent TDEPS file (which is normal, some packages have no transitive dependencies), the mapfile version of the code interpreted this as a single element array, containing an empty string. This was eventually rendered into the subsequent TDEPS file as an empty line.

    Essentially, the previous code depended upon "the shell's sloppy word splitting and glob expansion" that shellcheck warns against. Updating _get_tdeps_for (and similarly _get_deps_for) to output nothing in the case of an empty set (and omitting the superfluous return):

    _get_tdeps_for() {
      local pkg_path="$1"
      if [[ -f "$pkg_path/TDEPS" ]]; then
        cat "$pkg_path"/TDEPS
      fi
    }

    fixes the issue.

This PR makes some additional improvements to _get_[t]deps_for; see 05d3623.

@thesentinels
Copy link
Contributor

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

…limited

This change was originally from #6240

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
- Don't output anything in the case of an empty or missing [T]DEPS file,
  since mapfile interprets a single newline as a 1-element array: ("")
- Only cat [T]DEPS if it has nonzero size
- Abort if pkg_path argument is missing
- Remove superfluous, unconditional return

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
@baumanj baumanj changed the title Revert "Reverts 65a1f9 and a03510 for hab-plan-build.sh" Fix plan build regression in 0.76.0 release Mar 4, 2019
Copy link
Contributor

@christophermaier christophermaier left a comment

Choose a reason for hiding this comment

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

Looks good to me, though I'll defer ultimately to @smacfarlane @eeyun and @fnichol for their validation.

Nice work @baumanj

Copy link
Contributor

@raskchanky raskchanky left a comment

Choose a reason for hiding this comment

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

Nice work

@raskchanky
Copy link
Contributor

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
@baumanj baumanj requested a review from chefsalim as a code owner March 4, 2019 20:13
@eeyun
Copy link
Contributor

eeyun commented Mar 4, 2019

Discussion on whether to merge this now or wait until we have some scripted tests is taking place in slack. As a note on the issue, the cases we were testing on Friday that were failing appear to be fine in this PR branch but as @smacfarlane pointed out there's still some concern around moving forward with reverting the reversion without some tests that can tell us that there aren't any other unforseen ripples from the change.

@eeyun
Copy link
Contributor

eeyun commented Mar 4, 2019

The decision here is to merge this, thaw the merge-freeze and backfill tests while this is in acceptance before the next release! Great work on these fixes @baumanj.

Copy link
Contributor

@smacfarlane smacfarlane left a comment

Choose a reason for hiding this comment

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

I've validated this change fixes the issues we ran into last week, and the BUILD_TDEPS and TDEPS files contain the correct entries without newlines.

I have one question around syntax which I've left inline, but that's not a blocker to merging.

tenor-36257275

scaff_build_deps_resolved+=("$resolved")
# Add each (fully qualified) direct run dependency of the scaffolding
# package.
mapfile -t sdeps < <(_get_deps_for "$resolved")
Copy link
Contributor

Choose a reason for hiding this comment

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

@baumanj Could you provide a brief comment inline describing what the < <() syntax means? I'm having a little trouble understanding it. I see in your pr you link to the shellcheck page that describes that this is the preferred style, but didn't see an explanation of the syntax. Is it a particular bash idiom we could link to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added d60e521

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
@baumanj baumanj merged commit 166a388 into master Mar 4, 2019
@baumanj baumanj deleted the revert-6248-eeyun/revert_shellcheck branch March 4, 2019 23:10
chef-ci added a commit that referenced this pull request Mar 4, 2019
Obvious fix; these changes are the result of automation not creative thinking.
@christophermaier christophermaier added Type:BugFixes PRs that fix an existing bug and removed X-fix labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type:BugFixes PRs that fix an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve the illusive bug in hab-plan-build.sh
6 participants