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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::{
    makepad_live_id::LiveId,
    makepad_code_editor::text::{Position, Length},
    makepad_micro_serde::{SerBin, DeBin, DeBinErr},
};


#[derive(PartialEq, Clone, Copy, Debug, SerBin, DeBin)]
pub struct BuildCmdId(pub u64);

#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum BuildTarget {
    Release,
    Debug,
    ReleaseStudio,
    DebugStudio,
    Profiler,
    IosSim{org:String, app:String},
    IosDevice{org:String, app:String},
    Android,
    WebAssembly
}

impl BuildTarget {
    pub fn runs_in_studio(&self)->bool{
        match self{
            Self::ReleaseStudio=>true,
            Self::DebugStudio=>true,
            _=>false
        }
    }
    
    pub const RELEASE_STUDIO:u64 = 0;
    pub const DEBUG_STUDIO:u64 = 1;
    pub const RELEASE:u64 = 2;
    pub const DEBUG:u64 = 3;
    pub const PROFILER:u64 = 4;
    pub const IOS_SIM:u64 = 5;
    pub const IOS_DEVICE:u64 = 6;
    pub const ANDROID:u64 = 7;
    pub const WEBASSEMBLY:u64 = 8;
    pub fn len() -> u64 {9}
    pub fn name(idx: u64) -> &'static str {
        match idx {
            Self::RELEASE_STUDIO=> "Release Studio",
            Self::DEBUG_STUDIO=> "Debug Studio",
            Self::RELEASE=> "Release",
            Self::DEBUG=> "Debug",
            Self::PROFILER=> "Profiler",
            Self::IOS_SIM=> "iOS Simulator",
            Self::IOS_DEVICE=> "iOS Device",
            Self::ANDROID=> "Android",
            Self::WEBASSEMBLY=> "WebAssembly",
            _=>"Unknown"
        }
    }
    pub fn id(&self) -> u64 {
        match self {
            Self::ReleaseStudio=>Self::RELEASE_STUDIO,
            Self::DebugStudio=>Self::DEBUG_STUDIO,
            Self::Release=>Self::RELEASE,
            Self::Debug=>Self::DEBUG,
            Self::Profiler=>Self::PROFILER,
            Self::IosSim{..}=>Self::IOS_SIM,
            Self::IosDevice{..}=>Self::IOS_DEVICE,
            Self::Android=>Self::ANDROID,
            Self::WebAssembly=>Self::WEBASSEMBLY
        }
    }
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct BuildProcess{
    pub binary: String,
    pub target: BuildTarget
}

impl BuildProcess{
    pub fn as_id(&self)->LiveId{
        LiveId::from_str(&self.binary).bytes_append(&self.target.id().to_be_bytes())
    }
}


#[derive(Clone, Debug)]
pub struct BuildCmdWrap {
    pub cmd_id: BuildCmdId,
    pub cmd: BuildCmd
}

impl BuildCmdId{
    pub fn wrap_msg(&self, item:LogItem)->LogItemWrap{
        LogItemWrap{
            cmd_id: *self,
            item,
        }
    }
}

#[derive(Clone, Debug)]
pub enum BuildCmd {
    Stop,
    Run(BuildProcess, String),
    HostToStdin(String)
}

#[derive(Clone, Debug)]
pub struct LogItemWrap {
    pub cmd_id: BuildCmdId,
    pub item: LogItem
}

#[derive(Clone, Copy, Debug, SerBin, DeBin)]
pub enum LogItemLevel{
    Warning,
    Error,
    Log,
    Wait,
    Panic,
}

#[derive(Clone, Debug)]
pub struct LogItemLocation{
    pub level: LogItemLevel,
    pub file_name: String,
    pub start: Position,
    pub length: Length,
    pub msg: String
}

#[derive(Clone, Debug)]
pub struct LogItemBare{
    pub level: LogItemLevel,
    pub line: String,
}

#[derive(Clone, Debug)]
pub enum LogItem {
    Bare(LogItemBare),
    Location(LogItemLocation),
    StdinToHost(String),
}