File size: 1,144 Bytes
b6130a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from enum import Enum
from typing import Callable, List

from pants.engine.rules import rule
from pants.util.memo import memoized_classproperty
from pants.util.osutil import get_normalized_os_name


class Platform(Enum):
    darwin = "darwin"
    linux = "linux"

    # TODO: try to turn all of these accesses into v2 dependency injections!
    @memoized_classproperty
    def current(cls) -> "Platform":
        return Platform(get_normalized_os_name())


class PlatformConstraint(Enum):
    darwin = "darwin"
    linux = "linux"
    none = "none"

    @memoized_classproperty
    def local_platform(cls) -> "PlatformConstraint":
        return PlatformConstraint(Platform.current.value)


# TODO We will want to allow users to specify the execution platform for rules,
# which means replacing this singleton rule with a RootRule populated by an option.
@rule
def materialize_platform() -> Platform:
    return Platform.current


def create_platform_rules() -> List[Callable]:
    return [materialize_platform]