Example #1
0
        public override bool Execute()
        {
            Logger.Instance = new XBuildLogProvider(Log); // TODO: maybe initialise statically; this put in constructor causes NRE

            if (!ObjectFiles.Any())
            {
                return(true);
            }

            var lfiles = new List <string>();
            var ofiles = ObjectFiles.Select(x => x.ItemSpec);

            if (String.IsNullOrEmpty(GCCToolLinkerPath))
            {
                GCCToolLinkerPath = "";
            }
            GCCToolLinkerPathCombined = GCCToolLinkerPath;

            shellApp = new ShellAppConversion(GCCBuild_SubSystem, GCCBuild_ShellApp, GCCBuild_PreRunApp,
                                              GCCBuild_ConvertPath, GCCBuild_ConvertPath_mntFolder, IntPath);

            if (OS.Equals("Windows_NT") && String.IsNullOrWhiteSpace(shellApp.shellapp))
            {
                GCCToolLinkerPathCombined = Utilities.FixAppPath(GCCToolLinkerPathCombined, GCCToolLinkerExe);
            }
            else
            {
                GCCToolLinkerPathCombined = Path.Combine(GCCToolLinkerPath, GCCToolLinkerExe);
            }

            string OutputFile_Converted = OutputFile;

            if (shellApp.convertpath)
            {
                OutputFile_Converted = shellApp.ConvertWinPathToWSL(OutputFile);
            }

            else if (!Directory.Exists(Path.GetDirectoryName(OutputFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
            }


            // linking
            Dictionary <string, string> Flag_overrides = new Dictionary <string, string>();

            Flag_overrides.Add("OutputFile", OutputFile_Converted);

            var flags = Utilities.GetConvertedFlags(GCCToolLinker_Flags, GCCToolLinker_AllFlags, ObjectFiles[0], Flag_overrides, shellApp);

            Logger.Instance.LogCommandLine($"{GCCToolLinkerPathCombined} {flags}");

            using (var runWrapper = new RunWrapper(GCCToolLinkerPathCombined, flags, shellApp, GCCToolSupportsResponsefile))
            {
                bool result = runWrapper.RunLinker(String.IsNullOrEmpty(ObjectFiles[0].GetMetadata("SuppressStartupBanner")) || ObjectFiles[0].GetMetadata("SuppressStartupBanner").Equals("true") ? false : true);
                if (result)
                {
                    string allofiles = String.Join(",", ofiles);
                    if (allofiles.Length > 100)
                    {
                        allofiles = allofiles.Substring(0, 100) + "...";
                    }
                    Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted}");
                }

                return(result);
            }
        }