diff --git a/LICENSE b/LICENSE index f431584..dc586dc 100644 --- a/LICENSE +++ b/LICENSE @@ -3,21 +3,19 @@ The MIT License (MIT) Copyright (c) pixeldroid https://github.com/pixeldroid/loomtasks -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 8eeb96f..6d7da29 100644 --- a/README.md +++ b/README.md @@ -38,24 +38,27 @@ Clone this repo. Running `rake` in your project directory will execute the default task, which prints the list of available tasks and some useful info: - Foo v1.2.3 Rakefile running on Ruby 2.3.0 (lib=sprint33, test=sprint33) + Foo v1.2.3 Rakefile running on Ruby 2.3.0 (lib=sprint34, test=sprint34) rake clean # removes intermediate files to ensure a clean build rake clobber # removes all generated artifacts to restore project to checkout-like state - rake demo:build # builds FooDemo.loom for sprint33 SDK + rake demo:build # builds FooDemo.loom for sprint34 SDK rake demo:cli[options] # executes FooDemo.loom as a commandline app, with options rake demo:gui # launches FooDemo.loom as a GUI app - rake lib:build # builds Foo.loomlib for sprint33 SDK - rake lib:install # installs Foo.loomlib into sprint33 SDK + rake help # show detailed usage and project info + rake lib:build # builds Foo.loomlib for sprint34 SDK + rake lib:install # installs Foo.loomlib into sprint34 SDK rake lib:release # prepares sdk-specific Foo.loomlib for release, and updates version in README - rake lib:show # lists libs installed for sprint33 SDK - rake lib:uninstall # removes Foo.loomlib from sprint33 SDK + rake lib:show # lists libs installed for sprint34 SDK + rake lib:uninstall # removes Foo.loomlib from sprint34 SDK + rake set:sdk[id] # sets the provided SDK version into lib/loom.config and test/loom.config + rake set:version[v] # sets the library version number into lib/src/Foo.build and lib/src/pixeldroid/cli/Foo.ls rake set[sdk] # sets the provided SDK version into lib/loom.config and test/loom.config rake test # shorthand for rake test:run - rake test:build # builds FooTest.loom against sprint33 SDK + rake test:build # builds FooTest.loom against sprint34 SDK rake test:ci # runs FooTest.loom for CI rake test:run # runs FooTest.loom for the console - rake version[v] # changes the library version number - (using loomtasks v1.2.0) + rake version # report loomlib version + (using loomtasks v1.2.1) use `rake -D` for more detailed task descriptions diff --git a/Rakefile b/Rakefile index 2a48e1d..e10bcfb 100644 --- a/Rakefile +++ b/Rakefile @@ -43,6 +43,27 @@ task :install do |t, args| puts '' end +desc [ + "show usage and project info", +].join("\n") +task :help do |t, args| + system("rake -D") + + puts "Log bugs to: https://github.com/pixeldroid/loomtasks/issues" + puts "Project home page: https://github.com/pixeldroid/loomtasks" + puts '' + puts "Please see the README for additional details." + puts '' +end + +desc [ + "report loomtasks version", +].join("\n") +task :version do |t, args| + puts "loomtasks v#{VERSION}" + puts '' +end + namespace :list do desc [ diff --git a/lib/tasks/loomlib.rake b/lib/tasks/loomlib.rake index 9ff7696..531994f 100644 --- a/lib/tasks/loomlib.rake +++ b/lib/tasks/loomlib.rake @@ -33,6 +33,10 @@ def const_lib_version_file const_find('LIB_VERSION_FILE') end +def default_sdk + global_config['default_sdk'] +end + def lib_build_file() File.join('lib', 'src', "#{const_lib_name}.build") end @@ -41,6 +45,10 @@ def lib_config_file() File.join('lib', 'loom.config') end +def lib_file() + "#{const_lib_name}.loomlib" +end + def lib_version_file() const_lib_version_file end @@ -53,6 +61,10 @@ def test_config_file() File.join('test', 'loom.config') end +def global_config() + @global_loom_config || (@global_loom_config = parse_loom_config(global_config_file)) +end + def lib_config() @lib_loom_config || (@lib_loom_config = parse_loom_config(lib_config_file)) end @@ -81,14 +93,14 @@ end @lib_loom_config = nil @test_loom_config = nil -CLEAN.include ['lib/build/**', 'test/bin/**', 'TEST-*.xml'] +CLEAN.include ['bin/**', 'lib/build/**', 'test/bin/**', 'TEST-*.xml'] Rake::Task[:clean].clear_comments() Rake::Task[:clean].add_description([ "removes intermediate files to ensure a clean build", "running now would delete #{CLEAN.length} files:\n #{CLEAN.join("\n ")}", ].join("\n")) -CLOBBER.include ['lib/build', 'test/bin', 'releases'] +CLOBBER.include ['bin', 'lib/build', 'test/bin', 'releases'] Rake::Task[:clobber].enhance(['lib:uninstall']) Rake::Task[:clobber].clear_comments() Rake::Task[:clobber].add_description([ @@ -119,7 +131,7 @@ task :check_consts do |t, args| end -LIBRARY = "lib/build/#{const_lib_name}.loomlib" +LIBRARY = File.join('lib', 'build', lib_file) file LIBRARY do |t, args| puts "[file] creating #{t.name}..." @@ -135,18 +147,18 @@ file LIBRARY do |t, args| puts '' end -FileList['lib/src/**/*.ls'].each do |src| +FileList[File.join('lib', 'src', '**', '*.ls')].each do |src| file LIBRARY => src end -APP = "test/bin/#{const_lib_name}Test.loom" +APP = File.join('test', 'bin', "#{const_lib_name}Test.loom") file APP => LIBRARY do |t, args| puts "[file] creating #{t.name}..." sdk_version = test_config['sdk_version'] - file_installed = File.join(libs_path(sdk_version), "#{const_lib_name}.loomlib") + file_installed = File.join(libs_path(sdk_version), lib_file) Rake::Task['lib:install'].invoke unless FileUtils.uptodate?(file_installed, [LIBRARY]) @@ -159,57 +171,81 @@ file APP => LIBRARY do |t, args| puts '' end -FileList['test/src/app/*.ls'].each do |src| +FileList[File.join('test', 'src', 'app', '*.ls')].each do |src| file APP => src end -FileList['test/src/spec/*.ls'].each do |src| +FileList[File.join('test', 'src', 'spec', '*.ls')].each do |src| file APP => src end -desc [ - "sets the provided SDK version into lib/loom.config and test/loom.config", - "lib/loom.config defines which SDK will be used to compile the loomlib, and also where to install it", - "test/loom.config defines which SDK will be used to compile the test app and demo app", -].join("\n") -task :set, [:sdk] => 'lib:uninstall' do |t, args| - args.with_defaults(:sdk => 'sprint33') - sdk_version = args.sdk +namespace :set do - lib_config['sdk_version'] = sdk_version - test_config['sdk_version'] = sdk_version + desc [ + "sets the provided SDK version into #{lib_config_file} and #{test_config_file}", + "this updates #{lib_config_file} to define which SDK will compile the loomlib and be the install target", + "this updates #{test_config_file} to define which SDK will compile the test app and demo app", + ].join("\n") + task :sdk, [:id] => 'lib:uninstall' do |t, args| + args.with_defaults(:id => default_sdk) + sdk_version = args.id + lib_dir = libs_path(sdk_version) - write_lib_config(lib_config) - write_test_config(test_config) + fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir)) - puts "[#{t.name}] task completed, sdk updated to #{sdk_version}" - puts '' + lib_config['sdk_version'] = sdk_version + test_config['sdk_version'] = sdk_version + + write_lib_config(lib_config) + write_test_config(test_config) + + puts "[#{t.name}] task completed, sdk updated to #{sdk_version}" + puts '' + end + + desc [ + "sets the library version number into #{lib_build_file} and #{lib_version_file}", + "#{lib_version_file} is expected to have a line matching:", + "#{lib_version_regex.to_s}", + ].join("\n") + task :version, [:v] do |t, args| + args.with_defaults(:v => '1.0.0') + lib_version = args.v + + lib_build_config['version'] = lib_version + lib_build_config['modules'].first['version'] = lib_version + + write_lib_build_config(lib_build_config) + update_lib_version(lib_version) + + puts "[#{t.name}] task completed, lib version updated to #{lib_version}" + puts '' + end end desc [ - "changes the library version number", - "this updates #{lib_build_file}", - "this updates #{lib_version_file}", + "show detailed usage and project info", ].join("\n") -task :version, [:v] do |t, args| - args.with_defaults(:v => '1.0.0') - lib_version = args.v - - lib_build_config['version'] = lib_version - lib_build_config['modules'].first['version'] = lib_version +task :help do |t, args| + system("rake -D") - write_lib_build_config(lib_build_config) - update_lib_version(lib_version) + puts "Please see the README for additional details." + puts '' +end - puts "[#{t.name}] task completed, lib version updated to #{lib_version}" +desc [ + "report loomlib version", +].join("\n") +task :version do |t, args| + puts "#{const_lib_name} v#{lib_version}" puts '' end namespace :lib do desc [ - "builds #{const_lib_name}.loomlib for #{lib_config['sdk_version']} SDK", + "builds #{lib_file} for #{lib_config['sdk_version']} SDK", "the SDK is specified in test/loom.config", "you can change the SDK with rake set[sdk]", "the .loomlib binary is created in lib/build", @@ -220,54 +256,52 @@ namespace :lib do end desc [ - "prepares sdk-specific #{const_lib_name}.loomlib for release, and updates version in README", + "prepares sdk-specific #{lib_file} for release, and updates version in README", "the version value will be read from #{LIB_VERSION_FILE}", "it must match this regex: #{lib_version_regex}", ].join("\n") task :release => LIBRARY do |t, args| - lib = "lib/build/#{const_lib_name}.loomlib" sdk = lib_config['sdk_version'] ext = '.loomlib' release_dir = 'releases' - puts "[#{t.name}] updating README to reference version #{lib_version}" + puts "[#{t.name}] updating README to reference version #{lib_version} and sdk '#{sdk}'" update_readme_version(lib_version, sdk) Dir.mkdir(release_dir) unless Dir.exists?(release_dir) - lib_release = %Q[#{File.basename(lib, ext)}-#{sdk}#{ext}] - FileUtils.copy(lib, "#{release_dir}/#{lib_release}") + lib_release = %Q[#{File.basename(LIBRARY, ext)}-#{sdk}#{ext}] + FileUtils.copy(LIBRARY, "#{release_dir}/#{lib_release}") puts "[#{t.name}] task completed, find #{lib_release} in #{release_dir}/" puts '' end desc [ - "installs #{const_lib_name}.loomlib into #{lib_config['sdk_version']} SDK", + "installs #{lib_file} into #{lib_config['sdk_version']} SDK", "this makes it available to reference in .build files of any project targeting #{lib_config['sdk_version']}", ].join("\n") task :install => LIBRARY do |t, args| sdk_version = lib_config['sdk_version'] - lib = File.join('lib', 'build', "#{const_lib_name}.loomlib") - FileUtils.cp(lib, libs_path(sdk_version)) + FileUtils.cp(LIBRARY, libs_path(sdk_version)) - puts "[#{t.name}] task completed, #{const_lib_name}.loomlib installed for #{sdk_version}" + puts "[#{t.name}] task completed, #{lib_file} installed for #{sdk_version}" puts '' end desc [ - "removes #{const_lib_name}.loomlib from #{lib_config['sdk_version']} SDK", + "removes #{lib_file} from #{lib_config['sdk_version']} SDK", ].join("\n") task :uninstall do |t, args| sdk_version = lib_config['sdk_version'] - lib = File.join(libs_path(sdk_version), "#{const_lib_name}.loomlib") + installed_lib = File.join(libs_path(sdk_version), lib_file) - if (File.exists?(lib)) - FileUtils.rm_r(lib) - puts "[#{t.name}] task completed, #{const_lib_name}.loomlib removed from #{sdk_version}" + if (File.exists?(installed_lib)) + FileUtils.rm_r(installed_lib) + puts "[#{t.name}] task completed, #{lib_file} removed from #{sdk_version}" else - puts "[#{t.name}] nothing to do; no #{const_lib_name}.loomlib found in #{sdk_version} sdk" + puts "[#{t.name}] nothing to do; no #{lib_file} found in #{sdk_version} sdk" end puts '' end @@ -279,10 +313,10 @@ namespace :lib do ].join("\n") task :show do |t, args| sdk_version = lib_config['sdk_version'] + lib_dir = libs_path(sdk_version) - libs_dir = File.join(sdk_root, sdk_version, 'libs') - puts("installed libs in #{libs_dir}") - Dir.glob("#{libs_dir}/*").each { |f| puts(File.basename(f)) } + puts("installed libs in #{lib_dir}") + Dir.glob(File.join(lib_dir, '*')).each { |f| puts(File.basename(f)) } puts '' end @@ -292,7 +326,7 @@ end namespace :test do desc [ - "builds #{const_lib_name}Test.loom against #{test_config['sdk_version']} SDK", + "builds #{APP} against #{test_config['sdk_version']} SDK", "the SDK is specified in test/loom.config", "you can change the SDK with rake set[sdk]", "the .loom binary is created in test/bin", @@ -303,40 +337,36 @@ namespace :test do end desc [ - "runs #{const_lib_name}Test.loom for the console", + "runs #{APP} for the console", "the test runner will print short-form results to stdout", ].join("\n") task :run => APP do |t, args| - puts "[#{t.name}] running #{t.prerequisites[0]}..." - sdk_version = test_config['sdk_version'] - bin_dir = 'bin' + # loomexec expects to find bin/Main.loom, so we make a launchable copy there + puts "[#{t.name}] running #{t.prerequisites[0]} as #{main_binary}..." Dir.mkdir(bin_dir) unless Dir.exists?(bin_dir) - - FileUtils.cp(APP, File.join(bin_dir, 'Main.loom')) - cmd = "#{loomexec(sdk_version)} --ignored ignore --format ansi" - try(cmd, "failed to run .loom") + FileUtils.cp(APP, main_binary) + cmd = "#{loomexec(sdk_version)} --format ansi" + try(cmd, "tests failed") puts '' end desc [ - "runs #{const_lib_name}Test.loom for CI", + "runs #{APP} for CI", "in CI mode, the test runner will print long-form results to stdout and generate jUnit compatible reports", "the jUnit xml report files are written to the project root, as TEST-*.xml", ].join("\n") task :ci => APP do |t, args| - puts "[#{t.name}] running #{t.prerequisites[0]}..." - sdk_version = test_config['sdk_version'] - bin_dir = 'bin' + # loomexec expects to find bin/Main.loom, so we make a launchable copy there + puts "[#{t.name}] running #{t.prerequisites[0]} as #{main_binary}..." Dir.mkdir(bin_dir) unless Dir.exists?(bin_dir) - - FileUtils.cp(APP, File.join(bin_dir, 'Main.loom')) - cmd = "#{loomexec(sdk_version)} --ignored ignore --format junit --format console" - try(cmd, "failed to run .loom") + FileUtils.cp(APP, main_binary) + cmd = "#{loomexec(sdk_version)} --format junit --format console" + try(cmd, "tests failed") puts '' end diff --git a/lib/tasks/loomlib_demo.rake b/lib/tasks/loomlib_demo.rake index 72ba305..0ff5eed 100644 --- a/lib/tasks/loomlib_demo.rake +++ b/lib/tasks/loomlib_demo.rake @@ -12,9 +12,10 @@ require 'fileutils' require File.join(File.dirname(__FILE__), 'support') include LoomTasks -DEMO = "test/bin/#{const_lib_name}Demo.loom" -FileList['test/src/demo/*.ls'].each do |src| +DEMO = File.join('test', 'bin', "#{const_lib_name}Demo.loom") + +FileList[File.join('test', 'src', 'demo', '*.ls')].each do |src| file DEMO => src end @@ -22,7 +23,7 @@ file DEMO => LIBRARY do |t, args| puts "[file] creating #{t.name}..." sdk_version = test_config['sdk_version'] - file_installed = "#{sdk_root}/#{sdk_version}/libs/#{const_lib_name}.loomlib" + file_installed = File.join(sdk_root, sdk_version, 'libs', "#{lib_file}") Rake::Task['lib:install'].invoke unless FileUtils.uptodate?(file_installed, [LIBRARY]) @@ -38,7 +39,7 @@ end namespace :demo do desc [ - "builds #{const_lib_name}Demo.loom for #{test_config['sdk_version']} SDK", + "builds #{DEMO} for #{test_config['sdk_version']} SDK", "the SDK is specified in test/loom.config", "you can change the SDK with rake set[sdk]", "the .loom binary is created in test/bin", @@ -49,45 +50,48 @@ namespace :demo do end desc [ - "launches #{const_lib_name}Demo.loom as a GUI app", + "launches #{DEMO} as a GUI app", "use this launcher if your demo application class extends loom.Application", "if your demo is a cli app, remove this task from the list with Rake::Task['demo:gui'].clear", ].join("\n") task :gui => DEMO do |t, args| - puts "[#{t.name}] launching #{t.prerequisites[0]}..." - sdk_version = test_config['sdk_version'] - Dir.chdir('test') do - loomlib = "bin/#{const_lib_name}Demo.loom" - abort("could not find '#{loomlib}'' to launch") unless File.exists?(loomlib) + puts "[#{t.name}] launching #{DEMO} as #{main_binary}..." + abort("could not find '#{DEMO}' to launch") unless File.exists?(DEMO) - # loomlaunch expects to find Main.loom, so we make a launchable copy here - FileUtils.cp(loomlib, 'bin/Main.loom') + # loomlaunch expects to find bin/Main.loom, so we make a launchable copy here + Dir.mkdir(bin_dir) unless Dir.exists?(bin_dir) + FileUtils.cp(DEMO, main_binary) - # capture the interrupt signal from a quit app - begin - cmd = loomlaunch(sdk_version) - try(cmd, "failed to launch .loom") - rescue Exception => e - puts ' (quit)' - end + # capture the interrupt signal from a quit app + begin + cmd = loomlaunch(sdk_version) + try(cmd, "failed to launch .loom") + rescue Exception => e + puts ' (quit)' end end desc [ - "executes #{const_lib_name}Demo.loom as a commandline app, with options", + "executes #{DEMO} as a commandline app, with options, if provided", "use this launcher if your demo application class extends system.application.ConsoleApplication", "if your demo is a gui app, remove this task from the list with Rake::Task['demo:cli'].clear", ].join("\n") task :cli, [:options] => DEMO do |t, args| args.with_defaults(:options => '') - puts "[#{t.name}] executing #{t.prerequisites[0]}..." sdk_version = test_config['sdk_version'] - cmd = "#{loomexec(sdk_version)} test/bin/#{const_lib_name}Demo.loom #{args.options}" - try(cmd, "failed to run .loom") + puts "[#{t.name}] executing #{DEMO} as #{main_binary}..." + abort("could not find '#{DEMO}' to launch") unless File.exists?(DEMO) + + # loomexec expects to find bin/Main.loom, so we make a launchable copy there + Dir.mkdir(bin_dir) unless Dir.exists?(bin_dir) + FileUtils.cp(DEMO, main_binary) + + cmd = "#{loomexec(sdk_version)} #{args.options}" + try(cmd, "failed to exec .loom") puts '' end diff --git a/lib/tasks/support.rb b/lib/tasks/support.rb index cb2f3a7..1e5c082 100644 --- a/lib/tasks/support.rb +++ b/lib/tasks/support.rb @@ -4,7 +4,7 @@ module LoomTasks - VERSION = '1.2.0' + VERSION = '2.0.0' EXIT_OK = 0 @@ -23,10 +23,20 @@ def try(cmd, failure_message) fail(failure_message) if (exec_with_echo(cmd) != EXIT_OK) end + def bin_dir() + 'bin' + end + + def main_binary() + File.join(bin_dir, 'Main.loom') + end + def loomexec(sdk_version) # needs to be run in the project root # stubbornly, the runner loads bin/Main.loom from the current working directory - File.join(sdk_tools(sdk_version), 'loomexec') + # weirdly, the runner expects a throw-away arg, so we pass an ignorable something + ignorable = '//' + "#{File.join(sdk_tools(sdk_version), 'loomexec')} #{ignorable}" end def loomlaunch(sdk_version) @@ -50,6 +60,10 @@ def lsc(sdk_version) File.join(sdk_tools(sdk_version), 'lsc') end + def global_config_file() + File.join(Dir.home, '.loom', 'loom.config') + end + def sdk_root() File.join(Dir.home, '.loom', 'sdks') end diff --git a/lib/tasks/templates/LoomlibTest.ls.erb b/lib/tasks/templates/LoomlibTest.ls.erb index 2d4c663..feb5b9c 100644 --- a/lib/tasks/templates/LoomlibTest.ls.erb +++ b/lib/tasks/templates/LoomlibTest.ls.erb @@ -1,6 +1,7 @@ package { + import system.Process; import system.application.ConsoleApplication; import pixeldroid.bdd.Spec; @@ -15,12 +16,14 @@ package public class <%= lib_name %>Test extends ConsoleApplication { private var seed:Number = -1; + private const SUCCESS:Number = 0; + private const FAILURE:Number = 1; override public function run():void { <%= lib_name %>Spec.describe(); parseArgs(); - Spec.execute(seed); + Process.exit(Spec.execute(seed) ? SUCCESS : FAILURE); } private function parseArgs():void diff --git a/lib/tasks/templates/Rakefile.erb b/lib/tasks/templates/Rakefile.erb index e18710e..ca85134 100644 --- a/lib/tasks/templates/Rakefile.erb +++ b/lib/tasks/templates/Rakefile.erb @@ -1,5 +1,13 @@ LIB_NAME = '<%= lib_name %>' LIB_VERSION_FILE = File.join('lib', 'src', '<%= lib_name %>.ls') -load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib.rake')) -#load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib_demo.rake')) # optional +begin + load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib.rake')) + #load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib_demo.rake')) # optional +rescue LoadError + abort([ + 'error: missing loomlib.rake', + ' please install loomtasks before running this Rakefile:', + ' https://github.com/pixeldroid/loomtasks/', + ].join("\n")) +end