Exemplo n.º 1
0
        public static ResponseFileData ParseResponseFileFromFile(
            string responseFilePath,
            string projectDirectory,
            string[] systemReferenceDirectories)
        {
            if (!File.Exists(responseFilePath))
            {
                var empty = new ResponseFileData
                {
                    Defines            = new string[0],
                    FullPathReferences = new ResponseFileData.Reference[0],
                    Unsafe             = false,
                    Errors             = new string[0]
                };

                return(empty);
            }

            var responseFileText = File.ReadAllText(responseFilePath);

            return(ParseResponseFileText(
                       responseFileText,
                       responseFilePath,
                       projectDirectory,
                       systemReferenceDirectories));
        }
Exemplo n.º 2
0
        public static ResponseFileData ParseResponseFileFromFile(
            string responseFilePath,
            string projectDirectory,
            string[] systemReferenceDirectories)
        {
            responseFilePath = Paths.ConvertSeparatorsToUnity(responseFilePath);
            projectDirectory = Paths.ConvertSeparatorsToUnity(projectDirectory);

            var relativeResponseFilePath = Paths.GetPathRelativeToProjectDirectory(responseFilePath);

            if (File.Exists(responseFilePath))
            {
                var responseFileText = File.ReadAllText(responseFilePath);
                return(ParseResponseFileText(
                           responseFileText,
                           responseFilePath,
                           projectDirectory,
                           systemReferenceDirectories));
            }
            else
            {
                var empty = new ResponseFileData
                {
                    Defines            = new string[0],
                    FullPathReferences = new string[0],
                    Unsafe             = false,
                    Errors             = new string[0],
                    OtherArguments     = new string[0],
                };

                return(empty);
            }
        }
Exemplo n.º 3
0
        static ResponseFileData ParseResponseFileText(
            string fileContent,
            string fileName,
            string projectDirectory,
            string[] systemReferenceDirectories)
        {
            List <ScriptCompilerBase.CompilerOption> compilerOptions = GetCompilerOptions(fileContent);

            var  responseArguments = new List <string>();
            var  defines           = new List <string>();
            var  references        = new List <string>();
            bool unsafeDefined     = false;
            var  errors            = new List <string>();

            foreach (var option in compilerOptions)
            {
                var arg   = option.Arg;
                var value = option.Value;

                if (IsDefine(option))
                {
                    defines.AddRange(GetOptionDefines(option));
                }
                else if (IsReference(option))
                {
                    if (TryGetReference(option, fileName, projectDirectory, systemReferenceDirectories, ref errors,
                                        out var result))
                    {
                        references.Add(result);
                    }
                }
                else if (IsSetUnsafe(option))
                {
                    unsafeDefined = true;
                }
                else if (IsUnsetUnsafe(option))
                {
                    unsafeDefined = false;
                }
                else
                {
                    var valueWithColon = value.Length == 0 ? "" : ":" + SafeArgString(value);
                    responseArguments.Add(arg + valueWithColon);
                }
            }

            var responseFileData = new ResponseFileData
            {
                Defines            = defines.ToArray(),
                FullPathReferences = references.ToArray(),
                Unsafe             = unsafeDefined,
                Errors             = errors.ToArray(),
                OtherArguments     = responseArguments.ToArray(),
            };

            return(responseFileData);
        }
Exemplo n.º 4
0
        public static ResponseFileData ParseResponseFileFromFile(string responseFilePath)
        {
            if (!File.Exists(responseFilePath))
            {
                var empty = new ResponseFileData
                {
                    Defines    = new string[0],
                    References = new ResponseFileData.Reference[0],
                    Unsafe     = false,
                    Errors     = new string[0]
                };

                return(empty);
            }

            var responseFileText = File.ReadAllText(responseFilePath);

            return(ParseResponseFileText(responseFileText));
        }
Exemplo n.º 5
0
        public static ResponseFileData ParseResponseFileFromFile(
            string responseFilePath,
            string projectDirectory,
            string[] systemReferenceDirectories)
        {
            responseFilePath = Paths.ConvertSeparatorsToUnity(responseFilePath);
            projectDirectory = Paths.ConvertSeparatorsToUnity(projectDirectory);

            var relativeResponseFilePath = GetRelativePath(responseFilePath, projectDirectory);
            var responseFile             = AssetDatabase.LoadAssetAtPath <TextAsset>(relativeResponseFilePath);

            if (!responseFile && File.Exists(responseFilePath))
            {
                var responseFileText = File.ReadAllText(responseFilePath);
                return(ParseResponseFileText(
                           responseFileText,
                           responseFilePath,
                           projectDirectory,
                           systemReferenceDirectories));
            }

            if (!responseFile)
            {
                var empty = new ResponseFileData
                {
                    Defines            = new string[0],
                    FullPathReferences = new string[0],
                    References         = new ResponseFileReference[0],
                    Unsafe             = false,
                    Errors             = new string[0],
                    OtherArguments     = new string[0],
                };

                return(empty);
            }

            return(ParseResponseFileText(
                       responseFile.text,
                       responseFile.name,
                       projectDirectory,
                       systemReferenceDirectories));
        }
        public static ResponseFileData ParseResponseFileFromFile(string responseFileName)
        {
            var relativeCustomResponseFilePath = Path.Combine("Assets", responseFileName);

            if (!File.Exists(relativeCustomResponseFilePath))
            {
                var empty = new ResponseFileData
                {
                    Defines    = new string[0],
                    References = new ResponseFileData.Reference[0],
                    Unsafe     = false,
                    Errors     = new string[0]
                };

                return(empty);
            }

            var responseFileText = File.ReadAllText(relativeCustomResponseFilePath);

            return(ParseResponseFileText(responseFileText));
        }
Exemplo n.º 7
0
        static ResponseFileData ParseResponseFileText(
            string fileContent,
            string fileName,
            string projectDirectory,
            string[] systemReferenceDirectories)
        {
            var compilerOptions = new List <CompilerOption>();

            var responseFileStrings = ResponseFileTextToStrings(fileContent);

            foreach (var line in responseFileStrings)
            {
                int    idx = line.IndexOf(':');
                string arg, value;

                if (idx == -1)
                {
                    arg   = line;
                    value = "";
                }
                else
                {
                    arg   = line.Substring(0, idx);
                    value = line.Substring(idx + 1);
                }

                if (!string.IsNullOrEmpty(arg) && arg[0] == '-')
                {
                    arg = '/' + arg.Substring(1);
                }

                compilerOptions.Add(new CompilerOption {
                    Arg = arg, Value = value
                });
            }

            var  responseArguments = new List <string>();
            var  defines           = new List <string>();
            var  references        = new List <string>();
            bool unsafeDefined     = false;
            var  errors            = new List <string>();

            foreach (var option in compilerOptions)
            {
                var arg   = option.Arg;
                var value = option.Value;

                switch (arg)
                {
                case "/d":
                case "/define":
                {
                    if (value.Length == 0)
                    {
                        errors.Add("No value set for define");
                        break;
                    }

                    var defs = value.Split(CompilerOptionArgumentSeperators);
                    foreach (string define in defs)
                    {
                        defines.Add(define.Trim());
                    }
                }
                break;

                case "/r":
                case "/reference":
                {
                    if (value.Length == 0)
                    {
                        errors.Add("No value set for reference");
                        break;
                    }

                    string[] refs = value.Split(CompilerOptionArgumentSeperators);

                    if (refs.Length != 1)
                    {
                        errors.Add("Cannot specify multiple aliases using single /reference option");
                        break;
                    }

                    var reference = refs[0];
                    if (reference.Length == 0)
                    {
                        continue;
                    }

                    int index             = reference.IndexOf('=');
                    var responseReference = index > -1 ? reference.Substring(index + 1) : reference;

                    var  fullPathReference = responseReference;
                    bool isRooted          = Path.IsPathRooted(responseReference);
                    if (!isRooted)
                    {
                        foreach (var directory in systemReferenceDirectories)
                        {
                            var systemReferencePath = Paths.Combine(directory, responseReference);
                            if (File.Exists(systemReferencePath))
                            {
                                fullPathReference = systemReferencePath;
                                isRooted          = true;
                                break;
                            }
                        }

                        var userPath = Paths.Combine(projectDirectory, responseReference);
                        if (File.Exists(userPath))
                        {
                            fullPathReference = userPath;
                            isRooted          = true;
                        }
                    }

                    if (!isRooted)
                    {
                        errors.Add($"{fileName}: not parsed correctly: {responseReference} could not be found as a system library.\n" +
                                   "If this was meant as a user reference please provide the relative path from project root (parent of the Assets folder) in the response file.");
                        continue;
                    }

                    responseReference = fullPathReference.Replace('\\', '/');
                    references.Add(responseReference);
                }
                break;

                case "/unsafe":
                case "/unsafe+":
                {
                    unsafeDefined = true;
                }
                break;

                case "/unsafe-":
                {
                    unsafeDefined = false;
                }
                break;

                default:
                    var valueWithColon = value.Length == 0 ? "" : ":" + value;
                    responseArguments.Add(arg + valueWithColon);
                    break;
                }
            }

            var responseFileData = new ResponseFileData
            {
                Defines            = defines.ToArray(),
                FullPathReferences = references.ToArray(),
                Unsafe             = unsafeDefined,
                Errors             = errors.ToArray(),
                OtherArguments     = responseArguments.ToArray(),
            };

            return(responseFileData);
        }
        public static ResponseFileData ParseResponseFileText(string responseFileText)
        {
            var compilerOptions = new List <CompilerOption>();

            var responseFileStrings = ResponseFileTextToStrings(responseFileText);

            foreach (var line in responseFileStrings)
            {
                int    idx = line.IndexOf(':');
                string arg, value;

                if (idx == -1)
                {
                    arg   = line;
                    value = "";
                }
                else
                {
                    arg   = line.Substring(0, idx);
                    value = line.Substring(idx + 1);
                }

                if (!string.IsNullOrEmpty(arg) && arg[0] == '-')
                {
                    arg = '/' + arg.Substring(1);
                }

                compilerOptions.Add(new CompilerOption {
                    Arg = arg, Value = value
                });
            }

            var  defines       = new List <string>();
            var  references    = new List <ResponseFileData.Reference>();
            bool unsafeDefined = false;
            var  errors        = new List <string>();

            foreach (var option in compilerOptions)
            {
                var arg   = option.Arg;
                var value = option.Value;

                switch (arg)
                {
                case "/d":
                case "/define":
                {
                    if (value.Length == 0)
                    {
                        errors.Add("No value set for define");
                        break;
                    }

                    var defs = value.Split(CompilerOptionArgumentSeperators);
                    foreach (string define in defs)
                    {
                        defines.Add(define.Trim());
                    }
                }
                break;

                case "/r":
                case "/reference":
                {
                    if (value.Length == 0)
                    {
                        errors.Add("No value set for reference");
                        break;
                    }

                    string[] refs = value.Split(CompilerOptionArgumentSeperators);

                    if (refs.Length != 1)
                    {
                        errors.Add("Cannot specify multiple aliases using single /reference option");
                        break;
                    }

                    foreach (string reference in refs)
                    {
                        if (reference.Length == 0)
                        {
                            continue;
                        }

                        int index = reference.IndexOf('=');
                        if (index > -1)
                        {
                            string alias    = reference.Substring(0, index);
                            string assembly = reference.Substring(index + 1);

                            references.Add(new ResponseFileData.Reference {
                                    Alias = alias, Assembly = assembly
                                });
                        }
                        else
                        {
                            references.Add(new ResponseFileData.Reference {
                                    Alias = string.Empty, Assembly = reference
                                });
                        }
                    }
                }
                break;

                case "/unsafe":
                case "/unsafe+":
                {
                    unsafeDefined = true;
                }
                break;

                case "/unsafe-":
                {
                    unsafeDefined = false;
                }
                break;
                }
            }

            var responseFileData = new ResponseFileData
            {
                Defines    = defines.ToArray(),
                References = references.ToArray(),
                Unsafe     = unsafeDefined,
                Errors     = errors.ToArray()
            };

            return(responseFileData);
        }