mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
3c5295f83b
Summary: Add a ContextGenerator class so that we actually use the correct per-project context when loading projects and computing dependencies. Previously commands like `build` and `test` would change the contexts for each project as they iterated through and performed the build. However, they did not do this when first loading the projects. This could cause them to use different context values when loading dependencies than when performing the build. For instance, this could cause issues if a project depends on `googletest` only when testing is enabled, as the code previously did not set the "test" parameter when evaluating dependencies. Reviewed By: pkaush Differential Revision: D16477396 fbshipit-source-id: c1e055f07de1cb960861d19594e3bda20a2ccd87
99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
# Copyright (c) 2019-present, Facebook, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
import re
|
|
import shlex
|
|
import sys
|
|
|
|
|
|
def is_windows():
|
|
""" Returns true if the system we are currently running on
|
|
is a Windows system """
|
|
return sys.platform.startswith("win")
|
|
|
|
|
|
def get_linux_type():
|
|
try:
|
|
with open("/etc/os-release") as f:
|
|
data = f.read()
|
|
except EnvironmentError:
|
|
return (None, None)
|
|
|
|
os_vars = {}
|
|
for line in data.splitlines():
|
|
parts = line.split("=", 1)
|
|
if len(parts) != 2:
|
|
continue
|
|
key = parts[0].strip()
|
|
value_parts = shlex.split(parts[1].strip())
|
|
if not value_parts:
|
|
value = ""
|
|
else:
|
|
value = value_parts[0]
|
|
os_vars[key] = value
|
|
|
|
name = os_vars.get("NAME")
|
|
if name:
|
|
name = name.lower()
|
|
name = re.sub("linux", "", name)
|
|
name = name.strip()
|
|
|
|
return "linux", name, os_vars.get("VERSION_ID").lower()
|
|
|
|
|
|
class HostType(object):
|
|
def __init__(self, ostype=None, distro=None, distrovers=None):
|
|
if ostype is None:
|
|
distro = None
|
|
distrovers = None
|
|
if sys.platform.startswith("linux"):
|
|
ostype, distro, distrovers = get_linux_type()
|
|
elif sys.platform.startswith("darwin"):
|
|
ostype = "darwin"
|
|
elif is_windows():
|
|
ostype = "windows"
|
|
distrovers = str(sys.getwindowsversion().major)
|
|
else:
|
|
ostype = sys.platform
|
|
|
|
# The operating system type
|
|
self.ostype = ostype
|
|
# The distribution, if applicable
|
|
self.distro = distro
|
|
# The OS/distro version if known
|
|
self.distrovers = distrovers
|
|
|
|
def is_windows(self):
|
|
return self.ostype == "windows"
|
|
|
|
def is_darwin(self):
|
|
return self.ostype == "darwin"
|
|
|
|
def is_linux(self):
|
|
return self.ostype == "linux"
|
|
|
|
def as_tuple_string(self):
|
|
return "%s-%s-%s" % (
|
|
self.ostype,
|
|
self.distro or "none",
|
|
self.distrovers or "none",
|
|
)
|
|
|
|
@staticmethod
|
|
def from_tuple_string(s):
|
|
ostype, distro, distrovers = s.split("-")
|
|
return HostType(ostype=ostype, distro=distro, distrovers=distrovers)
|
|
|
|
def __eq__(self, b):
|
|
return (
|
|
self.ostype == b.ostype
|
|
and self.distro == b.distro
|
|
and self.distrovers == b.distrovers
|
|
)
|