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

Regression in Nimscript projectDir() behavior, returns empty string #9985

Closed
kaushalmodi opened this issue Dec 14, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@kaushalmodi
Copy link
Contributor

commented Dec 14, 2018

This is a very recent regression, probably related with the os paths refactoring.

Earlier the projectDir() in nimscript returned the correct non-empty string, a path string.

Now it is returning an empty string.

Example

In my ~/.config/nim/config.nims, I have a function like this:

proc getGitRootMaybe(): string =
  ## Try to get the path to the current git root directory.
  ## Return ``projectDir()`` if a ``.git`` directory is not found.
  const
    maxAttempts = 10            # arbitrarily picked
  var
    path = projectDir() # projectDir() needs nim 0.20.0 (or nim devel as of Tue Oct 16 08:41:09 EDT 2018)
    attempt = 0
  while (attempt < maxAttempts) and (not existsDir(path / ".git")):
    path = path / "../"
    attempt += 1
  if existsDir(path / ".git"):
    result = path
  else:
    result = projectDir()

code reference

Current Output

I download that config.nims before running Travis tests for my elnim project. I run the tests every week (Travis cron) after building the latest Nim devel.

Today, that test started failing:

$ nim test
Hint: used config file '/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/config/nim.cfg' [Conf]
Hint: used config file '/home/travis/build/kaushalmodi/elnim/config.nims' [Conf]
Hint: used config file '/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/config/nim.cfg' [Conf]
Hint: used config file '/home/travis/build/kaushalmodi/elnim/config.nims' [Conf]
Hint: used config file '/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/config/nimdoc.cfg' [Conf]
Hint: system [Processing]
Error: invalid module name: .nim
stack trace: (most recent call last)
/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/lib/system/nimscript.nim(351)
/home/travis/build/kaushalmodi/elnim/config.nims(242) testTask
/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/lib/system/nimscript.nim(252) selfExec
/home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/lib/system/nimscript.nim(252, 7) Error: unhandled exception: FAILED: /home/travis/build/kaushalmodi/elnim/nim/f76bd06643d0b8ee4de18808eb73d78e9aa91270/bin/nim doc src/.nim
The command "nim test" exited with 1.

Travis log

The error is "Error: invalid module name: .nim" because projectDir() returns "", and then this code in config.nims:

let
  root = getGitRootMaybe()
  (_, pkgName) = root.splitPath()
  srcFile = root / "src" / (pkgName & ".nim")

resolves srcFile to just ".nim".

On locally building Nim devel f76bd06, I could recreate the same failing on doing nim test locally too.

To recreate this error, simply add echo "project dir = ", projectDir() to your project's config.nims or the ~/.config/nim/config.nims.

Expected Output

With echo "project dir = ", projectDir() in your config.nims, it should print a non-empty string for project dir path.

@Araq Araq closed this in a87be40 Dec 15, 2018

nc-x added a commit to nc-x/Nim that referenced this issue Dec 16, 2018

Revert "fixes nim-lang#9985"
This reverts commit a87be40.

nc-x added a commit to nc-x/Nim that referenced this issue Dec 16, 2018

Revert "fixes nim-lang#9985"
This reverts commit a87be40.

nc-x added a commit to nc-x/Nim that referenced this issue Dec 16, 2018

Revert "fixes nim-lang#9985"
This reverts commit a87be40.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.