// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System.Diagnostics; using Flax.Build.Projects; namespace Flax.Build.Platforms { /// /// The build platform for all Unix-like systems. /// /// public abstract class UnixPlatform : Platform { /// public override string ExecutableFileExtension => string.Empty; /// public override string SharedLibraryFileExtension => ".so"; /// public override string StaticLibraryFileExtension => ".a"; /// public override string ProgramDatabaseFileExtension => string.Empty; /// public override string SharedLibraryFilePrefix => "lib"; /// public override string StaticLibraryFilePrefix => "lib"; /// public override ProjectFormat DefaultProjectFormat => ProjectFormat.VisualStudioCode; /// /// Initializes a new instance of the class. /// protected UnixPlatform() { } /// /// Uses which command to find the given file. /// /// The name of the file to find. /// The full path or null if not found anything valid. public static string Which(string name) { if (string.IsNullOrEmpty(name)) return null; Process proc = new Process { StartInfo = { FileName = "/bin/sh", ArgumentList = { "-c", $"which {name}" }, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true } }; proc.Start(); proc.WaitForExit(); string path = proc.StandardOutput.ReadLine(); Log.Verbose(string.Format("which {0} exit code: {1}, result: {2}", name, proc.ExitCode, path)); if (proc.ExitCode == 0) { string err = proc.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(err)) Log.Verbose(string.Format("which stderr: {0}", err)); return path; } return null; } } }