alliedmodders / ambuild

AlliedModders C++ Build System
BSD 3-Clause "New" or "Revised" License
60 stars 31 forks source link

Can't specify path in hl2sdk-manifests option #160

Open Fighter19 opened 6 months ago

Fighter19 commented 6 months ago

While specifying an absolute path outside of the current working directory, the call to computeScriptPaths in context_manager.py, will badly determine the location of the script and therefore concatenate an absolute path with another absolute path, leading to an error.

HL2SDKCS2=/very/long/path/on/hdd/data/Git/hl2sdk python ../configure.py -s cs2 --hl2sdk-manifests /very/long/path/on/hdd/data/Git/metamod-source/hl2sdk-manifests/
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/prep.py", line 156, in Configure
    if not cm.generate(options.generator):
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/context_manager.py", line 93, in generate
    self.parseBuildScripts()
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 50, in parseBuildScripts
    self.execContext(cx)
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 152, in execContext
    exec(code, scriptGlobals)
  File "/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/AMBuildScript", line 68, in <module>
    SdkHelpers = builder.Eval(os.path.join(hl2sdk_manifests, 'SdkHelpers.ambuild'), {
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context.py", line 115, in Eval
    return self.cm.evalScript(self, path, vars or {})
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 60, in evalScript
    obj = self.importScriptImpl(context, path, vars or {})
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 81, in importScriptImpl
    self.generator.addConfigureFile(parent, scriptPath)
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/amb2_gen.py", line 744, in addConfigureFile
    self.db.add_or_update_script(path)
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/database.py", line 826, in add_or_update_script
    stamp = os.path.getmtime(path)
  File "/usr/lib/python3.10/genericpath.py", line 55, in getmtime
    return os.stat(filename).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/very/long/path/on/hdd/data/Git/metamod-source/hl2sdk-manifests/SdkHelpers.ambuild'

Furthermore it seems that this is also the case when trying to specify a relative path:

HL2SDKCS2=/very/long/path/on/hdd/data/Git/hl2sdk python ../configure.py -s cs2 --hl2sdk-manifests ../../hl2sdk-manifests/
Script File: ../../hl2sdk-manifests/SdkHelpers.ambuild
Source Path: /very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm
Both: /very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/../../hl2sdk-manifests/SdkHelpers.ambuild
Checking CC compiler (vendor test gcc)... ['clang', '-m32', 'test.c', '-o', 'test-c']
found clang version 14.0, x86
Checking CXX compiler (vendor test gcc)... ['clang++', '-m32', 'test.cpp', '-o', 'test-cxx']
found clang version 14.0, x86
Checking CC compiler (vendor test gcc)... ['clang', '-m64', 'test.c', '-o', 'test-c']
found clang version 14.0, x86_64
Checking CXX compiler (vendor test gcc)... ['clang++', '-m64', 'test.cpp', '-o', 'test-cxx']
found clang version 14.0, x86_64
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/prep.py", line 156, in Configure
    if not cm.generate(options.generator):
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/context_manager.py", line 93, in generate
    self.parseBuildScripts()
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 50, in parseBuildScripts
    self.execContext(cx)
  File "/home/user/.local/lib/python3.10/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 152, in execContext
    exec(code, scriptGlobals)
  File "/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/AMBuildScript", line 305, in <module>
    MMSPlugin.detectSDKs()
  File "/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/AMBuildScript", line 123, in detectSDKs
    SdkHelpers.findSdks(builder, self.all_targets, sdk_list)
  File "/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/../../hl2sdk-manifests/SdkHelpers.ambuild", line 23, in findSdks
    for sdk_name, sdk in SdkHelpers.getSdks(builder):
  File "/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/../../hl2sdk-manifests/SdkHelpers.ambuild", line 126, in getSdks
    for sdk_manifest in os.listdir(sdk_manifest_dir):
FileNotFoundError: [Errno 2] No such file or directory: '/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/hl2sdk-manifests/manifests'
Configure failed: [Errno 2] No such file or directory: '/very/long/path/on/hdd/data/Git/metamod-source/samples/s2_sample_mm/hl2sdk-manifests/manifests'
psychonic commented 1 month ago

While it sounds like there's a potential issue here with AMBuild's path handling, the specific problem mentioned has now been addressed within SdkHelpers by automatically converting to correct absolute paths within there.

psychonic commented 1 month ago

I believe that the remaining issue here is addressed by https://github.com/alliedmodders/ambuild/pull/170