| Conley Owens | 094cdbe | 2014-01-30 15:09:59 -0800 | [diff] [blame] | 1 | # Copyright (C) 2014 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| Mike Frysinger | 0ab6b11 | 2022-12-08 01:46:45 -0500 | [diff] [blame] | 15 | import functools |
| Daniel Kutik | 50a2c0e | 2022-11-25 13:32:05 +0100 | [diff] [blame] | 16 | import importlib.machinery |
| 17 | import importlib.util |
| Conley Owens | 094cdbe | 2014-01-30 15:09:59 -0800 | [diff] [blame] | 18 | import os |
| 19 | |
| 20 | |
| Mike Frysinger | 4406642 | 2024-03-21 12:58:01 -0400 | [diff] [blame] | 21 | def WrapperDir(): |
| 22 | return os.path.dirname(__file__) |
| 23 | |
| 24 | |
| Conley Owens | 094cdbe | 2014-01-30 15:09:59 -0800 | [diff] [blame] | 25 | def WrapperPath(): |
| Mike Frysinger | 4406642 | 2024-03-21 12:58:01 -0400 | [diff] [blame] | 26 | return os.path.join(WrapperDir(), "repo") |
| Conley Owens | 094cdbe | 2014-01-30 15:09:59 -0800 | [diff] [blame] | 27 | |
| David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 28 | |
| Mike Frysinger | 0ab6b11 | 2022-12-08 01:46:45 -0500 | [diff] [blame] | 29 | @functools.lru_cache(maxsize=None) |
| Conley Owens | 094cdbe | 2014-01-30 15:09:59 -0800 | [diff] [blame] | 30 | def Wrapper(): |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 31 | modname = "wrapper" |
| 32 | loader = importlib.machinery.SourceFileLoader(modname, WrapperPath()) |
| 33 | spec = importlib.util.spec_from_loader(modname, loader) |
| 34 | module = importlib.util.module_from_spec(spec) |
| 35 | loader.exec_module(module) |
| 36 | return module |