From d9a9155a80f0918847241742f95d13d9efb8b7f2 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 21 Nov 2011 11:44:27 -0800 Subject: [PATCH] tools.deploy: embed image into deployed VM Also, use the unix backend to deploy non-UI applications on macosx --- basis/tools/deploy/backend/backend.factor | 17 ++++++++++------- basis/tools/deploy/embed/embed.factor | 2 +- basis/tools/deploy/macosx/macosx.factor | 18 +++++++++++------- basis/tools/deploy/unix/unix.factor | 6 ++++-- basis/tools/deploy/windows/windows.factor | 4 ++-- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/basis/tools/deploy/backend/backend.factor b/basis/tools/deploy/backend/backend.factor index 0fabf39b6c..70a7003cd9 100644 --- a/basis/tools/deploy/backend/backend.factor +++ b/basis/tools/deploy/backend/backend.factor @@ -8,7 +8,8 @@ io.streams.c io.files io.files.temp io.pathnames io.directories io.directories.hierarchy io.backend quotations io.launcher tools.deploy.config tools.deploy.config.editor bootstrap.image io.encodings.utf8 destructors accessors hashtables -tools.deploy.libraries vocabs.metadata.resources ; +tools.deploy.libraries vocabs.metadata.resources +tools.deploy.embed locals ; IN: tools.deploy.backend : copy-vm ( executable bundle-name -- vm ) @@ -29,8 +30,8 @@ ERROR: can't-deploy-library-file library ; : copy-libraries ( manifest name dir -- ) append-path swap libraries>> [ copy-library ] with each ; -: image-name ( vocab bundle-name -- str ) - prepend-path ".image" append ; +: deployed-image-name ( vocab -- str ) + ".image" append temp-file ; : copy-lines ( -- ) readln [ print flush copy-lines ] when* ; @@ -119,10 +120,12 @@ DEFER: ?make-staging-image [ "invalid vocab manifest!" throw ] if ] if-empty ; -: make-deploy-image ( vm image vocab config -- manifest ) +:: make-deploy-image-executable ( vm image vocab config -- manifest ) make-boot-image - over "vocab-manifest-" prepend temp-file - [ swap deploy-command-line run-factor ] - [ parse-vocab-manifest-file ] bi ; + vocab "vocab-manifest-" prepend temp-file :> manifest-file + image vocab manifest-file config deploy-command-line :> flags + vm flags run-factor + image vm embed-image + manifest-file parse-vocab-manifest-file ; HOOK: deploy* os ( vocab -- ) diff --git a/basis/tools/deploy/embed/embed.factor b/basis/tools/deploy/embed/embed.factor index da8e2f78fa..e6bd5d1d52 100644 --- a/basis/tools/deploy/embed/embed.factor +++ b/basis/tools/deploy/embed/embed.factor @@ -1,7 +1,7 @@ ! (c)2010 Joe Groff bsd license USING: alien.c-types alien.data bootstrap.image bootstrap.image.private destructors io io.directories -io.encodings.binary io.files locals system ; +io.encodings.binary io.files locals system kernel ; IN: tools.deploy.embed :: embed-image ( image executable -- ) diff --git a/basis/tools/deploy/macosx/macosx.factor b/basis/tools/deploy/macosx/macosx.factor index 98b3d2528a..57bdd99420 100644 --- a/basis/tools/deploy/macosx/macosx.factor +++ b/basis/tools/deploy/macosx/macosx.factor @@ -7,11 +7,12 @@ tools.deploy.config.editor assocs hashtables prettyprint io.backend.unix cocoa io.encodings.utf8 io.backend cocoa.application cocoa.classes cocoa.plists combinators vocabs.metadata vocabs.loader ; +QUALIFIED-WITH: tools.deploy.unix unix IN: tools.deploy.macosx : bundle-dir ( -- dir ) running.app? - [ vm parent-directory parent-directory ] + [ vm parent-directory parent-directory parent-directory ] [ "resource:Factor.app" ] if ; @@ -61,9 +62,6 @@ IN: tools.deploy.macosx } 2cleave dup 0o755 set-file-permissions ; -: deploy.app-image ( vocab bundle-name -- str ) - [ % "/Contents/Resources/" % % ".image" % ] "" make ; - : bundle-name ( -- string ) deploy-name get ".app" append ; @@ -72,16 +70,22 @@ IN: tools.deploy.macosx [ normalize-path [ ] [ parent-directory ] bi ] bi* -> selectFile:inFileViewerRootedAtPath: drop ; -M: macosx deploy* ( vocab -- ) +: deploy-app-bundle ( vocab -- ) "resource:" [ dup deploy-config [ bundle-name dup exists? [ delete-tree ] [ drop ] if [ bundle-name create-app-dir ] keep - [ bundle-name deploy.app-image ] keep - namespace make-deploy-image + [ deployed-image-name ] keep + namespace make-deploy-image-executable bundle-name [ "Contents/Resources" copy-resources ] [ "Contents/Frameworks" copy-libraries ] 2bi bundle-name show-in-finder ] bind ] with-directory ; + +M: macosx deploy* ( vocab -- ) + ! pass off to M: unix deploy* if we're building a console app + deploy-console? get + [ call-next-method ] + [ deploy-app-bundle ] if ; diff --git a/basis/tools/deploy/unix/unix.factor b/basis/tools/deploy/unix/unix.factor index 629e607b62..562546f1c2 100644 --- a/basis/tools/deploy/unix/unix.factor +++ b/basis/tools/deploy/unix/unix.factor @@ -3,6 +3,7 @@ USING: io io.backend io.directories io.files.info.unix kernel namespaces sequences system tools.deploy.backend tools.deploy.config tools.deploy.config.editor ; +QUALIFIED: webbrowser IN: tools.deploy.unix : create-app-dir ( vocab bundle-name -- vm ) @@ -16,9 +17,10 @@ M: unix deploy* ( vocab -- ) "resource:" [ dup deploy-config [ [ bundle-name create-app-dir ] keep - [ bundle-name image-name ] keep - namespace make-deploy-image + [ deployed-image-name ] keep + namespace make-deploy-image-executable bundle-name "" [ copy-resources ] [ copy-libraries ] 3bi bundle-name normalize-path "Binary deployed to " "." surround print + bundle-name webbrowser:open-file ] bind ] with-directory ; diff --git a/basis/tools/deploy/windows/windows.factor b/basis/tools/deploy/windows/windows.factor index e3e8bee46a..08255f9cf5 100755 --- a/basis/tools/deploy/windows/windows.factor +++ b/basis/tools/deploy/windows/windows.factor @@ -35,8 +35,8 @@ M: windows deploy* { [ create-exe-dir dup ] [ drop embed-ico ] - [ image-name ] - [ drop namespace make-deploy-image ] + [ drop deployed-image-name ] + [ drop namespace make-deploy-image-executable ] [ nip "" [ copy-resources ] [ copy-libraries ] 3bi ] [ nip open-in-explorer ] } 2cleave