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

backend: fix inconsistencies in --genScript:on mode #802

Merged
merged 2 commits into from
Jul 18, 2023

Conversation

CyberTailor
Copy link
Contributor

@CyberTailor CyberTailor commented Jul 17, 2023

Summary

  • Bugfix: Make compiler executable configurable in --genScript:on
    mode.

    That means you can now use command-line options like --gcc.exe or
    nim.cfg options like clang.exe with --genScript:on flag, and they
    will be respected.

    This is needed if compiler on the target machine (when
    cross-compiling) is named differently than the default.

  • Change: Use --cincludes option in --genScript:on mode.

    Since cIncludes paths can be specified only via cli, there should be
    no unintended side effects. This change is made for consistency.

Details

This PR changes behavior of the getCompileCFileCmd function in the
extccomp module, in particular:

  • Make sure getConfigVar(conf, c, ".exe") always takes precedence over
    getCompilerExe, even when relative paths are requested.
  • Remove outdated code related to compiler executable formatting. None of
    defined compilers used format strings in the executable.

@saem
Copy link
Collaborator

saem commented Jul 17, 2023

Thanks for the PR.

Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

Please update the PR message, it's used as the final commit message the pre-existing PR template walks you through it.

I took a quick look at the code and it seems it compilePattern, and possibly includeCmd, could be made let. The mutable variable and awkward/error prone logic is facilitated by the mutable variable.

@CyberTailor
Copy link
Contributor Author

Please update the PR message

Done, although the description is kinda short.

it seems it compilePattern, and possibly includeCmd, could be made let

I don't see how

@zerbina
Copy link
Collaborator

zerbina commented Jul 17, 2023

Done, although the description is kinda short.

A small request regarding the summary: could you reword it so that it reflects the bugfix nature of the PR? The current wording makes it sound more like a feature addition.

It's not directly mentioned in the template, but since the PR message is used as the final commit message, please also make sure that the lines have a maximum length of 72 characters.

I don't see how

At least for compilePattern, the following would work:

let compilePattern =
  if noAbsolutePaths(conf): joinPath(conf.cCompilerPath, exe)
  else:                     exe

@@ -580,17 +580,16 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
options.add ' '
options.add cfile.customArgs

var compilePattern: string
let compilePattern =
if noAbsolutePaths(conf): exe
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just confirming my understand: this is in fact the crux of the change because regardless of flags the pattern is configured in the same fashion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getCompilerExe(conf, c, cfile.cname) is a fallback, but it's currently forced in --genScript:on mode

@CyberTailor CyberTailor changed the title backend: respect '--gcc.exe' with '--genScript:on' backend: refactor getCompileCFileCmd Jul 17, 2023
@haxscramper haxscramper added this to the C backend refactoring milestone Jul 17, 2023
@haxscramper haxscramper added refactor Implementation refactor compiler General compiler tag compiler/backend Related to backend system of the compiler labels Jul 17, 2023
@zerbina zerbina added the bug Something isn't working label Jul 17, 2023
@saem
Copy link
Collaborator

saem commented Jul 18, 2023

thanks again for the PR, @CyberTailor.

The PR is used as a fairly detailed change log in order to:

  • derive a change log
  • help debug via git bisect
  • learning the code base/code archeology

All of these require clear PR messages that describe:

  • the behavioural change (before and after)
  • implementation changes
  • reasons for change
  • any additional context/tidbits

I've pulled together a todo for things I've noticed:

  • the PR title ("refactor") doesn't reflect this is a bug fix; your first line in the summary is closer to summarizing the effect of the PR
  • update the summary:
    • describe the new behaviour, what can people expect
    • add in a reason for the change (perhaps something like: it's inconsistent between modes for no good reason/without cause)
  • update the details:
    • with the title update, please ensure that the module extccomp and changed routine getCompileCFileCmd are mentioned
    • even though they're details, they're a summary relative to the code, most people won't know local variables, so instead of exe and compilerPattern, instead take the perspective of behaviour of the compiler before vs after and the changes required to make that happen outward behaviour was before (the executable wasn't configurable) and

N.B. refactor means changing code without changing behaviour

Just in case it helps: my approach to writing PR message is I brain dump everything under details first, clean it up, then extract the summary from it, and a title from the summary. If you're stuck collect the bullet points and I can help. Finally, recent commits are PR summaries and you can use those as examples. Zerbina's are especially good.

@CyberTailor CyberTailor changed the title backend: refactor getCompileCFileCmd backend: fix inconsistencies in --genScript:on mode Jul 18, 2023
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

That's a much improved description, thanks

@saem
Copy link
Collaborator

saem commented Jul 18, 2023

/merge

@github-actions
Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


@chore-runner chore-runner bot added this pull request to the merge queue Jul 18, 2023
Merged via the queue into nim-works:devel with commit c824ed1 Jul 18, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler compiler General compiler tag refactor Implementation refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants