Ejemplo n.º 1
0
        /// <summary>
        /// <c>dotnet-compile-php</c> entry point.
        /// </summary>
        /// <param name="args">Arguments passed from <c>dotnet build</c>.</param>
        public static int Main(string[] args)
        {
            var rspfile = CreateRspFile(args);

            // compile
            return(PhpCompilerDriver.Run(PhpCommandLineParser.Default, null, new[] { "@" + rspfile }, null, Directory.GetCurrentDirectory(), null, null, new SimpleAnalyzerAssemblyLoader(), Console.Out));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <c>dotnet-compile-php</c> entry point.
        /// </summary>
        /// <param name="args">Arguments passed from <c>dotnet build</c>.</param>
        public static int Main(string[] args)
        {
            args = ProcessArguments(args);

            // compile
            return(PhpCompilerDriver.Run(PhpCommandLineParser.Default, null, args, null, Directory.GetCurrentDirectory(), null, null, new SimpleAnalyzerAssemblyLoader(), Console.Out));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <c>dotnet-compile-php</c> entry point.
        /// </summary>
        /// <param name="args">Arguments passed from <c>dotnet build</c>.</param>
        public static int Main(string[] args)
        {
            string rspfile = CreateRspFile(args, out string sdkdir);

            string libs = Environment.GetEnvironmentVariable("LIB") + @";C:\Windows\Microsoft.NET\assembly\GAC_MSIL";

            // compile
            return(PhpCompilerDriver.Run(PhpCommandLineParser.Default, null, new[] { "@" + rspfile }, null, System.IO.Directory.GetCurrentDirectory(), sdkdir, libs, new SimpleAnalyzerAssemblyLoader(), Console.Out));
        }
Ejemplo n.º 4
0
        public static int Main(string[] args)
        {
            // /basedir:
            string basedir = args.FirstOrDefault(x => x.StartsWith(BasedirOption));

            if (basedir != null)
            {
                basedir = basedir.Substring(BasedirOption.Length);
            }

            // compile
            return(PhpCompilerDriver.Run(PhpCommandLineParser.Default, null, args, null, basedir, null, null, new SimpleAnalyzerAssemblyLoader(), TextWriter.Null));
        }
Ejemplo n.º 5
0
        /// <summary></summary>
        public override bool Execute()
        {
            _cancellation = new CancellationTokenSource();

            // initiate our assembly resolver within MSBuild process:
            AssemblyResolver.InitializeSafe();

            if (IsCanceled())
            {
                return(false);
            }

            //
            // compose compiler arguments:
            var args = new List <string>(1024)
            {
                "/output-name:" + OutputName,
                "/target:" + (EmitEntryPoint ? "exe" : "library"),
                Optimize ? "/o+" : "/o-",
            };

            if (HasDebugPlus)
            {
                args.Add("/debug+");
            }

            if (ShortOpenTags)
            {
                args.Add("/shortopentag+");
            }

            if (string.Equals(PublicSign, "true", StringComparison.OrdinalIgnoreCase))
            {
                args.Add("/publicsign+");
            }
            else if (string.Equals(PublicSign, "false", StringComparison.OrdinalIgnoreCase))
            {
                args.Add("/publicsign-");
            }

            AddNoEmpty(args, "target-framework", TargetFramework);
            AddNoEmpty(args, "temp-output", TempOutputPath);
            AddNoEmpty(args, "out", OutputPath);
            AddNoEmpty(args, "m", EntryPoint);
            AddNoEmpty(args, "pdb", PdbFile);
            AddNoEmpty(args, "debug-type", DebugType);// => emitPdb = true
            AddNoEmpty(args, "keyfile", KeyFile);
            AddNoEmpty(args, "xmldoc", DocumentationFile);
            AddNoEmpty(args, "langversion", LangVersion);
            AddNoEmpty(args, "v", Version);
            AddNoEmpty(args, "nowarn", NoWarn);
            AddNoEmpty(args, "phpdoctypes", PhpDocTypes);
            AddNoEmpty(args, "sourcelink", SourceLink);
            AddNoEmpty(args, "codepage", CodePage);
            AddNoEmpty(args, "subdir", PhpRelativePath);
            AddNoEmpty(args, "logger", "Peachpie.Compiler.Diagnostics.Observer,Peachpie.Compiler.Diagnostics");

            if (DefineConstants != null)
            {
                foreach (var d in DefineConstants)
                {
                    args.Add("/d:" + d);
                }
            }

            if (ReferencePath != null && ReferencePath.Length != 0)
            {
                foreach (var r in ReferencePath)

                {
                    args.Add("/r:" + r);
                }
            }
            else
            {
                Log.LogWarning("No references specified.");
            }

            if (Resources != null)
            {
                foreach (var res in Resources)
                {
                    args.Add(FormatArgFromItem(res, "res", "LogicalName", "Access"));
                }
            }

            // sources at the end:
            if (Compile != null)
            {
                foreach (var s in Compile)
                {
                    args.Add(s);
                }
            }

            //
            // save the arguments as .rsp file for debugging purposes:
            try
            {
                File.WriteAllText(Path.Combine(TempOutputPath, "dotnet-php.rsp"), string.Join(Environment.NewLine, args));
            }
            catch (Exception ex)
            {
                this.Log.LogWarningFromException(ex);
            }

            //
            // run the compiler:
            string libs = Environment.GetEnvironmentVariable("LIB") + @";C:\Windows\Microsoft.NET\assembly\GAC_MSIL";

            if (IsCanceled())
            {
                return(false);
            }

            // compile
            try
            {
                var resultCode = PhpCompilerDriver.Run(
                    PhpCommandLineParser.Default,
                    null,
                    args: args.ToArray(),
                    clientDirectory: null,
                    baseDirectory: Directory.GetCurrentDirectory(),
                    sdkDirectory: NetFrameworkPath,
                    additionalReferenceDirectories: libs,
                    analyzerLoader: new SimpleAnalyzerAssemblyLoader(),
                    output: new LogWriter(this.Log),
                    cancellationToken: _cancellation.Token);

                return(resultCode == 0);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary></summary>
        public override bool Execute()
        {
            _cancellation = new CancellationTokenSource();

            // initiate our assembly resolver within MSBuild process:
            AssemblyResolver.InitializeSafe();

            if (IsCanceled())
            {
                return(false);
            }

            //
            // compose compiler arguments:
            var args = new List <string>(1024)
            {
                "/output-name:" + OutputName,
                "/target:" + (string.IsNullOrEmpty(OutputType) ? "library" : OutputType),
                "/o:" + Optimization,
                "/fullpaths:" + GenerateFullPaths.ToString(),
            };

            if (HasDebugPlus)
            {
                args.Add("/debug+");
            }

            if (ShortOpenTags)
            {
                args.Add("/shortopentag+");
            }

            if (string.Equals(PublicSign, "true", StringComparison.OrdinalIgnoreCase))
            {
                args.Add("/publicsign+");
            }
            else if (string.Equals(PublicSign, "false", StringComparison.OrdinalIgnoreCase))
            {
                args.Add("/publicsign-");
            }

            AddNoEmpty(args, "target-framework", TargetFramework);
            AddNoEmpty(args, "temp-output", TempOutputPath);
            AddNoEmpty(args, "out", OutputPath);
            AddNoEmpty(args, "m", EntryPoint);
            AddNoEmpty(args, "pdb", PdbFile);
            AddNoEmpty(args, "debug-type", DebugType);// => emitPdb = true
            AddNoEmpty(args, "keyfile", KeyFile);
            AddNoEmpty(args, "xmldoc", DocumentationFile);
            AddNoEmpty(args, "langversion", LangVersion);
            AddNoEmpty(args, "v", Version);
            AddNoEmpty(args, "nowarn", NoWarn);
            AddNoEmpty(args, "phpdoctypes", PhpDocTypes);
            AddNoEmpty(args, "sourcelink", SourceLink);
            AddNoEmpty(args, "codepage", CodePage);
            AddNoEmpty(args, "subdir", PhpRelativePath);

            if (DefineConstants != null)
            {
                foreach (var d in DefineConstants)
                {
                    args.Add("/d:" + d);
                }
            }

            if (ReferencePath != null && ReferencePath.Length != 0)
            {
                foreach (var r in ReferencePath)

                {
                    args.Add("/r:" + r);
                }
            }
            else
            {
                Log.LogWarning("No references specified.");
            }

            if (Resources != null)
            {
                foreach (var res in Resources)
                {
                    args.Add(FormatArgFromItem(res, "res", "LogicalName", "Access"));
                }
            }

            if (Autoload_PSR4 != null)
            {
                foreach (var psr4map in Autoload_PSR4)
                {
                    //args.Add(FormatArgFromItem(psr4map, "autoload", "Prefix", "Path")); // Prefix can be empty!
                    args.Add($"/autoload:psr-4,{psr4map.GetMetadata("Prefix")},{psr4map.GetMetadata("Path")}");
                }
            }

            if (Autoload_ClassMap != null)
            {
                foreach (var fname in Autoload_ClassMap.Distinct())
                {
                    args.Add("/autoload:classmap," + fname);
                }
            }

            if (Autoload_Files != null)
            {
                foreach (var fname in Autoload_Files.Distinct())
                {
                    args.Add("/autoload:files," + fname);
                }
            }

            if (string.IsNullOrWhiteSpace(BasePath))
            {
                BasePath = Directory.GetCurrentDirectory();
            }

            if (!Directory.Exists(BasePath))
            {
                this.Log.LogWarning("Specified base directory '{0}' does not exist.", BasePath);
            }

            // sources at the end:
            if (Compile != null)
            {
                foreach (var s in Compile)
                {
                    args.Add(s);
                }
            }

#if DEBUG
            // save the arguments as .rsp file for debugging purposes:
            try
            {
                File.WriteAllText(Path.Combine(TempOutputPath, "dotnet-php.rsp"), string.Join(Environment.NewLine, args));
            }
            catch (Exception ex)
            {
                this.Log.LogWarningFromException(ex);
            }
#endif

            //
            // run the compiler:
            string libs = Environment.GetEnvironmentVariable("LIB") + @";C:\Windows\Microsoft.NET\assembly\GAC_MSIL";

            if (IsCanceled())
            {
                return(false);
            }

            // Debugger.Launch
            if (DebuggerAttach)
            {
                Debugger.Launch();
            }

            // compile
            try
            {
                var resultCode = PhpCompilerDriver.Run(
                    PhpCommandLineParser.Default,
                    null,
                    args: args.ToArray(),
                    clientDirectory: null,
                    baseDirectory: BasePath,
                    sdkDirectory: NetFrameworkPath,
                    additionalReferenceDirectories: libs,
                    analyzerLoader: new SimpleAnalyzerAssemblyLoader(),
                    output: new LogWriter(this.Log),
                    cancellationToken: _cancellation.Token);

                return(resultCode == 0);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }
        }