|
1 | | -from functools import cache, partial |
| 1 | +from functools import partial |
2 | 2 | import glob |
3 | 3 | import inspect |
4 | | -import json |
5 | 4 | import os |
6 | 5 | import subprocess |
7 | 6 | import sys |
8 | 7 |
|
| 8 | +from .config import ServerConfig |
9 | 9 |
|
10 | 10 | def usage(name, msg=None): |
11 | 11 | if msg: |
@@ -99,77 +99,3 @@ def get_workspace(): |
99 | 99 | print("updated buildServer.json") |
100 | 100 |
|
101 | 101 |
|
102 | | -def _config_property(name, default=None, doc=None, delete_none=True): |
103 | | - """ |
104 | | - default only affect getter, not write into data |
105 | | - """ |
106 | | - def fget(self): |
107 | | - return self.data.get(name, default) |
108 | | - |
109 | | - def fset(self, value): |
110 | | - if delete_none and value is None: |
111 | | - self.data.pop(name, None) |
112 | | - else: |
113 | | - self.data[name] = value |
114 | | - |
115 | | - def fdel(self): |
116 | | - del self.data[name] |
117 | | - |
118 | | - return property(fget, fset, fdel, doc) |
119 | | - |
120 | | - |
121 | | -class ServerConfig(object): |
122 | | - """this class control all user config. options: |
123 | | -
|
124 | | - kind: xcode|manual # where to find flags. default: manual |
125 | | - when kind=xcode: |
126 | | - workspace: the bind workspace path |
127 | | - scheme: the bind scheme |
128 | | - build_root: the build_root find from xcworkspace and scheme |
129 | | - when kind=manual(or no kind): |
130 | | - indexStorePath?: the manual parsed index path. may not exists |
131 | | -
|
132 | | - user can change scheme by call `xcode-build-server config`, |
133 | | - or change to manual by call `xcode-build-server parse` directly. |
134 | | -
|
135 | | - after config change. server should change to new flags too.. |
136 | | -
|
137 | | - other config: |
138 | | - skip_validate_bin: if true, will skip validate bin for background parser |
139 | | - """ |
140 | | - |
141 | | - # TODO: distinguish configuration and destination # |
142 | | - |
143 | | - default_path = "buildServer.json" |
144 | | - |
145 | | - kind = _config_property("kind", default="manual") |
146 | | - workspace = _config_property("workspace") |
147 | | - scheme = _config_property("scheme") |
148 | | - build_root = _config_property("build_root") |
149 | | - indexStorePath = _config_property("indexStorePath") |
150 | | - |
151 | | - skip_validate_bin = _config_property("skip_validate_bin") |
152 | | - |
153 | | - @cache |
154 | | - def shared(): |
155 | | - return ServerConfig(ServerConfig.default_path) |
156 | | - |
157 | | - def __init__(self, path): |
158 | | - self.path = os.path.abspath(path) |
159 | | - if os.path.exists(path): |
160 | | - with open(path, "r") as f: |
161 | | - self.data = json.load(f) |
162 | | - else: |
163 | | - self.data = {} |
164 | | - |
165 | | - self.data.update({ |
166 | | - "name": "xcode build server", |
167 | | - "version": "0.2", |
168 | | - "bspVersion": "2.0", |
169 | | - "languages": ["c", "cpp", "objective-c", "objective-cpp", "swift"], |
170 | | - "argv": [sys.argv[0]] |
171 | | - }) |
172 | | - |
173 | | - def save(self): |
174 | | - with open(self.path, "w") as f: |
175 | | - json.dump(self.data, f, indent="\t") |
0 commit comments