Skip to content

Commit

Permalink
Add full-rebuild option when building default package
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgibbs committed Aug 10, 2024
1 parent 28ce2f1 commit 444cbe4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion exe/space_shoes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use_dev = ARGV.delete("--dev") ? true : false
use_debug = ARGV.delete("--debug") ? true : false
use_help = ARGV.delete("--help") ? true : false
use_rebuild = ARGV.delete("--rebuild") ? true : false

# Default to local webview display if not otherwise given
ENV['SCARPE_DISPLAY'] ||= 'space_shoes'
Expand Down Expand Up @@ -117,7 +118,7 @@ when "-v"
when "build-default"
include SpaceShoes::Packaging

location = build_default_wasm_package
location = build_default_wasm_package(options: { full_rebuild: use_rebuild })
sp_location = File.join(SpaceShoes::Packaging::PACKAGING_ROOT, "spacewalk.js")
sp_location = write_spacewalk_file(out_file: sp_location)

Expand Down
21 changes: 15 additions & 6 deletions lib/space_shoes/host/packaging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Packaging
PACKAGING_ROOT = File.join(SOURCE_ROOT, "packaging")
LIB_ROOT = File.join(SOURCE_ROOT, "lib")

OPTIONS = [ :full_rebuild ]

private

def run_or_raise(cmd)
Expand All @@ -34,7 +36,12 @@ def write_spacewalk_file(out_file:)
out_file
end

def build_packed_wasm_file(pack_root: ".", out_file:)
def build_packed_wasm_file(pack_root: ".", out_file:, options: {})
bad_opts = options.keys - OPTIONS
unless bad_opts.empty?
raise SpaceShoes::Error, "Illegal options passed when building wasm file: #{bad_opts.inspect}"
end

unless File.exist?(pack_root) && File.directory?(pack_root)
raise SpaceShoes::Error, "Can't pack wasm file when source directory doesn't exist! source path: #{pack_root.inspect}"
end
Expand All @@ -45,9 +52,11 @@ def build_packed_wasm_file(pack_root: ".", out_file:)
end

Dir.chdir(pack_root) do
# Delete any possible temp build files
["rubies", "build", "spacewalk.js", "ruby.wasm", "packed_ruby.wasm"].each do |build_file|
FileUtils.rm_rf build_file
if options[:full_rebuild]
# Delete any possible temp build files
["rubies", "build", "spacewalk.js", "ruby.wasm", "packed_ruby.wasm"].each do |build_file|
FileUtils.rm_rf build_file
end
end

# Use the packaging dir's Bundler setup, not what the outer program was run with
Expand All @@ -61,11 +70,11 @@ def build_packed_wasm_file(pack_root: ".", out_file:)
end

# Note: packed Ruby+source package should be outside the app dir (a.k.a. src dir)
def build_default_wasm_package
def build_default_wasm_package(options: [])
out_file = PACKAGING_ROOT + "/packed_ruby.wasm"

# without parens on this call, Ruby grabs the next line as part of this one. Weird.
build_packed_wasm_file(pack_root: PACKAGING_ROOT, out_file:)
build_packed_wasm_file(pack_root: PACKAGING_ROOT, out_file:, options:)

out_file
end
Expand Down

0 comments on commit 444cbe4

Please sign in to comment.