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

patchShebangs: preserve times, resolves #33084 #33281

Closed
wants to merge 1 commit into from

Conversation

lukateras
Copy link
Member

Motivation for this change

See #33084 (comment). Please test: I haven't.

/cc @johbo

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@@ -54,7 +54,11 @@ patchShebangs() {
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
# Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33084
Copy link
Contributor

Choose a reason for hiding this comment

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

Golfing: mtime=$(stat -c '%Y' "$f"); whatever; touch -d @$mtime "$f" (I think that does the same thing, works with GNU, at least ...)

Copy link
Member Author

Choose a reason for hiding this comment

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

It won't, it doesn't preserve nanoseconds.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good idea Just to local mtime=... so that it doesn't pollute the global scope.

edit oh wrote that before the nanoseconds. Bummer.

Copy link
Contributor

Choose a reason for hiding this comment

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

stat -c '%y' then?

Copy link
Member Author

@lukateras lukateras Jan 1, 2018

Choose a reason for hiding this comment

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

It seems error-prone to convert %y format into format accepted by touch. If local suffix is problematic, mktemp could be used in beginning of patchShebangs to reserve a unique file name in /tmp and then that one file can be used as a buffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

On my end, touch -d "$(stat -c '%y' ...)" ... works as I expect, in that the mtimes are identical, to the nanosecond, without the need for conversion. Same for touch -d @$(stat -c '%.Y'). Perhaps these are GNU-isms, not to be relied on?

Copy link
Member

Choose a reason for hiding this comment

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

Do we have these options in the bootstrapping phase (in case this setup-hook is used there)?

Copy link
Member

Choose a reason for hiding this comment

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

touch -d @$(stat -c '%Y' README.md)  default.nix

in the nixpkgs repo also works with busybox. There is no posix version of the stat command so there is no standard set of flags we would have to rely on.

Copy link
Member

Choose a reason for hiding this comment

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

We're not restricted to POSIX, since stdenv supplies coreutils.

@Mic92
Copy link
Member

Mic92 commented Jan 2, 2018

I found patchShebangs to introduce a certain overhead, when scanning through big packages.
How does this change affect build time?

@@ -54,7 +54,11 @@ patchShebangs() {
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
# Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33084
cp -p "$f" "$f.tmp"
Copy link
Member

Choose a reason for hiding this comment

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

Making a full copy of the file, just to store its mtime, seems very inefficient to me.

Can't you do touch -r "$f" "$f.tmp"?

Copy link
Member

@Mic92 Mic92 Jan 5, 2018

Choose a reason for hiding this comment

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

That file does not exists before cp -> sed edit $f inplace.

Copy link
Contributor

Choose a reason for hiding this comment

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

touch will create it.

Copy link
Member

Choose a reason for hiding this comment

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

right.

@vcunat vcunat self-assigned this Jan 21, 2018
vcunat pushed a commit to vcunat/nixpkgs that referenced this pull request Jan 21, 2018
Close NixOS#33281.  Edits by vcunat:
 - use Eelco's idea: empty file instead of full copy
 - use longer name suffix to decrease the likelihood of collision
@vcunat
Copy link
Member

vcunat commented Jan 22, 2018

Staged 4b1b6ee .

@vcunat vcunat closed this Jan 22, 2018
@vcunat vcunat deleted the yegortimoshenko-patch-1 branch January 22, 2018 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants