Add support for Solaris and illumos systems
Change-Id: I72406d16c0f15c909219a94dcf396e013a9501db
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/9560
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/build/gen.py b/build/gen.py
index 9353fb1..c4effa8 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -49,10 +49,12 @@
self._platform = 'openbsd'
elif self._platform.startswith('haiku'):
self._platform = 'haiku'
+ elif self._platform.startswith('sunos'):
+ self._platform = 'solaris'
@staticmethod
def known_platforms():
- return ['linux', 'darwin', 'mingw', 'msvc', 'aix', 'fuchsia', 'freebsd', 'openbsd', 'haiku']
+ return ['linux', 'darwin', 'mingw', 'msvc', 'aix', 'fuchsia', 'freebsd', 'openbsd', 'haiku', 'solaris']
def platform(self):
return self._platform
@@ -78,8 +80,11 @@
def is_haiku(self):
return self._platform == 'haiku'
+ def is_solaris(self):
+ return self._platform == 'solaris'
+
def is_posix(self):
- return self._platform in ['linux', 'freebsd', 'darwin', 'aix', 'openbsd', 'haiku']
+ return self._platform in ['linux', 'freebsd', 'darwin', 'aix', 'openbsd', 'haiku', 'solaris']
def main(argv):
@@ -203,6 +208,7 @@
'aix': 'build_aix.ninja.template',
'openbsd': 'build_openbsd.ninja.template',
'haiku': 'build_haiku.ninja.template',
+ 'solaris': 'build_linux.ninja.template',
}[platform.platform()])
with open(template_filename) as f:
@@ -318,7 +324,7 @@
ldflags.extend(['-fdata-sections', '-ffunction-sections'])
if platform.is_darwin():
ldflags.append('-Wl,-dead_strip')
- elif not platform.is_aix():
+ elif not platform.is_aix() and not platform.is_solaris():
# Garbage collection is done by default on aix.
ldflags.append('-Wl,--gc-sections')
@@ -328,6 +334,8 @@
ldflags.append('-Wl,-S')
elif platform.is_aix():
ldflags.append('-Wl,-s')
+ elif platform.is_solaris():
+ ldflags.append('-Wl,--strip-all')
else:
ldflags.append('-Wl,-strip-all')
diff --git a/src/gn/args.cc b/src/gn/args.cc
index 4d5a720..bba3eca 100644
--- a/src/gn/args.cc
+++ b/src/gn/args.cc
@@ -316,6 +316,8 @@
os = "openbsd";
#elif defined(OS_HAIKU)
os = "haiku";
+#elif defined(OS_SOLARIS)
+ os = "solaris";
#else
#error Unknown OS type.
#endif
diff --git a/src/gn/function_write_file_unittest.cc b/src/gn/function_write_file_unittest.cc
index 78eefc5..7113526 100644
--- a/src/gn/function_write_file_unittest.cc
+++ b/src/gn/function_write_file_unittest.cc
@@ -89,7 +89,7 @@
FILETIME last_modified_filetime = {};
ASSERT_TRUE(::SetFileTime(foo_file.GetPlatformFile(), nullptr,
&last_access_filetime, &last_modified_filetime));
-#elif defined(OS_AIX) || defined(OS_HAIKU)
+#elif defined(OS_AIX) || defined(OS_HAIKU) || defined(OS_SOLARIS)
struct timeval times[2] = {};
ASSERT_EQ(utimes(foo_name.value().c_str(), times), 0);
#else
diff --git a/src/util/exe_path.cc b/src/util/exe_path.cc
index 3b66a7b..0a91bcc 100644
--- a/src/util/exe_path.cc
+++ b/src/util/exe_path.cc
@@ -22,6 +22,8 @@
#elif defined(OS_HAIKU)
#include <OS.h>
#include <image.h>
+#elif defined(OS_SOLARIS)
+#include <stdlib.h>
#endif
#if defined(OS_MACOSX)
@@ -80,6 +82,16 @@
return base::FilePath(std::string(i_info.name));
}
+#elif defined(OS_SOLARIS)
+
+base::FilePath GetExePath() {
+ const char *raw = getexecname();
+ if (raw == NULL) {
+ return base::FilePath();
+ }
+ return base::FilePath(raw);
+}
+
#else
base::FilePath GetExePath() {
diff --git a/src/util/sys_info.cc b/src/util/sys_info.cc
index 5fefc9b..082d2d6 100644
--- a/src/util/sys_info.cc
+++ b/src/util/sys_info.cc
@@ -26,6 +26,11 @@
std::string arch(info.machine);
if (arch == "i386" || arch == "i486" || arch == "i586" || arch == "i686") {
arch = "x86";
+ } else if (arch == "i86pc") {
+ // Solaris and illumos systems report 'i86pc' (an Intel x86 PC) as their
+ // machine for both 32-bit and 64-bit x86 systems. Considering the rarity
+ // of 32-bit systems at this point, it is safe to assume 64-bit.
+ arch = "x86_64";
} else if (arch == "amd64") {
arch = "x86_64";
} else if (std::string(info.sysname) == "AIX") {