Skip to content

Conversation

genotrance
Copy link
Collaborator

@timotheecour
Copy link
Contributor

see also #65 (as mentioned by @genotrance)

@dom96 dom96 mentioned this pull request Sep 1, 2018
@Araq
Copy link

Araq commented Oct 9, 2018

Ping @dom96

@dom96
Copy link
Owner

dom96 commented Oct 13, 2018

I'm going to remove your comments because they are incredibly distracting to me as I'm reviewing this, sorry. (I backed them up in this screenshot)

Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
Repository owner deleted a comment from genotrance Oct 13, 2018
@genotrance
Copy link
Collaborator Author

No worries.


downloadFile(url, result, params)

proc downloadCheckRenamed(params: CliParams, url, filename: string): string =
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this code should be in a procedure. Also the downloadCheck proc above should be renamed to something else or restructured. Even something long like downloadIfNecessary would be better, the current name is too vague.

Copy link
Owner

Choose a reason for hiding this comment

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

or maybe hashedDownload?

except HttpRequestError:
# Fallback to downloading from Github
# Rename to nim-VERSION.tar.gz to disambiguate
result = downloadCheckRenamed(params, githubUrl % ("v" & $version),
Copy link
Owner

Choose a reason for hiding this comment

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

Why would GitHub have it, but not nim-lang.org? This seems redundant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea was to fallback to github.com if nim-lang.org was down. It should fall back to tar.gz + csources on Linux as well since github.com won't have an xz file with built-in csources.

Copy link
Owner

Choose a reason for hiding this comment

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

nim-lang.org has so far a better uptime than github.com. It's a nice thought but I doubt this complexity is worth it.

result = getDownloadDir(params) / filename
if not fileExists(result):
let origfile = downloadCheck(params, url)
moveFile(origfile, result)
Copy link
Owner

Choose a reason for hiding this comment

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

After looking at this in more detail this seems unnecessary. The downloadFile proc takes an outputPath, also the params.getDownloadPath used in needsDownload should already use the right path. You shouldn't need to move the file for cases where you're downloading "nim-0.19.0.tar.gz", from what I can tell your code just moves it to the same place...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll look into cleaning up the proc names and avoid renaming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually now that I looked at this further, the reason its this way is because needsDownload() sets the outputPath, you cannot pass a value down if you want a rename, it will get overwritten.

There are two reasons to rename:

  • Line 269 - downloading Nim sources from github - you get a master.tgz, no version in name
  • Line 285 - downloading csources from github - you again get a master.tgz, no version in name

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, what I would do is overload needsDownload:

proc needsDownload(params: CliParams, downloadUrl: string, outputPath: string): bool =

Also I would get rid of these procs, putting two lines into a proc isn't worth it.

return outputPath
try:
# Download csources tagged version from Github
# Rename to csources-VERSION.tar.gz to disambiguate
Copy link
Owner

Choose a reason for hiding this comment

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

See my remark above, renaming shouldn't be necessary.

"csources-$1.tar.gz" % $version)
except HttpRequestError:
result = downloadCheck(params, csourcesUrl % "master")
display("Warning:", "Building from latest C sources. They may not be " &
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick:

*Downloading the latest C sources

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you want to change the message? Csources are already downloaded by now though.

Copy link
Owner

Choose a reason for hiding this comment

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

In that case "Downloaded", the point is that this procedure isn't building the C sources. You don't know what context it might be called from, it's better to make the messages reflect what the procedure is doing.

if not needsDownload(params, mingwUrl, outputPath):
return outputPath

display("Downloading", "C compiler (Mingw32)", priority = HighPriority)
Copy link
Owner

Choose a reason for hiding this comment

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

This will be misleading since it will be shown even if the download doesn't happen.

display("Downloading", "DLLs (openssl, pcre, ...)", priority = HighPriority)
downloadFile(dllsUrl, outputPath, params)
return outputPath
result = downloadCheck(params, dllsUrl)
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above.

proc extractZip(path: string, extractDir: string) =
var cmd = "unzip -o $1 -d $2"
if defined(windows):
cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('$1', '$2'); }\""
Copy link
Owner

Choose a reason for hiding this comment

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

It's awesome that powershell supports this.

Sadly it will fail on older Windows versions. I test choosenim on Win XP, any chance we could get a good fallback for those?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No good answer for this. Options are to use nimarchive or some other capable extraction lib that supports gz and xz as well. Alternative is to disallow binary install if powershell isn't available.

Copy link
Owner

Choose a reason for hiding this comment

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

Alternative is to disallow binary install if powershell isn't available.

I would like this, but I'm not going to block you for it.

# Fix win binary folder to avoid /nim-0.xx.0/nim-0.xx.0
let winFolder = extractDir/"nim-$1" % $version
if dirExists(winFolder):
moveDirContents(winFolder, extractDir)
Copy link
Owner

Choose a reason for hiding this comment

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

Can't you just use moveDir here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moveDir() raises an exception since directory already exists.

Error: unhandled exception: Cannot create a file when that file already exists. Good old Windows.

Copy link
Owner

Choose a reason for hiding this comment

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

Why would that directory already exist? Even if it exists, can't we just overwrite it?

errC = 0

when defined(windows):
(outp, errC) = execCmdEx("cmd /c echo int main^(^) { return sizeof^(void *^); } | gcc -xc - -o archtest && archtest")
Copy link
Owner

Choose a reason for hiding this comment

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

Is this not POSIX Shell syntax?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what was added to build.bat to allow gcc arch detection.

https://github.com/nim-lang/csources/blob/master/build.bat#L14

@genotrance
Copy link
Collaborator Author

I'm closing this PR in favor of simpler PRs that can be reviewed and accepted quickly.

@genotrance genotrance closed this Jan 3, 2019
iffy pushed a commit to iffy/choosenim that referenced this pull request Jul 11, 2025
fix(switcher.nim): fix CC for FreeBSD
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.

4 participants