Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

support fetching xz tarballs #10

Closed
wants to merge 8 commits into from
Closed

Conversation

DeeDeeG
Copy link
Contributor

@DeeDeeG DeeDeeG commented Sep 21, 2019

Closes #8

This is the xz feature. As I see it...

Technical goals include:

  • Basic ability to download xz tarballs
  • Ability to fall back to gzip if necessary

Preferences already identified:

  • xz should be able to be on by default, without this change causing problems for existing end-users

Nice to have:

  • Reasonable way to configure this by environment variable
  • Reasonable way to configure this by command-line flags

Totally optional:

  • Backward compatibility for environment variable with the prior implementation at tj/n (Feature: xz compression option tj/n#571)
    • This is totally optional, since implementation can be tweaked upon porting to n, or the old n environment variable could be tweaked/deprecated, etc.

I believe this PR as initially posted meets those goals, but could perhaps be refined. (Although I note it is quite possible to bikeshed the minor things, so would prefer to settle on something soonish, rather than extend discussion too indefinitely...)

meta: commits are very spaced out/tiny, to aid in some rebasing and tweaks I have been doing. Can consolidate a bit if/as desired.

Set "NVH_USE_XZ" to "true" to use xz compression.
--use-xz for xz, --no-use-xz for gzip.
Overrides environment variable.
@DeeDeeG DeeDeeG changed the base branch from master to develop September 21, 2019 23:17
Node.js has had xz support on Linux and macOS since 4.0.0

(io.js had xz starting from 1.0+ for Linux, from 2.3.2+ for macOS.

Node.js picks up where io.js left off,
so 4.0+ has xz for both Linux and macOS as well.)

There are some versions of Node.js in the 0.10 and 0.12 series
that also have xz tarballs, but these aren't downloaded often,
and checking just the major version is simpler than checking
major, minor and patch versions.
@shadowspawn
Copy link
Owner

Nice work after all the hard research. I could run with this and make a few changes myself. I'll let you know what I am thinking. Some code comments coming about smaller details.

I don't like the complication of g_xz_force_enabled. I feel this is adding support for a use-case I do not see being likely?

However, I suggest you do not change the code for that because I have some opinions about the normalising and can_use_xz call, and I'll make a branch and try some code to see if my ideas turn into reasonable structure.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 22, 2019

Tiny updates in force push:

  • Re-order a commit for more readable commit history (better grouping)
  • remove &> /dev/null from is_ok.
    • This was from a branch where I had two is_oks, and the first curl 404 not found error message seemed out of place when it showed up every time nvh safely fell back to gzip.
  • Increase minimum node version for xz from 3 to 4, given that io.js is not supported.
  • Reverted incorrect use of double-quotes rather than single-quotes for "$resolved_version" --> '$resolved_version' in the error message for preflight checks.
  • Refactored an if-then for handling "xz forced on" mode (whether to run can_use_xz in install()), for readability, and for consistency with other if-thens to do with "xz forced on" mode.

@shadowspawn
Copy link
Owner

remove &> /dev/null from is_ok

That was something I was going to comment on, already addressed. 👍

bin/nvh Outdated Show resolved Hide resolved
bin/nvh Outdated Show resolved Hide resolved
Determine whether xz can be used, based on platform/system details.
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 22, 2019

Updated can_use_xz to address the two most-recent comments.

DeeDeeG and others added 4 commits September 21, 2019 23:03
If can_use_xz() checks fail, revert to using gzip.
Adapted from this comment:
shadowspawn#8 (comment)

Co-authored-by: John Gee <john@ruru.gen.nz>
Skips node version checks, which would otherwise gate xz usage.

In other words:
Overrides any checks that would normally be run,
so that nvh always attempts to use xz.

---

Also updates "--use-xz" to not set the "xz forced on" state.
(This matches the flag's description in the help messages.)

---

Partly adapted from this comment (with liberties taken on implementation):
shadowspawn#8 (comment)

Co-authored-by: John Gee <john@ruru.gen.nz>
Activates "force use xz" state, which skips xz-related sanity checks.
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 22, 2019

More tiny changes in force-push:

  • Edit the commit titled "Use can_use_xz to gate xz usage"
    • This commit harmlessly passed the node version to can_use_xz, which was unnecessary, because in this PR, can_use_xz() doesn't operate on arguments at all. Just some code cleanup after all the rebasing.
  • Edit the same commit's commit title to have parentheses for "can_use_xz()"

local resolved_major_version
resolved_major_version="$(echo ${resolved_version#v} | cut -d '.' -f '1')"
if [[ "${resolved_major_version}" -lt 4 ]]; then
NVH_USE_XZ="false"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a thought: the Node version check could be moved back into can_use_xz().

Not sure which I prefer, but putting it in can_use_xz() could be a bit more DRY, due to not having to check for NVH_USE_XZ again.

Could gate any of the checks in can_use_xz() (e.g. just the platform checks) with: if [[ "${g_xz_force_enabled}" = "false" ]]; then if need be.

@shadowspawn
Copy link
Owner

Working on code now, almost done...

@shadowspawn
Copy link
Owner

Pushed to a branch on nvh. I'll open a PR back to you!

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 22, 2019

It is getting a bit late in my time zone, but I may have a look before I log off for the evening. Happy to take a look if not this evening then tomorrow.

Edit: I take it this is the branch in question: https://github.com/shadowspawn/nvh/tree/feature/auto-xz Taking a quick look now, but if it is much of a change I probably should wait until tomorrow to really give it a proper look.

Edit 2: Looks more in line with the coding style of the rest of nvh. 👍 (I couldn't tell if the branch changes scenarios where xz will be used. on my TODO for tomorrow would be to take a closer look at that, etc.) Logging off for the night. Thanks for the back and forth!

@shadowspawn
Copy link
Owner

No worries, no hurry. Thanks.

Copy link
Owner

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

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

Planning some refactoring as per changes on feature/auto-xz, but happy with PR as stands.

Thanks for the deep investigations!

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 22, 2019

Thanks for the review!

Miscellaneous comments regarding the branch at feature/auto-xz (as of commit dbb996b):

  • I could drop the last two commits from this PR for a neater commit history. Those are the commits that added the xz "force enabled" mode.
  • Comment in setup still references xz force-enabled mode: "set to anything else to force-enable"
  • Looking at the comments for can_use_xz(), "Unfortunately we can't query tar itself." We sort of can, just that we would need to check all of:
    • the version number of tar
    • whether tar is GNU tar or (bsd)tar from libarchive
    • still have to check for xz on PATH on Linux
    • Now need to additionally check for /usr/lib/liblzma.dylib on macOS
      So it's more testing logic, for what amounts to checks that more than likely only work on Linux or macOS anyway. (So I guess "we can't [just] query tar itself." is, by and large, accurate without being long-winded.)
    • Normalizing NVH_USE_XZ in main() looks practical, as it can call can_use_xz().
      • Probably makes the normalization in the setup phase redundant, or vice-versa.
        • okay, I see this just sets NVH_USE_XZ to "true" if unset, so it's not redundant.
        • could potentially refactor the normalization/on-by-default logic into a single if-elif-else in main() if desired.
      • Noticed the comment in main() reads: "# Default to using nvh" which probably should be "# Default to using xz"
        • I've also done this a few times. 😄

In any case I am happy to ship this feature off to wider, bluer waters (upstream). Thanks for the rounds of feedback and review.

@shadowspawn
Copy link
Owner

Good tip about dropping the two commits, I can do that. And I'll update the errata in the comments, thanks.

@shadowspawn
Copy link
Owner

Merged and tweaked on develop. Preparing for release.

Thank you for your contributions.

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

Successfully merging this pull request may close these issues.

2 participants