|
36 | 36 | extract_as_list, typeslistify, stringlistify, classify_unity_sources,
|
37 | 37 | get_filenames_templates_dict, substitute_values, has_path_sep,
|
38 | 38 | OptionKey, PerMachineDefaultable, OptionOverrideProxy,
|
39 |
| - MesonBugException |
| 39 | + MesonBugException, EnvironmentVariables |
40 | 40 | )
|
41 | 41 | from .compilers import (
|
42 | 42 | is_object, clink_langs, sort_clink, all_languages,
|
@@ -502,71 +502,6 @@ def needs_copy(self) -> bool:
|
502 | 502 | return False
|
503 | 503 |
|
504 | 504 |
|
505 |
| -EnvInitValueType = T.Dict[str, T.Union[str, T.List[str]]] |
506 |
| - |
507 |
| - |
508 |
| -class EnvironmentVariables(HoldableObject): |
509 |
| - def __init__(self, values: T.Optional[EnvInitValueType] = None, |
510 |
| - init_method: Literal['set', 'prepend', 'append'] = 'set', separator: str = os.pathsep) -> None: |
511 |
| - self.envvars: T.List[T.Tuple[T.Callable[[T.Dict[str, str], str, T.List[str], str], str], str, T.List[str], str]] = [] |
512 |
| - # The set of all env vars we have operations for. Only used for self.has_name() |
513 |
| - self.varnames: T.Set[str] = set() |
514 |
| - |
515 |
| - if values: |
516 |
| - init_func = getattr(self, init_method) |
517 |
| - for name, value in values.items(): |
518 |
| - init_func(name, listify(value), separator) |
519 |
| - |
520 |
| - def __repr__(self) -> str: |
521 |
| - repr_str = "<{0}: {1}>" |
522 |
| - return repr_str.format(self.__class__.__name__, self.envvars) |
523 |
| - |
524 |
| - def hash(self, hasher: T.Any): |
525 |
| - myenv = self.get_env({}) |
526 |
| - for key in sorted(myenv.keys()): |
527 |
| - hasher.update(bytes(key, encoding='utf-8')) |
528 |
| - hasher.update(b',') |
529 |
| - hasher.update(bytes(myenv[key], encoding='utf-8')) |
530 |
| - hasher.update(b';') |
531 |
| - |
532 |
| - def has_name(self, name: str) -> bool: |
533 |
| - return name in self.varnames |
534 |
| - |
535 |
| - def get_names(self) -> T.Set[str]: |
536 |
| - return self.varnames |
537 |
| - |
538 |
| - def set(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None: |
539 |
| - self.varnames.add(name) |
540 |
| - self.envvars.append((self._set, name, values, separator)) |
541 |
| - |
542 |
| - def append(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None: |
543 |
| - self.varnames.add(name) |
544 |
| - self.envvars.append((self._append, name, values, separator)) |
545 |
| - |
546 |
| - def prepend(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None: |
547 |
| - self.varnames.add(name) |
548 |
| - self.envvars.append((self._prepend, name, values, separator)) |
549 |
| - |
550 |
| - @staticmethod |
551 |
| - def _set(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str: |
552 |
| - return separator.join(values) |
553 |
| - |
554 |
| - @staticmethod |
555 |
| - def _append(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str: |
556 |
| - curr = env.get(name) |
557 |
| - return separator.join(values if curr is None else [curr] + values) |
558 |
| - |
559 |
| - @staticmethod |
560 |
| - def _prepend(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str: |
561 |
| - curr = env.get(name) |
562 |
| - return separator.join(values if curr is None else values + [curr]) |
563 |
| - |
564 |
| - def get_env(self, full_env: T.MutableMapping[str, str]) -> T.Dict[str, str]: |
565 |
| - env = full_env.copy() |
566 |
| - for method, name, values, separator in self.envvars: |
567 |
| - env[name] = method(env, name, values, separator) |
568 |
| - return env |
569 |
| - |
570 | 505 | @dataclass(eq=False)
|
571 | 506 | class Target(HoldableObject):
|
572 | 507 |
|
|
0 commit comments