From 444cbe437e9579980a90f7d76c37edb5212d5c47 Mon Sep 17 00:00:00 2001 From: Noah Gibbs Date: Sat, 10 Aug 2024 17:06:09 +0100 Subject: [PATCH] Add full-rebuild option when building default package --- exe/space_shoes | 3 ++- lib/space_shoes/host/packaging.rb | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/exe/space_shoes b/exe/space_shoes index c82c2e9..c487220 100755 --- a/exe/space_shoes +++ b/exe/space_shoes @@ -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' @@ -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) diff --git a/lib/space_shoes/host/packaging.rb b/lib/space_shoes/host/packaging.rb index 91a427b..8c71f0a 100644 --- a/lib/space_shoes/host/packaging.rb +++ b/lib/space_shoes/host/packaging.rb @@ -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) @@ -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 @@ -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 @@ -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