@@ -168,85 +168,17 @@ def ffx_daemon_log_path(self):
168
168
def ffx_isolate_dir (self ):
169
169
return os .path .join (self .tmp_dir (), "ffx_isolate" )
170
170
171
- def ffx_home_dir (self ):
172
- return os .path .join (self .ffx_isolate_dir (), "user-home" )
171
+ def home_dir (self ):
172
+ return os .path .join (self .tmp_dir (), "user-home" )
173
173
174
- def ffx_tmp_dir (self ):
175
- return os .path .join (self .ffx_isolate_dir (), "tmp" )
176
-
177
- def ffx_log_dir (self ):
178
- return os .path .join (self .ffx_isolate_dir (), "log" )
179
-
180
- def ffx_user_config_dir (self ):
181
- return os .path .join (self .ffx_xdg_config_home (), "Fuchsia" , "ffx" , "config" )
182
-
183
- def ffx_user_config_path (self ):
184
- return os .path .join (self .ffx_user_config_dir (), "config.json" )
185
-
186
- def ffx_xdg_config_home (self ):
187
- if platform .system () == "Darwin" :
188
- return os .path .join (self .ffx_home_dir (), "Library" , "Preferences" )
189
- return os .path .join (self .ffx_home_dir (), ".local" , "share" )
190
-
191
- def ffx_ascendd_path (self ):
192
- return os .path .join (self .ffx_tmp_dir (), "ascendd" )
193
174
194
175
def start_ffx_isolation (self ):
195
176
# Most of this is translated directly from ffx's isolate library
196
177
os .mkdir (self .ffx_isolate_dir ())
197
- os .mkdir (self .ffx_home_dir ())
198
- os .mkdir (self .ffx_tmp_dir ())
199
- os .mkdir (self .ffx_log_dir ())
200
-
201
- fuchsia_dir = os .path .join (self .ffx_home_dir (), ".fuchsia" )
202
- os .mkdir (fuchsia_dir )
203
-
204
- fuchsia_debug_dir = os .path .join (fuchsia_dir , "debug" )
205
- os .mkdir (fuchsia_debug_dir )
206
-
207
- metrics_dir = os .path .join (fuchsia_dir , "metrics" )
208
- os .mkdir (metrics_dir )
178
+ os .mkdir (self .home_dir ())
209
179
210
- analytics_path = os .path .join (metrics_dir , "analytics-status" )
211
- with open (analytics_path , "w" , encoding = "utf-8" ) as analytics_file :
212
- print ("0" , file = analytics_file )
213
-
214
- ffx_path = os .path .join (metrics_dir , "ffx" )
215
- with open (ffx_path , "w" , encoding = "utf-8" ) as ffx_file :
216
- print ("1" , file = ffx_file )
217
-
218
- os .makedirs (self .ffx_user_config_dir ())
219
-
220
- with open (
221
- self .ffx_user_config_path (), "w" , encoding = "utf-8"
222
- ) as config_json_file :
223
- user_config_for_test = {
224
- "log" : {
225
- "enabled" : True ,
226
- "dir" : self .ffx_log_dir (),
227
- },
228
- "overnet" : {
229
- "socket" : self .ffx_ascendd_path (),
230
- },
231
- "ssh" : {
232
- "pub" : self .ssh_authfile_path (),
233
- "priv" : self .ssh_keyfile_path (),
234
- },
235
- "test" : {
236
- "is_isolated" : True ,
237
- "experimental_structured_output" : True ,
238
- },
239
- }
240
- print (json .dumps (user_config_for_test ), file = config_json_file )
241
-
242
- ffx_env_path = os .path .join (self .ffx_user_config_dir (), ".ffx_env" )
243
- with open (ffx_env_path , "w" , encoding = "utf-8" ) as ffx_env_file :
244
- ffx_env_config_for_test = {
245
- "user" : self .ffx_user_config_path (),
246
- "build" : None ,
247
- "global" : None ,
248
- }
249
- print (json .dumps (ffx_env_config_for_test ), file = ffx_env_file )
180
+ ffx_path = self .tool_path ("ffx" )
181
+ ffx_env = self .ffx_cmd_env ()
250
182
251
183
# Start ffx daemon
252
184
# We want this to be a long-running process that persists after the script finishes
@@ -256,38 +188,65 @@ def start_ffx_isolation(self):
256
188
) as ffx_daemon_log_file :
257
189
subprocess .Popen (
258
190
[
259
- self .tool_path ("ffx" ),
260
- "--config" ,
261
- self .ffx_user_config_path (),
191
+ ffx_path ,
262
192
"daemon" ,
263
193
"start" ,
264
194
],
265
- env = self . ffx_cmd_env () ,
195
+ env = ffx_env ,
266
196
stdout = ffx_daemon_log_file ,
267
197
stderr = ffx_daemon_log_file ,
268
198
)
269
199
200
+ # Disable analytics
201
+ subprocess .check_call (
202
+ [
203
+ ffx_path ,
204
+ "config" ,
205
+ "analytics" ,
206
+ "disable" ,
207
+ ],
208
+ env = ffx_env ,
209
+ stdout = self .subprocess_output (),
210
+ stderr = self .subprocess_output (),
211
+ )
212
+
213
+ # Set configs
214
+ configs = {
215
+ "log.enabled" : "true" ,
216
+ "ssh.pub" : self .ssh_authfile_path (),
217
+ "ssh.priv" : self .ssh_keyfile_path (),
218
+ "test.is_isolated" : "true" ,
219
+ "test.experimental_structured_output" : "true" ,
220
+ }
221
+ for key , value in configs .items ():
222
+ subprocess .check_call (
223
+ [
224
+ self .tool_path ("ffx" ),
225
+ "config" ,
226
+ "set" ,
227
+ key ,
228
+ value ,
229
+ ],
230
+ env = self .ffx_cmd_env (),
231
+ stdout = self .subprocess_output (),
232
+ stderr = self .subprocess_output (),
233
+ )
234
+
270
235
def ffx_cmd_env (self ):
271
- result = {
272
- "HOME" : self .ffx_home_dir (),
273
- "XDG_CONFIG_HOME" : self .ffx_xdg_config_home (),
274
- "ASCENDD" : self .ffx_ascendd_path (),
275
- "FUCHSIA_SSH_KEY" : self .ssh_keyfile_path (),
236
+ return {
237
+ "HOME" : self .home_dir (),
238
+ "FFX_ISOLATE_DIR" : self .ffx_isolate_dir (),
276
239
# We want to use our own specified temp directory
277
240
"TMP" : self .tmp_dir (),
278
241
"TEMP" : self .tmp_dir (),
279
242
"TMPDIR" : self .tmp_dir (),
280
243
"TEMPDIR" : self .tmp_dir (),
281
244
}
282
245
283
- return result
284
-
285
246
def stop_ffx_isolation (self ):
286
247
subprocess .check_call (
287
248
[
288
249
self .tool_path ("ffx" ),
289
- "--config" ,
290
- self .ffx_user_config_path (),
291
250
"daemon" ,
292
251
"stop" ,
293
252
],
@@ -709,8 +668,6 @@ def log(msg):
709
668
subprocess .run (
710
669
[
711
670
self .tool_path ("ffx" ),
712
- "--config" ,
713
- self .ffx_user_config_path (),
714
671
"test" ,
715
672
"run" ,
716
673
f"fuchsia-pkg://{ self .TEST_REPO_NAME } /{ package_name } #meta/{ package_name } .cm" ,
@@ -849,8 +806,6 @@ def delete_tmp(self):
849
806
def debug (self , args ):
850
807
command = [
851
808
self .tool_path ("ffx" ),
852
- "--config" ,
853
- self .ffx_user_config_path (),
854
809
"debug" ,
855
810
"connect" ,
856
811
"--" ,
@@ -948,8 +903,6 @@ def syslog(self, args):
948
903
subprocess .run (
949
904
[
950
905
self .tool_path ("ffx" ),
951
- "--config" ,
952
- self .ffx_user_config_path (),
953
906
"log" ,
954
907
"--since" ,
955
908
"now" ,
0 commit comments