Merge changes I6080fa7f,I3c0477cf,I0beac6e7
* changes: update_crate_tests: Add init exceptions update_crate_tests: Use prebuilt bazel update_crate_tests: Use subprocess.DEVNULL
This commit is contained in:
@@ -35,50 +35,51 @@ exclude_paths = [
|
|||||||
"//external/vm_tools"
|
"//external/vm_tools"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UpdaterException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Env(object):
|
class Env(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
try:
|
try:
|
||||||
self.ANDROID_BUILD_TOP = os.environ['ANDROID_BUILD_TOP']
|
self.ANDROID_BUILD_TOP = os.environ['ANDROID_BUILD_TOP']
|
||||||
except:
|
except KeyError:
|
||||||
sys.exit('ERROR: this script must be run from an Android tree.')
|
raise UpdaterException('$ANDROID_BUILD_TOP is not defined; you '
|
||||||
|
'must first source build/envsetup.sh and '
|
||||||
|
'select a target.')
|
||||||
if path == None:
|
if path == None:
|
||||||
self.cwd = os.getcwd()
|
self.cwd = os.getcwd()
|
||||||
else:
|
else:
|
||||||
self.cwd = path
|
self.cwd = path
|
||||||
try:
|
try:
|
||||||
self.cwd_relative = self.cwd.split(self.ANDROID_BUILD_TOP)[1]
|
self.cwd_relative = self.cwd.split(self.ANDROID_BUILD_TOP)[1]
|
||||||
self.setup = True
|
except IndexError:
|
||||||
except:
|
raise UpdaterException('The path ' + self.cwd + ' is not under ' +
|
||||||
# Mark setup as failed if a path to a rust crate is not provided.
|
self.ANDROID_BUILD_TOP + '; You must be in the '
|
||||||
self.setup = False
|
'directory of a crate or pass its absolute path '
|
||||||
|
'as first argument.')
|
||||||
|
|
||||||
|
|
||||||
class Bazel(object):
|
class Bazel(object):
|
||||||
# set up the Bazel queryview
|
# set up the Bazel queryview
|
||||||
def __init__(self, env):
|
def __init__(self, env):
|
||||||
|
if platform.system() != 'Linux':
|
||||||
|
raise UpdaterException('This script has only been tested on Linux.')
|
||||||
|
self.path = os.path.join(env.ANDROID_BUILD_TOP, "tools", "bazel")
|
||||||
os.chdir(env.ANDROID_BUILD_TOP)
|
os.chdir(env.ANDROID_BUILD_TOP)
|
||||||
print("Building Bazel Queryview. This can take a couple of minutes...")
|
print("Building Bazel Queryview. This can take a couple of minutes...")
|
||||||
cmd = "./build/soong/soong_ui.bash --build-mode --all-modules --dir=. queryview"
|
cmd = "./build/soong/soong_ui.bash --build-mode --all-modules --dir=. queryview"
|
||||||
try:
|
try:
|
||||||
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||||
self.setup = True
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("Error: Unable to update TEST_MAPPING due to the following build error:")
|
raise UpdaterException('Unable to update TEST_MAPPING: ' + e.output)
|
||||||
print(e.output)
|
|
||||||
# Mark setup as failed if the Bazel queryview fails to build.
|
|
||||||
self.setup = False
|
|
||||||
os.chdir(env.cwd)
|
os.chdir(env.cwd)
|
||||||
|
|
||||||
def path(self):
|
|
||||||
# Only tested on Linux.
|
|
||||||
if platform.system() != 'Linux':
|
|
||||||
sys.exit('ERROR: this script has only been tested on Linux.')
|
|
||||||
return "/usr/bin/bazel"
|
|
||||||
|
|
||||||
# Return all modules for a given path.
|
# Return all modules for a given path.
|
||||||
def query_modules(self, path):
|
def query_modules(self, path):
|
||||||
with open(os.devnull, 'wb') as DEVNULL:
|
cmd = self.path + " query --config=queryview /" + path + ":all"
|
||||||
cmd = self.path() + " query --config=queryview /" + path + ":all"
|
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL, text=True).strip().split("\n")
|
||||||
out = subprocess.check_output(cmd, shell=True, stderr=DEVNULL, text=True).strip().split("\n")
|
|
||||||
modules = set()
|
modules = set()
|
||||||
for line in out:
|
for line in out:
|
||||||
# speed up by excluding unused modules.
|
# speed up by excluding unused modules.
|
||||||
@@ -89,10 +90,9 @@ class Bazel(object):
|
|||||||
|
|
||||||
# Return all reverse dependencies for a single module.
|
# Return all reverse dependencies for a single module.
|
||||||
def query_rdeps(self, module):
|
def query_rdeps(self, module):
|
||||||
with open(os.devnull, 'wb') as DEVNULL:
|
cmd = (self.path + " query --config=queryview \'rdeps(//..., " +
|
||||||
cmd = (self.path() + " query --config=queryview \'rdeps(//..., " +
|
|
||||||
module + ")\' --output=label_kind")
|
module + ")\' --output=label_kind")
|
||||||
out = (subprocess.check_output(cmd, shell=True, stderr=DEVNULL, text=True)
|
out = (subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL, text=True)
|
||||||
.strip().split("\n"))
|
.strip().split("\n"))
|
||||||
if '' in out:
|
if '' in out:
|
||||||
out.remove('')
|
out.remove('')
|
||||||
@@ -130,12 +130,7 @@ class TestMapping(object):
|
|||||||
self.env = Env(path)
|
self.env = Env(path)
|
||||||
self.bazel = Bazel(self.env)
|
self.bazel = Bazel(self.env)
|
||||||
|
|
||||||
def is_setup(self):
|
|
||||||
return self.env.setup and self.bazel.setup
|
|
||||||
|
|
||||||
def create_test_mapping(self, path):
|
def create_test_mapping(self, path):
|
||||||
if not self.is_setup():
|
|
||||||
return
|
|
||||||
tests = self.get_tests(path)
|
tests = self.get_tests(path)
|
||||||
if not bool(tests):
|
if not bool(tests):
|
||||||
return
|
return
|
||||||
@@ -173,10 +168,11 @@ def main():
|
|||||||
path = sys.argv[1]
|
path = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
path = None
|
path = None
|
||||||
|
try:
|
||||||
test_mapping = TestMapping(path)
|
test_mapping = TestMapping(path)
|
||||||
|
except UpdaterException as err:
|
||||||
|
sys.exit("Error: " + str(err))
|
||||||
test_mapping.create_test_mapping(None)
|
test_mapping.create_test_mapping(None)
|
||||||
if not test_mapping.is_setup():
|
|
||||||
raise ValueError('Error getting crate tests.')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user