-
Notifications
You must be signed in to change notification settings - Fork 64
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
Multiple features #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ const | |
githubUrl = "https://github.com/nim-lang/Nim/archive/$1.tar.gz" | ||
websiteUrl = "http://nim-lang.org/download/nim-$1.tar" & | ||
getArchiveFormat() | ||
csourcesUrl = "https://github.com/nim-lang/csources/archive/master.tar.gz" | ||
csourcesUrl = "https://github.com/nim-lang/csources/archive/$1.tar.gz" | ||
winBinaryZipUrl = "http://nim-lang.org/download/nim-$1_x$2.zip" | ||
|
||
const # Windows-only | ||
mingwUrl = "http://nim-lang.org/download/mingw32.tar.gz" | ||
|
@@ -198,7 +199,21 @@ proc needsDownload(params: CliParams, downloadUrl: string, | |
priority=HighPriority) | ||
return false | ||
|
||
proc downloadCheck(params: CliParams, url: string): string = | ||
result = "" | ||
if not needsDownload(params, url, result): return | ||
|
||
downloadFile(url, result, params) | ||
|
||
proc downloadCheckRenamed(params: CliParams, url, filename: string): string = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or maybe |
||
# Special check since we have to rename to disambiguate | ||
result = getDownloadDir(params) / filename | ||
if not fileExists(result): | ||
let origfile = downloadCheck(params, url) | ||
moveFile(origfile, result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at this in more detail this seems unnecessary. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into cleaning up the proc names and avoid renaming. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There are two reasons to rename:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, what I would do is overload 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. |
||
|
||
proc downloadImpl(version: Version, params: CliParams): string = | ||
let arch = getGccArch() | ||
if version.isSpecial(): | ||
let reference = | ||
case normalize($version) | ||
|
@@ -208,21 +223,28 @@ proc downloadImpl(version: Version, params: CliParams): string = | |
($version)[1 .. ^1] | ||
display("Downloading", "Nim $1 from $2" % [reference, "GitHub"], | ||
priority = HighPriority) | ||
let url = githubUrl % reference | ||
var outputPath: string | ||
if not needsDownload(params, url, outputPath): return outputPath | ||
|
||
downloadFile(url, outputPath, params) | ||
result = outputPath | ||
result = downloadCheck(params, githubUrl % reference) | ||
else: | ||
display("Downloading", "Nim $1 from $2" % [$version, "nim-lang.org"], | ||
priority = HighPriority) | ||
let url = websiteUrl % $version | ||
var outputPath: string | ||
if not needsDownload(params, url, outputPath): return outputPath | ||
|
||
downloadFile(url, outputPath, params) | ||
result = outputPath | ||
# Check if binary build available | ||
when defined(windows): | ||
try: | ||
result = downloadCheck(params, winBinaryZipUrl % [$version, $arch]) | ||
return | ||
except HttpRequestError: | ||
display("Info:", "Binary build unavailable, building from source", | ||
priority = HighPriority) | ||
|
||
# Check if source tar.gz posted on nim-lang.org | ||
try: | ||
result = downloadCheck(params, websiteUrl % $version) | ||
except HttpRequestError: | ||
# Fallback to downloading from Github | ||
# Rename to nim-VERSION.tar.gz to disambiguate | ||
result = downloadCheckRenamed(params, githubUrl % ("v" & $version), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"nim-$1.tar.gz" % $version) | ||
|
||
proc download*(version: Version, params: CliParams): string = | ||
## Returns the path of the downloaded .tar.(gz|xz) file. | ||
|
@@ -232,32 +254,26 @@ proc download*(version: Version, params: CliParams): string = | |
raise newException(ChooseNimError, "Version $1 does not exist." % | ||
$version) | ||
|
||
proc downloadCSources*(params: CliParams): string = | ||
var outputPath: string | ||
if not needsDownload(params, csourcesUrl, outputPath): | ||
return outputPath | ||
|
||
proc downloadCSources*(params: CliParams, version: Version): string = | ||
display("Downloading", "Nim C sources from GitHub", priority = HighPriority) | ||
downloadFile(csourcesUrl, outputPath, params) | ||
return outputPath | ||
try: | ||
# Download csources tagged version from Github | ||
# Rename to csources-VERSION.tar.gz to disambiguate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my remark above, renaming shouldn't be necessary. |
||
result = downloadCheckRenamed(params, csourcesUrl % ("v" & $version), | ||
"csources-$1.tar.gz" % $version) | ||
except HttpRequestError: | ||
result = downloadCheck(params, csourcesUrl % "master") | ||
display("Warning:", "Building from latest C sources. They may not be " & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: *Downloading the latest C sources There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"compatible with the Nim version you have chosen to " & | ||
"install.", Warning, HighPriority) | ||
|
||
proc downloadMingw32*(params: CliParams): string = | ||
var outputPath: string | ||
if not needsDownload(params, mingwUrl, outputPath): | ||
return outputPath | ||
|
||
display("Downloading", "C compiler (Mingw32)", priority = HighPriority) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
downloadFile(mingwUrl, outputPath, params) | ||
return outputPath | ||
result = downloadCheck(params, mingwUrl) | ||
|
||
proc downloadDLLs*(params: CliParams): string = | ||
var outputPath: string | ||
if not needsDownload(params, dllsUrl, outputPath): | ||
return outputPath | ||
|
||
display("Downloading", "DLLs (openssl, pcre, ...)", priority = HighPriority) | ||
downloadFile(dllsUrl, outputPath, params) | ||
return outputPath | ||
result = downloadCheck(params, dllsUrl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
proc retrieveUrl*(url: string): string = | ||
when defined(curl): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,24 @@ proc doCmdRaw*(cmd: string) = | |
"Execution failed with exit code $1\nCommand: $2\nOutput: $3" % | ||
[$exitCode, cmd, output]) | ||
|
||
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'); }\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would like this, but I'm not going to block you for it. |
||
|
||
let (outp, errC) = execCmdEx(cmd % [path, extractDir]) | ||
if errC != 0: | ||
raise newException(ChooseNimError, "Unable to extract ZIP. Error was $1" % outp) | ||
|
||
proc extract*(path: string, extractDir: string) = | ||
display("Extracting", path.extractFilename(), priority = HighPriority) | ||
|
||
let ext = path.splitFile().ext | ||
var newPath = path | ||
case ext | ||
of ".zip": | ||
extractZip(path, extractDir) | ||
return | ||
of ".xz": | ||
# We need to decompress manually. | ||
let unxzPath = findExe("unxz") | ||
|
@@ -51,6 +63,27 @@ proc extract*(path: string, extractDir: string) = | |
raise newException(ChooseNimError, "Unable to extract. Error was '$1'." % | ||
exc.msg) | ||
|
||
proc moveDirContents*(srcDir, dstDir: string) = | ||
for kind, entry in walkDir(srcDir): | ||
if kind in [pcFile, pcLinkToFile]: | ||
moveFile(entry, dstDir/entry.extractFilename()) | ||
else: | ||
moveDir(entry, dstDir/entry.extractFilename()) | ||
|
||
proc getGccArch*(): int = | ||
# gcc should be in PATH | ||
var | ||
outp = "" | ||
errC = 0 | ||
|
||
when defined(windows): | ||
(outp, errC) = execCmdEx("cmd /c echo int main^(^) { return sizeof^(void *^); } | gcc -xc - -o archtest && archtest") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not POSIX Shell syntax? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
else: | ||
(outp, errC) = execCmdEx("sh echo \"int main() { return sizeof(void *); }\" | gcc -xc - -o archtest && archtest") | ||
|
||
removeFile("archtest".addFileExt(ExeExt)) | ||
return errC * 8 | ||
|
||
proc getProxy*(): Proxy = | ||
## Returns ``nil`` if no proxy is specified. | ||
var url = "" | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?