Files
mongo/buildscripts/utils.py

144 lines
4.4 KiB
Python
Raw Normal View History

"""Various utilities that are handy."""
2010-02-04 10:21:36 -05:00
2012-04-11 10:57:25 -04:00
import codecs
2010-02-04 10:21:36 -05:00
import re
import os
import os.path
import subprocess
import sys
2012-05-10 14:46:08 -04:00
2010-02-04 10:21:36 -05:00
def get_all_source_files(arr=None, prefix="."):
"""Return source files."""
2010-09-03 11:58:53 -04:00
if arr is None:
arr = []
if not os.path.isdir(prefix):
2012-10-15 02:37:46 -04:00
# assume a file
arr.append(prefix)
2012-10-15 02:37:46 -04:00
return arr
for fx in os.listdir(prefix):
# pylint: disable=too-many-boolean-expressions
if (fx.startswith(".") or fx.startswith("pcre-") or fx.startswith("32bit")
or fx.startswith("mongodb-") or fx.startswith("debian")
SERVER-44549 Remove the mobile storage engine mode change 100644 => 100755 buildscripts/evergreen_task_timeout.py delete mode 100644 buildscripts/resmokeconfig/suites/disk_mobile.yml delete mode 100644 src/mongo/db/storage/mobile/SConscript delete mode 100644 src/mongo/db/storage/mobile/mobile_index.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_index.h delete mode 100644 src/mongo/db/storage/mobile/mobile_index_test.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_init.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_kv_engine.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_kv_engine.h delete mode 100644 src/mongo/db/storage/mobile/mobile_kv_engine_test.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_options.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_options.h delete mode 100644 src/mongo/db/storage/mobile/mobile_options.idl delete mode 100644 src/mongo/db/storage/mobile/mobile_options_mongod.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_record_store.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_record_store.h delete mode 100644 src/mongo/db/storage/mobile/mobile_record_store_test.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_recovery_unit.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_recovery_unit.h delete mode 100644 src/mongo/db/storage/mobile/mobile_session.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_session.h delete mode 100644 src/mongo/db/storage/mobile/mobile_session_pool.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_session_pool.h delete mode 100644 src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_sqlite_statement.h delete mode 100644 src/mongo/db/storage/mobile/mobile_util.cpp delete mode 100644 src/mongo/db/storage/mobile/mobile_util.h delete mode 100755 src/third_party/scripts/sqlite_get_sources.sh delete mode 100644 src/third_party/shim_sqlite.cpp delete mode 100644 src/third_party/sqlite-amalgamation-3260000/SConscript delete mode 100644 src/third_party/sqlite-amalgamation-3260000/patches/gethostuuid.patch delete mode 100644 src/third_party/sqlite-amalgamation-3260000/sqlite/shell.c delete mode 100644 src/third_party/sqlite-amalgamation-3260000/sqlite/sqlite3.c delete mode 100644 src/third_party/sqlite-amalgamation-3260000/sqlite/sqlite3.h delete mode 100644 src/third_party/sqlite-amalgamation-3260000/sqlite/sqlite3ext.h
2020-02-02 11:05:31 -05:00
or fx.startswith("mongo-cxx-driver") or "gotools" in fx or fx.find("mozjs") != -1):
continue
# pylint: enable=too-many-boolean-expressions
def is_followable_dir(prefix, full):
"""Return True if 'full' is a followable directory."""
if not os.path.isdir(full):
return False
if not os.path.islink(full):
return True
# Follow softlinks in the modules directory (e.g: enterprise).
if os.path.split(prefix)[1] == "modules":
return True
return False
full = prefix + "/" + fx
if is_followable_dir(prefix, full):
get_all_source_files(arr, full)
2010-09-03 11:58:53 -04:00
else:
if full.endswith(".cpp") or full.endswith(".h") or full.endswith(".c"):
full = full.replace("//", "/")
arr.append(full)
2010-09-03 11:58:53 -04:00
return arr
def get_git_branch():
"""Return the git branch version."""
if not os.path.exists(".git") or not os.path.isdir(".git"):
2010-07-19 15:37:19 -04:00
return None
version = open(".git/HEAD", "r").read().strip()
if not version.startswith("ref: "):
2010-07-19 15:37:19 -04:00
return version
version = version.split("/")
version = version[len(version) - 1]
2010-07-19 15:37:19 -04:00
return version
def get_git_branch_string(prefix="", postfix=""):
"""Return the git branch name."""
tt = re.compile(r"[/\\]").split(os.getcwd())
if len(tt) > 2 and tt[len(tt) - 1] == "mongo":
par = tt[len(tt) - 2]
mt = re.compile(r".*_([vV]\d+\.\d+)$").match(par)
if mt is not None:
return prefix + mt.group(1).lower() + postfix
2010-07-19 15:37:19 -04:00
if par.find("Nightly") > 0:
return ""
branch = get_git_branch()
if branch is None or branch == "master":
2010-07-19 15:37:19 -04:00
return ""
return prefix + branch + postfix
2010-07-19 15:37:19 -04:00
def get_git_version():
"""Return the git version."""
if not os.path.exists(".git") or not os.path.isdir(".git"):
2010-07-19 15:37:19 -04:00
return "nogitversion"
version = open(".git/HEAD", "r").read().strip()
if not version.startswith("ref: "):
2010-07-19 15:37:19 -04:00
return version
version = version[5:]
git_ver = ".git/" + version
if not os.path.exists(git_ver):
2010-07-19 15:37:19 -04:00
return version
return open(git_ver, "r").read().strip()
2010-07-19 15:37:19 -04:00
def get_git_describe():
"""Return 'git describe --abbrev=7'."""
with open(os.devnull, "r+") as devnull:
proc = subprocess.Popen("git describe --abbrev=7", stdout=subprocess.PIPE, stderr=devnull,
stdin=devnull, shell=True)
2019-02-19 10:50:57 -05:00
return proc.communicate()[0].strip().decode('utf-8')
def execsys(args):
"""Execute a subprocess of 'args'."""
if isinstance(args, str):
rc = re.compile(r"\s+")
args = rc.split(args)
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
res = proc.communicate()
return res
2010-02-04 10:21:36 -05:00
2010-05-14 23:37:29 -04:00
def which(executable):
"""Return full path of 'executable'."""
if sys.platform == "win32":
paths = os.environ.get("Path", "").split(";")
else:
paths = os.environ.get("PATH", "").split(":")
for path in paths:
path = os.path.expandvars(path)
path = os.path.expanduser(path)
path = os.path.abspath(path)
executable_path = os.path.join(path, executable)
if os.path.exists(executable_path):
return executable_path
return executable
2012-05-10 14:46:08 -04:00
2012-04-11 10:57:25 -04:00
def replace_with_repr(unicode_error):
"""Codec error handler replacement."""
# Unicode is a pain, some strings cannot be unicode()'d
# but we want to just preserve the bytes in a human-readable
# fashion. This codec error handler will substitute the
# repr() of the offending bytes into the decoded string
# at the position they occurred
2012-04-11 10:57:25 -04:00
offender = unicode_error.object[unicode_error.start:unicode_error.end]
2019-02-19 10:50:57 -05:00
return (str(repr(offender).strip("'").strip('"')), unicode_error.end)
2012-04-11 10:57:25 -04:00
codecs.register_error("repr", replace_with_repr)