| 1 |
from enum import Enum |
| 2 |
|
| 3 |
# Used for the --wrap-mode command-line argument |
| 4 |
# |
| 5 |
# Special wrap modes: |
| 6 |
# nofallback: Don't download wraps for dependency() fallbacks |
| 7 |
# nodownload: Don't download wraps for all subproject() calls |
| 8 |
# |
| 9 |
# subprojects are used for two purposes: |
| 10 |
# 1. To download and build dependencies by using .wrap |
| 11 |
# files if they are not provided by the system. This is |
| 12 |
# usually expressed via dependency(..., fallback: ...). |
| 13 |
# 2. To download and build 'copylibs' which are meant to be |
| 14 |
# used by copying into your project. This is always done |
| 15 |
# with an explicit subproject() call. |
| 16 |
# |
| 17 |
# --wrap-mode=nofallback will never do (1) |
| 18 |
# --wrap-mode=nodownload will do neither (1) nor (2) |
| 19 |
# |
| 20 |
# If you are building from a release tarball, you should be |
| 21 |
# able to safely use 'nodownload' since upstream is |
| 22 |
# expected to ship all required sources with the tarball. |
| 23 |
# |
| 24 |
# If you are building from a git repository, you will want |
| 25 |
# to use 'nofallback' so that any 'copylib' wraps will be |
| 26 |
# download as subprojects. |
| 27 |
# |
| 28 |
# --wrap-mode=forcefallback will ignore external dependencies, |
| 29 |
# even if they match the version requirements, and automatically |
| 30 |
# use the fallback if one was provided. This is useful for example |
| 31 |
# to make sure a project builds when using the fallbacks. |
| 32 |
# |
| 33 |
# Note that these options do not affect subprojects that |
| 34 |
# are git submodules since those are only usable in git |
| 35 |
# repositories, and you almost always want to download them. |
| 36 |
|
| 37 |
# This did _not_ work when inside the WrapMode class. |
| 38 |
# I don't know why. If you can fix this, patches welcome. |
| 39 |
string_to_value = {'default': 1, |
| 40 |
'nofallback': 2, |
| 41 |
'nodownload': 3, |
| 42 |
'forcefallback': 4, |
| 43 |
'nopromote': 5, |
| 44 |
} |
| 45 |
|
| 46 |
class WrapMode(Enum): |
| 47 |
default = 1 |
| 48 |
nofallback = 2 |
| 49 |
nodownload = 3 |
| 50 |
forcefallback = 4 |
| 51 |
nopromote = 5 |
| 52 |
|
| 53 |
def __str__(self) -> str: |
| 54 |
return self.name |
| 55 |
|
| 56 |
@staticmethod |
| 57 |
def from_string(mode_name: str) -> 'WrapMode': |
| 58 |
g = string_to_value[mode_name] |
| 59 |
return WrapMode(g) |