Skip to content

We need to better structure our bash support code #5844

Closed

Description

@stevekuznetsov

Currently we store most of our support functions for bash in hack/util.sh (800+lines) and hack/common.sh (600+ lines). I think the approach upstream has merit, so I think we should

  1. divide our utility functions into functional files (think build.sh, util.sh, etc)
  2. ensure that our functions are all correctly namespaced as a result, and
  3. move them into a new directory structure like the following.

Tests for the functions can live in a parallel structure.

hack
├── bin
│   ├── build.sh
│   ├── junit.sh
│   ├── testwrappers.sh
│   └── util.sh
└── test
    └── testwrappers_test.sh

/cc @smarterclayton @dmcpherson

Activity

  1. deads2k commented on Nov 11, 2015

    @deads2k
    Contributor

    I don't think that I'd want to follow upstream off the bash cliff unless we have to.

  2. stevekuznetsov commented on Nov 11, 2015

    @stevekuznetsov
    ContributorAuthor

    I hardly think that these changes would vault us off that cliff.

  3. smarterclayton commented on Nov 11, 2015

    @smarterclayton
    Contributor

    It does involve touching every other bash script - in the long term, are
    there other cleanups in bash that reduce the need for bash more? Reduce
    our dependence on certain things in util? I'm always a fan of cleanliness,
    but it's good to do it while also reducing the cost of long term
    maintenance. Bash has some level of unintended consequences when you
    refactor it (because it is not as free of side effects as it should be).
    It helps to frame these refactors in terms of "if I change this, this
    becomes much easier".

    On Nov 11, 2015, at 5:26 AM, Steve Kuznetsov [email protected]
    wrote:

    Currently we store most of our support functions for bash in hack/util.sh
    (800+lines) and 'hack/common.sh(600+ lines). I think the approach upstream
    has merit, so I think we should 1) divide our utility functions into
    functional files (thinkbuild.sh,util.sh`, etc) 2) ensure that they all
    are correctly namespaced as a result, and 3) move them into a new
    directory structure like the following. Tests for the functions can live in
    a parallel structure.

    hack
    ├── bin
    │ ├── build.sh
    │ ├── junit.sh
    │ ├── testwrappers.sh
    │ └── util.sh
    └── test
    └── testwrappers_test.sh

    /cc @smarterclayton https://github.com/smarterclayton @dmcpherson
    https://github.com/dmcpherson

    —
    Reply to this email directly or view it on GitHub
    #5844.

  4. stevekuznetsov commented on Nov 11, 2015

    @stevekuznetsov
    ContributorAuthor

    The value-adds that I see from a restructure/cleanup are:

    1. it's easy to read the helper function libraries
    2. we can import with more specificity
    3. we can easily see which functions do and do not have tests
    4. it becomes easier to create a new utility script and stick reusable code there

    I know with one or two monolithic utility functions I have hesitated to add code to them, knowing that 99% of scripts sourceing them won't need whatever utility function I am adding, even though there may be 10 that do.

    The effort to do this is fairly minimal so I think it should be a straightforward task with some concrete wins for little work. As you say this does entrench us further into using bash, but I'm not entirely sure what our alternative is - writing tiny golang executibles?

  5. stevekuznetsov commented on Nov 12, 2015

    @stevekuznetsov
    ContributorAuthor

    Another value add can come from updating our current bash to reflect best practices as reported by tools like ShellCheck. A cursory run of this over some of our scripts reveals quite a large amount of potential errors. I'm not sure we need to include it as a vetter in our CI for bash PRs but it's definitely got a lot of good checks.

  6. smarterclayton commented on Nov 12, 2015

    @smarterclayton
    Contributor

    It would be good to at least make it easy to run.

    On Nov 12, 2015, at 4:39 PM, Steve Kuznetsov [email protected]
    wrote:

    Another value add can come from updating our current bash to reflect best
    practices as reported by tools like ShellCheck http://www.shellcheck.net/.
    A cursory run of this over some of our scripts reveals quite a large amount
    of potential errors. I'm not sure we need to include it as a vetter in our
    CI for bash PRs but it's definitely got a lot of good checks.

    —
    Reply to this email directly or view it on GitHub
    #5844 (comment).

  7. stevekuznetsov commented on Apr 8, 2017

    @stevekuznetsov
    ContributorAuthor

    We're mostly there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions