Esempio n. 1
0
        /// <summary>
        /// Generates wrapper for specified ABC/SWC file.
        /// </summary>
        /// <param name="path">path to ABC file</param>
        /// <param name="outpath">output path. Can be null.</param>
        /// <param name="format">options</param>
        public static void Generate(string path, string outpath, string format)
        {
            if (!Path.IsPathRooted(path))
            {
                path = Path.Combine(Environment.CurrentDirectory, path);
            }

            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                throw new ArgumentException("Input path is invalid");
            }

            var cl = CommandLine.Parse(format) ?? new CommandLine();

            var asm = BuildAssembly(path, cl);

            if (string.IsNullOrEmpty(outpath))
            {
                outpath = Path.ChangeExtension(path, ".dll");
            }
            else if (!Path.IsPathRooted(outpath))
            {
                outpath = Path.Combine(Environment.CurrentDirectory, outpath);
            }

            asm.Name = Path.GetFileName(outpath);

            var copts = new CompilerOptions();

            bool srconly = cl.GetBoolOption(false, "srconly");

            var refs = GlobalSettings.GetRefs(cl);

            bool hasCorlibRef = GlobalSettings.HasCorlibRef(refs);

            string srcdir = cl.GetOption(null, "dir");

            if (string.IsNullOrEmpty(srcdir))
            {
                srcdir = Path.GetFileName(path) + "_src";
            }

            if (!Path.IsPathRooted(srcdir))
            {
                srcdir = Path.Combine(Environment.CurrentDirectory, srcdir);
            }

            ExportService.ToDirectory(asm, "c#", srcdir);
            copts.Recurse.Add(srcdir + "\\*.cs");

            if (!hasCorlibRef)
            {
                CopyAbcAttributes(srcdir);
            }

            if (!srconly)
            {
                copts.AddRes(path);

                if (path.EndsWith(".swc", StringComparison.InvariantCultureIgnoreCase))
                {
                    string swcdep = Path.ChangeExtension(path, ".swcdep");
                    if (File.Exists(swcdep))
                    {
                        copts.AddRes(swcdep);
                    }
                }

                copts.Optimize = true;
                copts.Debug    = true;

                if (hasCorlibRef)
                {
                    copts.NoConfig = true;
                    copts.NoStdlib = true;
                }

                copts.AddRefs(refs);

                copts.Output = outpath;
                copts.Target = CompilerTarget.Library;

                if (!cl.HasOption("nocsc"))
                {
                    Compile(copts, path);
                }
            }
        }