@@ -188,6 +188,10 @@ def help (pkgName)
188188 puts "Build a package."
189189 puts "Usage: crew build [package]"
190190 puts "Build [package] from source and place the archive and checksum in the current working directory."
191+ when "binstall"
192+ puts "Build and install a package."
193+ puts "Usage: crew binstall [package]"
194+ puts "Build and install [package] from source and place the archive and checksum in the current working directory."
191195 when "download"
192196 puts "Download a package."
193197 puts "Usage: crew download [package]"
@@ -640,6 +644,43 @@ def resolve_dependencies_and_build
640644 end
641645end
642646
647+ def resolve_dependencies_and_build_and_install
648+ begin
649+ origin = @pkg . name
650+
651+ # mark current package as which is required to compile from source
652+ @pkg . build_from_source = true
653+ resolve_dependencies
654+
655+ search origin , true
656+ build_package Dir . pwd
657+ if @device [ :installed_packages ] . any? { |pkg | pkg [ :name ] == @pkg . name }
658+ puts "Removing since forcing install..."
659+ remove @pkg . name
660+ end
661+ puts "Installing..."
662+ install_package CREW_DEST_DIR
663+
664+ #add to installed packages
665+ @device [ :installed_packages ] . push ( name : @pkg . name , version : @pkg . version )
666+ File . open ( CREW_CONFIG_PATH + 'device.json' , 'w' ) do |file |
667+ output = JSON . parse @device . to_json
668+ file . write JSON . pretty_generate ( output )
669+ end
670+ puts "#{ @pkg . name . capitalize } installed!"
671+ rescue InstallError => e
672+ abort "#{ @pkg . name } failed to build: #{ e . to_s } "
673+ ensure
674+ #cleanup
675+ unless ARGV [ 2 ] == 'keep'
676+ Dir . chdir CREW_BREW_DIR do
677+ system "rm -rf *"
678+ system "mkdir dest" #this is a little ugly, feel free to find a better way
679+ end
680+ end
681+ end
682+ end
683+
643684def build_package ( pwd )
644685 abort "It is not possible to build fake package" . lightred if @pkg . is_fake?
645686 abort "It is not possible to build without source" . lightred if !@pkg . is_source? ( @device [ :architecture ] )
@@ -774,6 +815,13 @@ when "build"
774815 else
775816 help "build"
776817 end
818+ when "binstall"
819+ if @pkgName
820+ search @pkgName
821+ resolve_dependencies_and_build_and_install
822+ else
823+ help "binstall"
824+ end
777825when "remove"
778826 if @pkgName
779827 remove @pkgName
0 commit comments