Commit 6485b85a by Calen Pennington

Allow overriding of prereqs cache dir

parent a22287f1
...@@ -17,7 +17,7 @@ PACKAGE_NAME = "edx-platform" ...@@ -17,7 +17,7 @@ PACKAGE_NAME = "edx-platform"
COMMIT = (ENV["GIT_COMMIT"] || `git rev-parse HEAD`).chomp()[0, 10] COMMIT = (ENV["GIT_COMMIT"] || `git rev-parse HEAD`).chomp()[0, 10]
BRANCH = (ENV["GIT_BRANCH"] || `git symbolic-ref -q HEAD`).chomp().gsub('refs/heads/', '').gsub('origin/', '') BRANCH = (ENV["GIT_BRANCH"] || `git symbolic-ref -q HEAD`).chomp().gsub('refs/heads/', '').gsub('origin/', '')
PREREQS_MD5_DIR = File.join(REPO_ROOT, '.prereqs_cache') PREREQS_MD5_DIR = ENV["PREREQ_CACHE_DIR"] || File.join(REPO_ROOT, '.prereqs_cache')
# Set up the clean and clobber tasks # Set up the clean and clobber tasks
CLOBBER.include(BUILD_DIR, REPORT_DIR, 'test_root/*_repo', 'test_root/staticfiles', PREREQS_MD5_DIR) CLOBBER.include(BUILD_DIR, REPORT_DIR, 'test_root/*_repo', 'test_root/staticfiles', PREREQS_MD5_DIR)
...@@ -117,36 +117,78 @@ def report_dir_path(dir) ...@@ -117,36 +117,78 @@ def report_dir_path(dir)
return File.join(REPORT_DIR, dir.to_s) return File.join(REPORT_DIR, dir.to_s)
end end
def compile_assets(watch=false, debug=false) def xmodule_cmd(watch=false, debug=false)
xmodule_cmd = 'xmodule_assets common/static/xmodule' xmodule_cmd = 'xmodule_assets common/static/xmodule'
if watch if watch
xmodule_cmd = "watchmedo shell-command \ "watchmedo shell-command " +
--patterns='*.js;*.coffee;*.sass;*.scss;*.css' \ "--patterns='*.js;*.coffee;*.sass;*.scss;*.css' " +
--recursive \ "--recursive " +
--command='#{xmodule_cmd}' \ "--command='#{xmodule_cmd}' " +
common/lib/xmodule" "common/lib/xmodule"
end else
coffee_cmd = "node_modules/.bin/coffee #{watch ? '--watch' : ''} --compile */static" xmodule_cmd
sass_cmd = "sass #{debug ? '--debug-info' : '--style compressed'} " + end
"--load-path ./common/static/sass " + end
"--require ./common/static/sass/bourbon/lib/bourbon.rb " +
"#{watch ? '--watch' : '--update --force'} */static" def coffee_cmd(watch=false, debug=false)
"node_modules/.bin/coffee #{watch ? '--watch' : ''} --compile */static"
[xmodule_cmd, coffee_cmd, sass_cmd].each do |cmd| end
if watch
background_process(cmd) def sass_cmd(watch=false, debug=false)
else "sass #{debug ? '--debug-info' : '--style compressed'} " +
pid = Process.spawn(cmd) "--load-path ./common/static/sass " +
puts "Waiting for `#{cmd}` to complete (pid #{pid})" "--require ./common/static/sass/bourbon/lib/bourbon.rb " +
Process.wait(pid) "#{watch ? '--watch' : '--update'} */static"
puts "Completed" end
if !$?.exited? || $?.exitstatus != 0
abort "`#{cmd}` failed" desc "Compile all assets"
multitask :assets => 'assets:all'
desc "Compile all assets in debug mode"
multitask 'assets:debug'
desc "Watch all assets for changes and automatically recompile"
multitask 'assets:watch'
namespace :assets do
[:xmodule, :coffee, :sass].each do |asset_type|
desc "Compile all #{asset_type} assets"
task asset_type do
cmd = send(asset_type.to_s + "_cmd", watch=false, debug=false)
sh(cmd)
end
multitask :all => asset_type
multitask :debug => "assets:#{asset_type}:debug"
multitask :watch => "assets:#{asset_type}:watch"
namespace asset_type do
desc "Compile all #{asset_type} assets in debug mode"
task :debug do
cmd = send(asset_type.to_s + "_cmd", watch=false, debug=true)
sh(cmd)
end
desc "Watch all #{asset_type} assets and compile on change"
task :watch do
cmd = send(asset_type.to_s + "_cmd", watch=true, debug=true)
background_process(cmd)
end end
end end
end end
# In watch mode, sass doesn't immediately compile out of date files,
# so force a recompile first
task "sass:watch" => "assets:sass:debug"
multitask :sass => [:install_ruby_prereqs, :xmodule]
multitask :coffee => [:install_node_prereqs, :xmodule]
multitask 'coffee:debug' => [:install_ruby_prereqs, 'xmodule:debug']
multitask 'sass:debug' => [:install_node_prereqs, 'xmodule:debug']
task :xmodule => :install_python_prereqs
end end
directory PREREQS_MD5_DIR directory PREREQS_MD5_DIR
def when_changed(*files) def when_changed(*files)
...@@ -294,15 +336,8 @@ end ...@@ -294,15 +336,8 @@ end
Start the #{system} locally with the specified environment (defaults to dev). Start the #{system} locally with the specified environment (defaults to dev).
Other useful environments are devplus (for dev testing with a real local database) Other useful environments are devplus (for dev testing with a real local database)
desc desc
task system, [:env, :options] => [:install_prereqs, :predjango] do |t, args| task system, [:env, :options] => [:install_prereqs, 'assets:watch', :predjango] do |t, args|
args.with_defaults(:env => 'dev', :options => default_options[system]) args.with_defaults(:env => 'dev', :options => default_options[system])
# Compile all assets first
compile_assets(watch=false, debug=true)
# Listen for any changes to assets
compile_assets(watch=true, debug=true)
sh(django_admin(system, args.env, 'runserver', args.options)) sh(django_admin(system, args.env, 'runserver', args.options))
end end
...@@ -315,8 +350,7 @@ end ...@@ -315,8 +350,7 @@ end
end end
desc "Compile coffeescript and sass, and then run collectstatic in the specified environment" desc "Compile coffeescript and sass, and then run collectstatic in the specified environment"
task "#{system}:gather_assets:#{env}" do task "#{system}:gather_assets:#{env}" => :assets do
compile_assets()
sh("#{django_admin(system, env, 'collectstatic', '--noinput')} > /dev/null") do |ok, status| sh("#{django_admin(system, env, 'collectstatic', '--noinput')} > /dev/null") do |ok, status|
if !ok if !ok
abort "collectstatic failed!" abort "collectstatic failed!"
...@@ -326,8 +360,7 @@ end ...@@ -326,8 +360,7 @@ end
end end
desc "Open jasmine tests for #{system} in your default browser" desc "Open jasmine tests for #{system} in your default browser"
task "browse_jasmine_#{system}" do task "browse_jasmine_#{system}" => :assets do
compile_assets()
django_for_jasmine(system, true) do |jasmine_url| django_for_jasmine(system, true) do |jasmine_url|
Launchy.open(jasmine_url) Launchy.open(jasmine_url)
puts "Press ENTER to terminate".red puts "Press ENTER to terminate".red
...@@ -336,8 +369,7 @@ end ...@@ -336,8 +369,7 @@ end
end end
desc "Use phantomjs to run jasmine tests for #{system} from the console" desc "Use phantomjs to run jasmine tests for #{system} from the console"
task "phantomjs_jasmine_#{system}" do task "phantomjs_jasmine_#{system}" => :assets do
compile_assets()
phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs'
django_for_jasmine(system, false) do |jasmine_url| django_for_jasmine(system, false) do |jasmine_url|
sh("#{phantomjs} node_modules/phantom-jasmine/lib/run_jasmine_test.coffee #{jasmine_url}") sh("#{phantomjs} node_modules/phantom-jasmine/lib/run_jasmine_test.coffee #{jasmine_url}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment