Skip to content

cc-wrapper: Pass shellcheck and other cleanups#27879

Merged
Ericson2314 merged 1 commit intoNixOS:stagingfrom
obsidiansystems:cc-wrapper-shellcheck
Aug 4, 2017
Merged

cc-wrapper: Pass shellcheck and other cleanups#27879
Ericson2314 merged 1 commit intoNixOS:stagingfrom
obsidiansystems:cc-wrapper-shellcheck

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Aug 2, 2017

Motivation for this change

In many cases, this involved taking @orivej's and @edolstra's recent ld-wrapper improvements, and applying then elsewhere.

The only semantics changes I know of are

  • Fix bad word-splitting---already done with ld-wrapper with no issues

  • Remove unused and probably wrong LD=---didn't take into account cross and in cc-wrapper pointed to unwrapped ld while in ld-wrapper pointed to wrapped ld.

Things done

Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.

  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built stdenv on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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.

CC @orivej

@Ericson2314 Ericson2314 requested review from edolstra and grahamc August 2, 2017 18:41
@mention-bot
Copy link

@Ericson2314, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @vcunat and @abbradar to be potential reviewers.

Copy link
Member Author

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Here's some things I'd like feedback on (along with me discovering my own mistake :)).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think not including extraBefore here was an oversight of whoever added it originally. Note that the debugging code below originally also skipped it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was the same one as above---eager copy paste---and unneeded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Somebody should weigh in on this.

Copy link
Member

Choose a reason for hiding this comment

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

thsi is probably not intentional

Copy link
Member

Choose a reason for hiding this comment

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

I weigh in on "thsi" most likely being a typo. Does that count?

Copy link
Member Author

@Ericson2314 Ericson2314 Aug 2, 2017

Choose a reason for hiding this comment

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

Wait, we already check for file existence, so this is definitely isn't needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Semantics change, but all the flags are sans-whitespace so it seems fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is clearer than the regex stuff that was there before---and shellcheck said the regex stuff was done wrong anyways such that only string literals would match.

Copy link
Member Author

Choose a reason for hiding this comment

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

N.B. bugs like this weren't being caught because extra word splitting on arrays.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

Semantics change, but the old version was a mistake. I fixed a hardening flag bug uncovered by this; hope there aren't others.

@orivej did something the same fix for ld-wrapper, and I guess it was fine there?

Copy link
Member Author

Choose a reason for hiding this comment

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

So the "skip" thing does say "bad path", but not knowing what flag it came from is strictly less useful. I'm conflicted.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a dead variable, but used in commented code, so I guess I'll leave it for now.

@Ericson2314 Ericson2314 force-pushed the cc-wrapper-shellcheck branch 4 times, most recently from 7f7ed3c to de957cc Compare August 3, 2017 20:06
@Ericson2314
Copy link
Member Author

In #27672 I made cc-wrapper robust with undefined variables with set -u. That makes me extra confident in this commit, as it is included in that.

@Ericson2314 Ericson2314 mentioned this pull request Aug 4, 2017
9 tasks
Copy link
Member

@grahamc grahamc left a comment

Choose a reason for hiding this comment

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

I'm worried about the n+=1:

[grahamc@Morbo:~]$ declare -i n=0

[grahamc@Morbo:~]$ i+=1

[grahamc@Morbo:~]$ echo $i
1

[grahamc@Morbo:~]$ i+=1

[grahamc@Morbo:~]$ echo $i
11

otherwise this looks great

Copy link
Member

Choose a reason for hiding this comment

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

thsi is probably not intentional

In many cases, this involved taking @orivej's and @edolstra's recent
ld-wrapper improvements, and applying then elsewhere.
@Ericson2314 Ericson2314 force-pushed the cc-wrapper-shellcheck branch from de957cc to 6463fd3 Compare August 4, 2017 16:47
@Ericson2314
Copy link
Member Author

OK I think I dealt with all comments.

NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK"
fi

LD=@ldPath@/ld
Copy link
Member Author

Choose a reason for hiding this comment

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

This would be the unwrapped ld, which seems wrong.

params=("${rest[@]}")
fi

LD=@prog@
Copy link
Member Author

Choose a reason for hiding this comment

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

This however would be the wrapped ld. Since cc will fork ld-wrapper, the old LD=..., assuming LD was already an export so it affected forked processes' environments (!), would be clobbered anyways.

export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"

# Export and assign separately in order that a failing $(..) will fail
# the script.
Copy link
Member Author

Choose a reason for hiding this comment

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

Added back better comment without typo.

@Ericson2314 Ericson2314 merged commit fdd07f6 into NixOS:staging Aug 4, 2017
@Ericson2314 Ericson2314 deleted the cc-wrapper-shellcheck branch August 4, 2017 18:19
@FRidh FRidh mentioned this pull request Aug 7, 2017
8 tasks
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.

6 participants