public static SwiftTargetCompilerInfo Create(SwiftCompilerLocation compilerLocation, string target)
        {
            if (compilerLocation == null)
            {
                throw new ArgumentNullException(nameof(compilerLocation));
            }

            string pathToCompilerLib = compilerLocation.SwiftCompilerLib;
            string sdkPath           = "";

            if (target != null)
            {
                string parent = ReliablePath.GetParentDirectory(pathToCompilerLib);
                sdkPath           = SdkForTarget(target);
                pathToCompilerLib = Path.Combine(parent, sdkPath);
            }

            if (!Directory.Exists(pathToCompilerLib))
            {
                throw ErrorHelper.CreateError(ReflectorError.kCantHappenBase + 18, $"Unable to find path to compiler library directory '{pathToCompilerLib}'.");
            }

            string swiftc = Path.Combine(compilerLocation.SwiftCompilerBin, "swiftc");
            string swift  = Path.Combine(compilerLocation.SwiftCompilerBin, "swift");

            return(new SwiftTargetCompilerInfo(target, compilerLocation.SwiftCompilerBin, pathToCompilerLib, swiftc, swift, sdkPath));
        }
Esempio n. 2
0
        void AppendLibraryAndFrameworks(StringBuilder sb, IEnumerable <string> candidateDirectories,
                                        string [] modNames, bool addReference)
        {
            List <string> candidates     = candidateDirectories.ToList();
            List <string> fwkDirectories = new List <string> ();
            List <string> libs           = new List <string> ();
            List <string> fwks           = new List <string> ();

            foreach (string moduleName in modNames)
            {
                string swiftModule = moduleName + ".swiftmodule";
                bool   addedFwk    = false;
                for (int i = 0; i < candidates.Count(); i++)
                {
                    // if it's a framework, there will be a one-to-one mapping of module names -> framework directories
                    // remove the path from the candidate and move it to fwkDirectories
                    // and add the name to fwks
                    if (SwiftModuleFinder.IsAppleFramework(candidates [i], swiftModule))
                    {
                        fwks.Add(moduleName);
                        fwkDirectories.Add(candidates [i]);
                        candidates.RemoveAt(i);
                        addedFwk = true;
                        break;
                    }
                }
                // if we didn't add a framework, it's probably a library
                if (!addedFwk)
                {
                    libs.Add(moduleName);
                }
                addedFwk = false;
            }

            foreach (string libdir in candidates)
            {
                sb.Append("-L ").Append(QuoteIfNeeded(libdir)).Append(' ');
            }

            foreach (string fwkdir in fwkDirectories)
            {
                string parentdir = ReliablePath.GetParentDirectory(fwkdir);
                sb.Append("-F ").Append(QuoteIfNeeded(parentdir)).Append(' ');
            }

            sb.Append("-L ").Append(QuoteIfNeeded(CompilerInfo.LibDirectory)).Append(' ');

            if (addReference)
            {
                foreach (string lib in libs)
                {
                    sb.Append("-l").Append(lib).Append(' ');
                }
                foreach (string fwk in fwks)
                {
                    sb.Append("-framework ").Append(fwk).Append(' ');
                }
            }
        }