Repository: nvaccess/nvda

Issue:
Undesirable side effect of versioned lib path: scons source required after every commit or branch change
Regression caused by #7535. Note that this issue is only related to running NVDA development version from source.

### Steps to reproduce:
1. Check out NVDA master branch
2. Run scons source to create a fully functional source tree
3. Execute "git checkout -b newTopicBranch"
4. Try to start NVDA from source

### Expected behavior:
Since there haven't been changes in NVDAHelper or other libraries, NVDA should just start from source without any problems.

### Actual behavior:
Core failure due to searching libraries in a non-existent path.

### Additional thoughts
Although versioned library paths make perfect sense due to the problems they fix, they have a negative impact on on the development experience and work flow. It is quite time consuming and therefore undesirable to run a scons source after every single commit.

Also note that, unless you do a git clean quite regularly, obsolete libraries from earlier scons source runs don't get cleaned up.

### Proposed fixes
1. Make scons source clean up source/lib and source/lib64. This code can basically be copied from installer.removeOldProgramFiles
2. In sourceEnv, set the versioned lib paths to the most recent folder that has been populated with libraries.


Discussion:
Any thoughts from other core contributors besides NV Access are appreciated. cc @josephsl @dkager @derekriemer
Sounds reasonable, though I never studied the build system in detail so I don't know if (2) would fix this.
I agree that `scons source` after every commit or checkout slows down the development process.
The danger with (2) is that if you checked out master from next it would use those libs and claim nothing needed done. It very well might.
[**@derekriemer**](https://github.com/derekriemer) commented on [21 Sep 2017, 00:33 CEST](https://github.com/nvaccess/nvda/issues/7614#issuecomment-330999813 "2017-09-20T22:33:34Z - Replied by Github Reply Comments"):
> The danger with (2) is that if you checked out master from next it would use those libs and claim nothing needed done. It very well might.

Honestly, in most of the cases previously, I ran scons source from next and checked out master without another run, and this worked without problems unless we had major submodule differences.
sure, but that doesn't mean we can make a universal generalization and copy the master files over to next if they exist. Just because it might work doesn't mean we can, or should make the build system do this.
[**@derekriemer**](https://github.com/derekriemer) commented on [21 sep. 2017 07:51 CEST](https://github.com/nvaccess/nvda/issues/7614#issuecomment-331058213 "2017-09-21T05:51:14Z - Replied by Github Reply Comments"):
> Just because it might work doesn't mean we can, or should make the build system do this.

I agree with that point. The only major concern I have with the current approach is that it slows down the development process, at least for me. Also note that if you really want to make sure that everything is up to date, you can always run a scons source, just as how it was before. The only thing I'd like to see is that development experience is restored to how it was before #7535, preferable in the most elegant way.

Resolving patch:
diff --git a/appveyor/mozillaSyms.py b/appveyor/mozillaSyms.py
--- a/appveyor/mozillaSyms.py
+++ b/appveyor/mozillaSyms.py
@@ -14,12 +14,11 @@
 import zipfile
 import requests
 
-NVDA_VERSION=os.getenv('version')
 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
 DUMP_SYMS = os.path.join(SCRIPT_DIR, "dump_syms.exe")
 NVDA_SOURCE = os.path.join(os.path.dirname(SCRIPT_DIR), "source")
-NVDA_LIB = os.path.join(NVDA_SOURCE, "lib",NVDA_VERSION)
-NVDA_LIB64 = os.path.join(NVDA_SOURCE, "lib64",NVDA_VERSION)
+NVDA_LIB = os.path.join(NVDA_SOURCE, "lib")
+NVDA_LIB64 = os.path.join(NVDA_SOURCE, "lib64")
 ZIP_FILE = os.path.join(SCRIPT_DIR, "mozillaSyms.zip")
 URL = 'https://crash-stats.mozilla.com/symbols/upload'
 
diff --git a/source/NVDAHelper.py b/source/NVDAHelper.py
--- a/source/NVDAHelper.py
+++ b/source/NVDAHelper.py
@@ -18,8 +18,12 @@
 import time
 import globalVars
 
-versionedLibPath=os.path.join('lib',versionInfo.version)
-versionedLib64Path=os.path.join('lib64',versionInfo.version)
+versionedLibPath='lib'
+versionedLib64Path='lib64'
+if getattr(sys,'frozen',None):
+	# Not running from source. Libraries are in a version-specific directory
+	versionedLibPath=os.path.join(versionedLibPath,versionInfo.version)
+	versionedLib64Path=os.path.join(versionedLib64Path,versionInfo.version)
 
 _remoteLib=None
 _remoteLoader64=None
diff --git a/source/setup.py b/source/setup.py
--- a/source/setup.py
+++ b/source/setup.py
@@ -222,8 +222,8 @@ def getRecursiveDataFiles(dest,source,excludes=()):
 	data_files=[
 		(".",glob("*.dll")+glob("*.manifest")+["builtin.dic"]),
 		("documentation", ['../copying.txt', '../contributors.txt']),
-		("lib/%s"%version, glob("lib/%s/*.dll"%version)),
-		("lib64/%s"%version, glob("lib64/%s/*.dll"%version) + glob("lib64/%s/*.exe"%version)),
+		("lib/%s"%version, glob("lib/*.dll")),
+		("lib64/%s"%version, glob("lib64/*.dll") + glob("lib64/*.exe")),
 		("waves", glob("waves/*.wav")),
 		("images", glob("images/*.ico")),
 		("louis/tables",glob("louis/tables/*")),


Test patch: