summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dan Willemsen <dwillemsen@google.com> 2025-01-17 04:09:14 -0500
committer Dan Willemsen <dwillemsen@google.com> 2025-01-17 04:52:39 -0500
commit144099f7c5a620111a61a7578d3cb4e742ed460b (patch)
tree55efc17f397604b05338d0aaa8389737633b384e
parent5e3937167e0b80a82cffa0579c672e011a649a3f (diff)
Fix releasetools device_specific error case
When the specified device_specific code isn't found, handle the error with a log statement rather than a NoneType exception. Fixes: 390497895 Test: treehugger Change-Id: Id5925f4e9ec9ae35d217823fc32f1ac7f06f1652
-rw-r--r--tools/releasetools/common.py2
-rw-r--r--tools/releasetools/test_common.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index e9cb5bb5fd..b6cbb15222 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -3138,6 +3138,8 @@ class DeviceSpecificParams(object):
if not os.path.exists(path) and os.path.exists(path + ".py"):
path = path + ".py"
spec = importlib.util.spec_from_file_location("device_specific", path)
+ if not spec:
+ raise FileNotFoundError(path)
logger.info("loaded device-specific extensions from %s", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
diff --git a/tools/releasetools/test_common.py b/tools/releasetools/test_common.py
index 89933a00fc..62f425ae6e 100644
--- a/tools/releasetools/test_common.py
+++ b/tools/releasetools/test_common.py
@@ -2157,3 +2157,11 @@ class PartitionBuildPropsTest(test_utils.ReleaseToolsTestCase):
'google/coral/coral:10/RP1A.200325.001/6337676:user/dev-keys',
'ro.product.odm.device': 'coral',
}, copied_props.build_props)
+
+
+class DeviceSpecificParamsTest(test_utils.ReleaseToolsTestCase):
+
+ def test_missingSource(self):
+ common.OPTIONS.device_specific = '/does_not_exist'
+ ds = DeviceSpecificParams()
+ self.assertIsNone(ds.module)