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

Fix rebuild logic binary checks for windows #24

Open
gradha opened this issue Mar 19, 2015 · 8 comments
Open

Fix rebuild logic binary checks for windows #24

gradha opened this issue Mar 19, 2015 · 8 comments

Comments

@gradha
Copy link
Contributor

gradha commented Mar 19, 2015

Looking at the logic of #23 the code performs the nakefile check like:

binaryTime = toSeconds(getLastModificationTime("nakefile"))

This doesn't include the exe extension for the windows binary, so it will likely fail. Or did windows drop file extensions for binaries?

@fowlmouth
Copy link
Owner

turns out those dont work on windows, it just raises the exception and goes along, can be fixed with findExe("nakefile"), we can expect there to not be another nakefile.exe on PATH, right?

@fowlmouth
Copy link
Owner

ok so I had this mostly working then I discovered why findExe("nake") wasnt working, in my nimble/bin the exes don't have exe in them, just .cmd launchers

fowlmouth added a commit that referenced this issue Mar 21, 2015
note nake.exe time check will not work on windows because there is no .exe file in .nimble/bin

refs #24
@gradha
Copy link
Contributor Author

gradha commented Mar 21, 2015

Instead of using findExe I was more thinking of something like getFilePermissions("."/addFileExt("nakefile", ExeExt)) to avoid looking at the path and be more in line with the last shell call which also prefixes the current directory to avoid troubles.

The .cmd extension you mention looks problematic, should then nim's stdlib findExe be upgraded to look for such extension on windows? nake could of course provide it's own implementation, but if this is the usual way of installing binaries on windows with nimble, other programs depending on calling findExe for nimble binaries would fail too?

@fowlmouth
Copy link
Owner

os.findExe doesnt look like it would be easy to fix, it relies on a const that says what an "exe" is for a platform and it only considers there to be one exe suffix for any platform. I'll write a specialized version for nake

@gradha
Copy link
Contributor Author

gradha commented Mar 26, 2015

Maybe a good idea to avoid painting ourselves into a corner would be to leave the interface open through a default parameter or a global variable:

import os

when defined(windows):
  const defaultBinaryExtensions = ["exe", "com", "bat"]
else:
  const defaultBinaryExtensions = ["", "sh", "bin"]

proc findBinary(filename: string,
    extensions: varargs[string] = defaultBinaryExtensions) =
  let dummyPaths = ["dir1", "dir2", "dir3"]
  for path in dummyPaths:
    for extension in extensions:
      echo "Testing ", path/filename.addFileExt(extension)

when isMainModule:
  findBinary("compiler")
  findBinary("compiler", ["cmd", "shell"])

The global variable version would have the advantage of affecting all findBinary calls, even those not in reach by end user code, so maybe its better? Your call.

@fowlmouth
Copy link
Owner

I'd prefer something like this, only difference is slightly less string ops (we can delay adding the path until the file is found)

proc findFile(filename: string,
    extensions: openarray[string] = defaultBinaryExtensions,
    paths: varargs[string]): string =
  result = ""
  if paths.len < 1: return
  let curdir = getCurrentDir()
  block search:
    for path in paths:
      setCurrentDir(path)
      for extension in extensions:
        let f = filename.addFileExt(extension)
        if fileExists(f):
          result = path / f
          break search
  setCurrentDir(curdir)

@gradha
Copy link
Contributor Author

gradha commented Mar 27, 2015

I imagine changing the current environment directory would be more expensive than a few string concatenations, but then it's not like performance is critical, it is already going to be slow with the calls to fileExists.

@Araq
Copy link

Araq commented Apr 5, 2017

Newer Nim's findExe also considers .cmd and .bat extensions out of the box.

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

No branches or pull requests

3 participants