aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-03-29 14:24:17 +0000
committerEgor Tensin <Egor.Tensin@gmail.com>2020-03-29 14:24:17 +0000
commit5807ec7bc875d678f2e9502259d62d83b858a854 (patch)
tree0e6e1f92777230d94c627ef9208de24d84b4558a /project
parentclang-format.py: fix timestamps in logs (diff)
downloadcmake-common-5807ec7bc875d678f2e9502259d62d83b858a854.tar.gz
cmake-common-5807ec7bc875d678f2e9502259d62d83b858a854.zip
project: add os.py
Diffstat (limited to 'project')
-rw-r--r--project/boost/build.py3
-rw-r--r--project/boost/directory.py3
-rw-r--r--project/cmake/build.py5
-rw-r--r--project/os.py36
-rw-r--r--project/utils.py9
5 files changed, 44 insertions, 12 deletions
diff --git a/project/boost/build.py b/project/boost/build.py
index 82180a5..a33a538 100644
--- a/project/boost/build.py
+++ b/project/boost/build.py
@@ -25,6 +25,7 @@ from project.boost.directory import BoostDir
from project.configuration import Configuration
from project.linkage import Linkage
from project.platform import Platform
+from project.os import on_linux_like
import project.utils
@@ -81,7 +82,7 @@ class BuildParameters:
if link is Linkage.SHARED:
logging.warning("Cannot link the runtime statically to a dynamic library, going to link dynamically")
runtime_link = Linkage.SHARED
- elif project.utils.on_linux():
+ elif on_linux_like():
logging.warning("Cannot link to the GNU C Library (which is assumed) statically, going to link dynamically")
runtime_link = Linkage.SHARED
yield link, runtime_link
diff --git a/project/boost/directory.py b/project/boost/directory.py
index e50041f..17448b6 100644
--- a/project/boost/directory.py
+++ b/project/boost/directory.py
@@ -6,7 +6,8 @@
import logging
import os.path
-from project.utils import cd, run, on_windows
+from project.utils import cd, run
+from project.os import on_windows
class BoostDir:
diff --git a/project/cmake/build.py b/project/cmake/build.py
index b15badd..5355c0b 100644
--- a/project/cmake/build.py
+++ b/project/cmake/build.py
@@ -151,9 +151,12 @@ def _parse_args(argv=None):
parser.add_argument('--install', metavar='DIR', dest='install_dir',
type=project.utils.normalize_path,
help='install directory')
+
+ configuration_options = '/'.join(map(str, Configuration.all()))
parser.add_argument('--configuration', metavar='CONFIG',
type=Configuration.parse, default=Configuration.DEBUG,
- help=f'build configuration ({"/".join(map(str, Configuration))})')
+ help=f'build configuration ({configuration_options})')
+
parser.add_argument('src_dir', metavar='DIR',
type=project.utils.normalize_path,
help='source directory')
diff --git a/project/os.py b/project/os.py
new file mode 100644
index 0000000..86ccaad
--- /dev/null
+++ b/project/os.py
@@ -0,0 +1,36 @@
+# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "cmake-common" project.
+# For details, see https://github.com/egor-tensin/cmake-common.
+# Distributed under the MIT License.
+
+from enum import Enum
+import platform
+
+
+class OS(Enum):
+ WINDOWS = 'Windows'
+ LINUX = 'Linux'
+ CYGWIN = 'Cygwin'
+
+ def __str__(self):
+ return self.value
+
+ @staticmethod
+ def current():
+ system = platform.system()
+ if system == 'Windows':
+ return OS.WINDOWS
+ if system == 'Linux':
+ return OS.LINUX
+ if system.startswith('CYGWIN_NT'):
+ return OS.CYGWIN
+ raise NotImplementedError(f'unsupported OS: {system}')
+
+
+def on_windows():
+ return OS.current() is OS.WINDOWS
+
+
+def on_linux_like():
+ os = OS.current()
+ return os is OS.LINUX or os is OS.CYGWIN
diff --git a/project/utils.py b/project/utils.py
index 9d986b0..8c57f59 100644
--- a/project/utils.py
+++ b/project/utils.py
@@ -6,7 +6,6 @@
from contextlib import contextmanager
import logging
import os.path
-import platform
import subprocess
@@ -44,11 +43,3 @@ def run(cmd_line):
def run_cmake(cmake_args):
return run(['cmake'] + cmake_args)
-
-
-def on_windows():
- return platform.system() == 'Windows'
-
-
-def on_linux():
- return not on_windows()