@@ -737,6 +737,125 @@ const DownstreamCompiler::Desc& DownstreamCompilerUtil::getCompiledWithDesc()
737
737
outFuncs[int (SLANG_PASS_THROUGH_GLSLANG)] = &GlslangDownstreamCompilerUtil::locateCompilers;
738
738
}
739
739
740
+ static String _getParentPath (const String& path)
741
+ {
742
+ // If we can get the canonical path, we'll do that before getting the parent
743
+ String canonicalPath;
744
+ if (SLANG_SUCCEEDED (Path::getCanonical (path, canonicalPath)))
745
+ {
746
+ return Path::getParentDirectory (canonicalPath);
747
+ }
748
+ else
749
+ {
750
+ return Path::getParentDirectory (path);
751
+ }
752
+ }
753
+
754
+ static SlangResult _findPaths (const String& path, const char * libraryName, String& outParentPath, String& outLibraryPath)
755
+ {
756
+ // Try to determine what the path is by looking up the path type
757
+ SlangPathType pathType;
758
+ if (SLANG_SUCCEEDED (Path::getPathType (path, &pathType)))
759
+ {
760
+ if (pathType == SLANG_PATH_TYPE_DIRECTORY)
761
+ {
762
+ outParentPath = path;
763
+ outLibraryPath = Path::combine (outParentPath, libraryName);
764
+ }
765
+ else
766
+ {
767
+ SLANG_ASSERT (pathType == SLANG_PATH_TYPE_FILE);
768
+
769
+ outParentPath = _getParentPath (path);
770
+ outLibraryPath = path;
771
+ }
772
+
773
+ return SLANG_OK;
774
+ }
775
+
776
+ // If this failed the path could be to a shared library, but we may need to convert to the shared library filename first
777
+ const String sharedLibraryFilePath = SharedLibrary::calcPlatformPath (path.getUnownedSlice ());
778
+ if (SLANG_SUCCEEDED (Path::getPathType (sharedLibraryFilePath, &pathType)) && pathType == SLANG_PATH_TYPE_FILE)
779
+ {
780
+ // We pass in the shared library path, as canonical paths can sometimes only apply to pre-existing objects.
781
+ outParentPath = _getParentPath (sharedLibraryFilePath);
782
+ // The original path should work as is for the SharedLibrary load. Notably we don't use the sharedLibraryFilePath
783
+ // as this is the wrong name to do a SharedLibrary load with.
784
+ outLibraryPath = path;
785
+
786
+ return SLANG_OK;
787
+ }
788
+
789
+ return SLANG_FAIL;
790
+ }
791
+
792
+ /* static */ SlangResult DownstreamCompilerUtil::loadSharedLibrary (const String& path, ISlangSharedLibraryLoader* loader, const char *const * dependentNames, const char * inLibraryName, ComPtr<ISlangSharedLibrary>& outSharedLib)
793
+ {
794
+ String parentPath;
795
+ String libraryPath;
796
+
797
+ // If a path is passed in lets, try and determine what kind of path it is.
798
+ if (path.getLength ())
799
+ {
800
+ if (SLANG_FAILED (_findPaths (path, inLibraryName, parentPath, libraryPath)))
801
+ {
802
+ // We have a few scenarios here.
803
+ // 1) The path could be the shared library/dll filename, that will be found through some operating system mechanism
804
+ // 2) That the shared library is *NOT* on the filesystem directly (the loader does something different)
805
+ // 3) Permissions or some other mechanism stops the lookup from working
806
+
807
+ // We should probably assume that the path means something, else why set it.
808
+ // It's probably less likely that it is a directory that we can't detect - as if it's a directory as part of an app
809
+ // it's permissions should allow detection, or be made to allow it.
810
+
811
+ // All this being the case we should probably assume that it is the shared library name.
812
+ libraryPath = path;
813
+
814
+ // Attempt to get a parent. If there isn't one this will be empty, which will mean it will be ignored, which is probably
815
+ // what we want if path is just a shared library name
816
+ parentPath = Path::getParentDirectory (libraryPath);
817
+ }
818
+ }
819
+
820
+ // Keep all dependent libs in scope, before we load the library we want
821
+ List<ComPtr<ISlangSharedLibrary>> dependentLibs;
822
+
823
+ // Try to load any dependent libs from the parent path
824
+ if (dependentNames)
825
+ {
826
+ for (const char *const * cur = dependentNames; *cur; ++cur)
827
+ {
828
+ const char * dependentName = *cur;
829
+ ComPtr<ISlangSharedLibrary> lib;
830
+ if (parentPath.getLength ())
831
+ {
832
+ String dependentPath = Path::combine (parentPath, dependentName);
833
+ loader->loadSharedLibrary (dependentPath.getBuffer (), lib.writeRef ());
834
+ }
835
+ else
836
+ {
837
+ loader->loadSharedLibrary (dependentName, lib.writeRef ());
838
+ }
839
+
840
+ if (lib)
841
+ {
842
+ dependentLibs.add (lib);
843
+ }
844
+ }
845
+ }
846
+
847
+ if (libraryPath.getLength ())
848
+ {
849
+ // If we hare a library path use that
850
+ return loader->loadSharedLibrary (libraryPath.getBuffer (), outSharedLib.writeRef ());
851
+ }
852
+ else
853
+ {
854
+ // Else just use the name that was passed in.
855
+ return loader->loadSharedLibrary (inLibraryName, outSharedLib.writeRef ());
856
+ }
857
+ }
858
+
740
859
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompilerSet !!!!!!!!!!!!!!!!!!!!!!*/
741
860
742
861
void DownstreamCompilerSet::getCompilerDescs (List<DownstreamCompiler::Desc>& outCompilerDescs) const
@@ -813,4 +932,6 @@ void DownstreamCompilerSet::addCompiler(DownstreamCompiler* compiler)
813
932
}
814
933
}
815
934
935
+
936
+
816
937
}
0 commit comments