| 
									
										
										
										
											2010-02-17 09:57:10 -05:00
										 |  |  | ! Copyright (C) 2007, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2016-04-01 22:56:04 -04:00
										 |  |  | USING: accessors assocs bootstrap.image hashtables io io.directories | 
					
						
							|  |  |  | io.encodings.utf8 io.files io.files.temp io.launcher io.pathnames | 
					
						
							|  |  |  | kernel locals make namespaces prettyprint sequences splitting system | 
					
						
							|  |  |  | tools.deploy.config tools.deploy.config.editor tools.deploy.embed | 
					
						
							|  |  |  | tools.deploy.libraries vocabs.loader vocabs.metadata.resources ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | IN: tools.deploy.backend | 
					
						
							| 
									
										
										
										
											2008-05-10 16:22:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 03:03:00 -04:00
										 |  |  | : copy-vm ( executable bundle-name -- vm-path )
 | 
					
						
							|  |  |  |     prepend-path vm-path over copy-file ;
 | 
					
						
							| 
									
										
										
										
											2008-05-10 16:22:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  | TUPLE: vocab-manifest vocabs libraries ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-14 14:29:37 -05:00
										 |  |  | : copy-resources ( manifest name dir -- )
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  |     append-path swap vocabs>> [ copy-vocab-resources ] with each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-17 09:57:10 -05:00
										 |  |  | ERROR: can't-deploy-library-file library ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  | : copy-library ( dir library -- )
 | 
					
						
							|  |  |  |     dup find-library-file | 
					
						
							| 
									
										
										
										
											2010-02-17 09:57:10 -05:00
										 |  |  |     [ swap over file-name append-path copy-file ] | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |     [ can't-deploy-library-file ] ?if ;
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : copy-libraries ( manifest name dir -- )
 | 
					
						
							|  |  |  |     append-path swap libraries>> [ copy-library ] with each ;
 | 
					
						
							| 
									
										
										
										
											2008-05-10 16:22:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-21 14:44:27 -05:00
										 |  |  | : deployed-image-name ( vocab -- str )
 | 
					
						
							|  |  |  |     ".image" append temp-file ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-18 19:20:26 -04:00
										 |  |  | : copy-lines ( -- )
 | 
					
						
							|  |  |  |     readln [ print flush copy-lines ] when* ;
 | 
					
						
							| 
									
										
										
										
											2008-01-29 03:03:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-03 21:36:04 -05:00
										 |  |  | : run-with-output ( arguments -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  |     <process> | 
					
						
							|  |  |  |         swap >>command | 
					
						
							|  |  |  |         +stdout+ >>stderr | 
					
						
							|  |  |  |         +closed+ >>stdin | 
					
						
							| 
									
										
										
										
											2008-03-26 16:59:11 -04:00
										 |  |  |         +low-priority+ >>priority | 
					
						
							| 
									
										
										
										
											2008-09-18 19:20:26 -04:00
										 |  |  |     utf8 [ copy-lines ] with-process-reader ;
 | 
					
						
							| 
									
										
										
										
											2008-01-29 03:03:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : make-boot-image ( -- )
 | 
					
						
							| 
									
										
										
										
											2015-09-08 19:15:10 -04:00
										 |  |  |     ! If stage1 image doesn't exist, create one. | 
					
						
							| 
									
										
										
										
											2008-02-07 18:55:31 -05:00
										 |  |  |     my-boot-image-name resource-path exists? | 
					
						
							| 
									
										
										
										
											2014-08-05 15:24:34 -04:00
										 |  |  |     [ make-my-image ] unless ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-20 22:11:53 -04:00
										 |  |  | : staging-image-name ( profile -- name )
 | 
					
						
							| 
									
										
										
										
											2015-08-12 12:08:24 -04:00
										 |  |  |     "-" join "." my-arch-name 3append
 | 
					
						
							| 
									
										
										
										
											2012-06-19 20:13:33 -04:00
										 |  |  |     "staging." ".image" surround cache-file ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-23 11:56:05 -05:00
										 |  |  | : delete-staging-images ( -- )
 | 
					
						
							|  |  |  |     cache-directory [ | 
					
						
							|  |  |  |         [ "staging." head? ] filter
 | 
					
						
							| 
									
										
										
										
											2015-08-12 12:08:24 -04:00
										 |  |  |         "." my-arch-name ".image" 3append [ tail? ] curry filter
 | 
					
						
							| 
									
										
										
										
											2014-12-23 11:56:05 -05:00
										 |  |  |         [ delete-file ] each
 | 
					
						
							|  |  |  |     ] with-directory-files ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 00:17:48 -04:00
										 |  |  | : input-image-name ( profile -- name )
 | 
					
						
							|  |  |  |     but-last [ my-boot-image-name ] [ staging-image-name ] if-empty ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : run-factor ( vm-path flags -- )
 | 
					
						
							|  |  |  |     swap prefix dup . run-with-output ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-20 22:11:53 -04:00
										 |  |  | : staging-command-line ( profile -- flags )
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2014-09-28 15:16:39 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             "-staging" , "-no-user-init" , "-pic=0" , | 
					
						
							|  |  |  |             [ staging-image-name "-output-image=" prepend , ] | 
					
						
							|  |  |  |             [ " " join "-include=" prepend , ] bi
 | 
					
						
							| 
									
										
										
										
											2008-03-20 22:11:53 -04:00
										 |  |  |         ] [ | 
					
						
							| 
									
										
										
										
											2016-08-19 00:17:48 -04:00
										 |  |  |             input-image-name "-i=" prepend , | 
					
						
							|  |  |  |             "-resource-path=" "" resource-path append , | 
					
						
							|  |  |  |             "-run=tools.deploy.restage" , | 
					
						
							| 
									
										
										
										
											2014-09-28 15:16:39 -04:00
										 |  |  |         ] bi
 | 
					
						
							| 
									
										
										
										
											2008-03-20 22:11:53 -04:00
										 |  |  |     ] { } make ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-20 22:11:53 -04:00
										 |  |  | : make-staging-image ( profile -- )
 | 
					
						
							| 
									
										
										
										
											2016-08-19 00:17:48 -04:00
										 |  |  |     { } [ suffix ] accumulate* [ staging-image-name exists? ] reject | 
					
						
							|  |  |  |     [ staging-command-line ] map
 | 
					
						
							|  |  |  |     [ vm-path swap run-factor ] each ;
 | 
					
						
							| 
									
										
										
										
											2008-01-29 03:03:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 15:58:00 -05:00
										 |  |  | : make-deploy-config ( vocab -- file )
 | 
					
						
							| 
									
										
										
										
											2009-04-07 22:47:57 -04:00
										 |  |  |     [ deploy-config vocab-roots get vocab-roots associate assoc-union unparse-use ] | 
					
						
							| 
									
										
										
										
											2008-12-08 17:02:31 -05:00
										 |  |  |     [ "deploy-config-" prepend temp-file ] bi
 | 
					
						
							| 
									
										
										
										
											2008-12-08 15:58:00 -05:00
										 |  |  |     [ utf8 set-file-contents ] keep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-28 15:16:39 -04:00
										 |  |  | : deploy-command-line ( image vocab manifest-file profile -- flags )
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2014-09-28 15:16:39 -04:00
										 |  |  |         "-pic=0" , | 
					
						
							|  |  |  |         staging-image-name "-i=" prepend , | 
					
						
							|  |  |  |         "-vocab-manifest-out=" prepend , | 
					
						
							|  |  |  |         [ "-deploy-vocab=" prepend , ] | 
					
						
							|  |  |  |         [ make-deploy-config "-deploy-config=" prepend , ] bi
 | 
					
						
							|  |  |  |         "-output-image=" prepend , | 
					
						
							|  |  |  |         "-resource-path=" "" resource-path append , | 
					
						
							|  |  |  |         "-run=tools.deploy.shaker" , | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  | : parse-vocab-manifest-file ( path -- vocab-manifest )
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:57:12 -05:00
										 |  |  |     utf8 file-lines [ "empty vocab manifest!" throw ] [ | 
					
						
							|  |  |  |         unclip-slice "VOCABS:" =
 | 
					
						
							|  |  |  |         [ { "LIBRARIES:" } split1 vocab-manifest boa ] | 
					
						
							|  |  |  |         [ "invalid vocab manifest!" throw ] if
 | 
					
						
							|  |  |  |     ] if-empty ;
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:32:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 10:54:26 -04:00
										 |  |  | :: make-deploy-image ( vm image vocab config -- manifest )
 | 
					
						
							| 
									
										
										
										
											2008-02-04 21:49:59 -05:00
										 |  |  |     make-boot-image | 
					
						
							| 
									
										
										
										
											2016-04-01 22:56:04 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     config config>profile :> profile | 
					
						
							|  |  |  |     vocab "vocab-manifest-" prepend temp-file :> manifest-file | 
					
						
							|  |  |  |     image vocab manifest-file profile deploy-command-line :> flags | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 00:17:48 -04:00
										 |  |  |     profile make-staging-image | 
					
						
							| 
									
										
										
										
											2016-04-01 22:56:04 -04:00
										 |  |  |     vm flags run-factor | 
					
						
							|  |  |  |     manifest-file parse-vocab-manifest-file ;
 | 
					
						
							| 
									
										
										
										
											2008-01-05 19:37:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 03:17:09 -04:00
										 |  |  | :: make-deploy-image-executable ( vm image vocab config -- manifest )
 | 
					
						
							|  |  |  |     vm image vocab config make-deploy-image | 
					
						
							|  |  |  |     image vm embed-image ;
 | 
					
						
							| 
									
										
										
										
											2011-11-21 17:20:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 14:01:56 -04:00
										 |  |  | SYMBOL: open-directory-after-deploy? | 
					
						
							|  |  |  | t open-directory-after-deploy? set-global
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-02 20:46:37 -04:00
										 |  |  | HOOK: deploy* os ( vocab -- )
 | 
					
						
							| 
									
										
										
										
											2015-08-04 22:06:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | HOOK: deploy-path os ( vocab -- path )
 |