Ejemplo n.º 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);
            var flags  = (Flags != null && Flags.Any()) ? Flags.Select(x => x.ItemSpec).ToList() : new List <string>();

            if (Libraries != null)
            {
                foreach (var library in Libraries.Select(x => x.ItemSpec))
                {
                    if (File.Exists(library))
                    {
                        var directory = Path.GetDirectoryName(library);
                        var fileName  = Path.GetFileName(library);

                        lfiles.Add(library);
                        flags.Add(string.Format(" -L{0} -l:{1}", directory, fileName));
                    }
                    else
                    {
                        flags.Add(string.Format("-l{0}", library));
                    }
                }
            }

            var joinedFlags = string.Join(" ", flags);

            using (var cache = new FileCacheManager(Path.GetDirectoryName(Output)))
            {
                if (!cache.SourceHasChanged(ofiles.Union(lfiles), joinedFlags) && File.Exists(Output))
                {
                    return(true);
                }
            }

            // linking
            var linker = new GLD(string.IsNullOrEmpty(LinkerPath) ? DefaultLinker : LinkerPath);

            return(linker.Link(ofiles, Output, joinedFlags));
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            if (String.IsNullOrEmpty(GCCBuild_ShellApp))
            {
                GCCBuild_ConvertPath = false;
            }
            if (!GCCBuild_ConvertPath)
            {
                GCCBuild_ShellApp = null;
            }
            if (!ObjectFiles.Any())
            {
                return(true);
            }



            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(GCCToolArchiverPath))
            {
                GCCToolArchiverPath = "";
            }

            string GCCToolArchiverCombined = GCCToolArchiverPath;

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

            if (OS.Equals("Windows_NT") && String.IsNullOrWhiteSpace(shellApp.shellapp))
            {
                GCCToolArchiverCombined = Utilities.FixAppPath(GCCToolArchiverCombined, GCCToolArchiverExe);
            }
            else
            {
                GCCToolArchiverCombined = Path.Combine(GCCToolArchiverPath, GCCToolArchiverExe);
            }

            string OutputFile_Converted = OutputFile;

            if (shellApp.convertpath)
            {
                OutputFile_Converted = shellApp.ConvertWinPathToWSL(OutputFile);
            }
            else if (!Directory.Exists(Path.GetDirectoryName(OutputFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
            }


            // archiving - librerian
            Dictionary <string, string> Flag_overrides = new Dictionary <string, string>();

            Flag_overrides.Add("OutputFile", OutputFile_Converted);

            bool needRearchive = true;

            if (File.Exists(OutputFile))
            {
                needRearchive = false;
                FileInfo libInfo = fileinfoDict.GetOrAdd(OutputFile, (x) => new FileInfo(x));
                foreach (var obj in ObjectFiles.Select(x => x.ItemSpec).Concat(new string[] { ProjectFile }))
                {
                    string depfile = obj;

                    if (shellApp.convertpath)
                    {
                        depfile = shellApp.ConvertWSLPathToWin(obj);//here convert back to Windows path
                    }
                    FileInfo fi = fileinfoDict.GetOrAdd(depfile, (x) => new FileInfo(x));
                    if (fi.Exists == false || fi.Attributes == FileAttributes.Directory || fi.Attributes == FileAttributes.Device)
                    {
                        continue;
                    }
                    if (fi.LastWriteTime > libInfo.LastWriteTime)
                    {
                        needRearchive = true;
                        break;
                    }
                }
            }

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

            using (var runWrapper = new RunWrapper(GCCToolArchiverCombined, flags, shellApp, GCCToolSupportsResponsefile))
            {
                bool result = true;
                if (needRearchive)
                {
                    TryDeleteFile(OutputFile);
                    Logger.Instance.LogCommandLine($"{GCCToolArchiverCombined} {flags}");
                    result = runWrapper.RunArchiver(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) + "...";
                    }
                    if (needRearchive)
                    {
                        Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted}");
                    }
                    else
                    {
                        Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted} (not archive - already up to date)");
                    }
                }

                return(result);
            }
        }
Ejemplo n.º 3
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);
            var flags  = (Flags != null && Flags.Any()) ? Flags.Select(x => x.ItemSpec).ToList() : new List <string>();

            if (Libraries != null)
            {
                foreach (var library in Libraries.Select(x => x.ItemSpec))
                {
                    if (File.Exists(library))
                    {
                        var directory = Path.GetDirectoryName(library);
                        var fileName  = Path.GetFileName(library);

                        lfiles.Add(library);
                        flags.Add(string.Format(" -L{0} -l:{1}", directory, fileName));
                    }
                    else
                    {
                        flags.Add(string.Format("-l{0}", library));
                    }
                }
            }

            var joinedFlags = string.Join(" ", flags);

            using (var cache = new FileCacheManager(Path.GetDirectoryName(Output)))
            {
                if (!cache.SourceHasChanged(ofiles.Union(lfiles), joinedFlags) && File.Exists(Output))
                {
                    return(true);
                }
            }

            // linking
            var linkerPath = string.IsNullOrEmpty(LinkerPath) ? DefaultLinker : LinkerPath;
            var linker     = new GLD(linkerPath);

            try
            {
                return(linker.Link(ofiles, Output, joinedFlags));
            }
            catch (Exception e)
            {
                if (e is Win32Exception error)
                {
                    if (error.NativeErrorCode == Utilities.ErrorFileNotFound)
                    {
                        Logger.Instance.LogError($"Could not find \"{LinkerPath}\" linker.");
                    }
                    else
                    {
                        Logger.Instance.LogError($"An error was encountered while trying to run \"{LinkerPath}\" linker: {e.Message}.");
                    }
                }
                else
                {
                    Logger.Instance.LogError($"An unknown exception has been thrown in CLinkerTask. Message: { e.Message }.");
                }
                return(false);
            }
        }
Ejemplo n.º 4
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);
            }
        }