squattingmonk / nasher

A build tool for Neverwinter Nights projects
MIT License
43 stars 17 forks source link

Excluding files doesn't work when using relative paths #90

Closed tinygiant98 closed 2 years ago

tinygiant98 commented 2 years ago

I've recently modified my projects to use the nwn-core-framework module as a base and use nasher's ability to exclude files to override the files I don't want to use (such as core_c_config.nss, which are project-specific. In nasher.cfg, I generally include the framework files like this:

include = "../nwn-core-framework/src/**/*.{nss,json}"

and it works fine, but when I want to exclude a specific file, like this, it doesn't exclude that file. I'll still get a "multiple locations" prompt during install/pack operations.

exclude = "../nwn-core-framework/src/demo/core_c_config.nss"

Using an absolute path does make this methodology work, as shown here:

exclude = "h:/projects/nwn-core-framework/src/demo/core_c_config.nss"

Suggested fix ... modify pathing to use absolute paths instead of relative paths when relative paths are provided. I haven't gotten into the code to see where this should be done, but I will as soon as I have a chance.

tinygiant98 commented 2 years ago

After some debugging, looks like it's not a pathing issue. Will report back ...

tinygiant98 commented 2 years ago

So it appears it's sort of a pathing issue. In options.nim, changing line 406 from:

of "exclude": target.excludes.add(e.value)

to

of "exclude": target.excludes.add(replace(e.value.absolutePath, '\\', '/'))

solves the issue. Not sure why and I'm wondering if this is a windows-only issue versus a problem across all systems.

Also, not sure what repercussions that change would have on relative pathing within the nasher project folder.

squattingmonk commented 2 years ago

This is not a Windows-only issue. The problem lies in walkSourceFiles in shared.nim, since walkGlobs returns absolute paths.

nasher should always set the current directory to the project root. I doubt this change would create any problems.

squattingmonk commented 2 years ago

Sorry I didn't move on this sooner. I've been having trouble getting it to match exclude directives that have glob characters in them. It doesn't look like the **/* syntax works. I've also tried converting the paths yielded by walkGlob to relative paths with the same issue.

I think the way to resolve this would be walk the exclude patterns, generate a list of files to be excluded, and then check if each included file is in that list.

Could you try the fix-issue-90 branch and see if it works for you? It includes commit 18abd3a, which allows listing of the source files, so that should make it easier to test.

tinygiant98 commented 2 years ago

Yup, but won't be able to for a day or two. Thanks!

squattingmonk commented 2 years ago

@tinygiant98, have you been able to test this yet?