`Makefile` nedir? `make` uygulamasının işini yapabilmesi için gereken işlemlerin akışının saklandığı dosya, yani bir tür reçetedir. https://opensource.com/article/18/8/what-how-makefile
`Makefile` faydaları ? Bir kısım kural içerir, bu kurallar birbirine bağlı olabilirler ya da sırayla birbirini takip edebilirler. https://opensource.com/article/18/8/what-how-makefile
`rake` nedir? • `make`’in Ruby’cesidir. • Ruby kurulumunda beraber gelir, bir gem’dir. • Komut satırı ortamında her projede kullanılabilir. • Domain Specific Language (DSL) için en iyi örnektir. • En güncel sürümü için `gem install rake` yeterlidir.
`rake` in babası kimdir ? https://www.wikiwand.com/en/Jim_Weirich • Jim Nolan Weirich tarafından geliştirildi. (1956-2014) • macOS 10.5 (Leopard)’dan beri birlikte geliyor (2006). • https://l.vigo.io/rake-10-5
Neden tercih ediyorum ? • Bash hız açısından iyi ama limitli • macOS ile birlikte `ruby` geldiği için `rake` de built-in, ek bir araca ihtiyaç yok! • Local (folder bazında) ya da Global (tüm sistem bazında) çalışan Rakefile tanımlamak mümkün • Çünkü ruby ❤
default task $ rake rake aborted! Don't know how to build task 'default' (See the list of available tasks with `rake --tasks`) (See full trace by running task with --trace)
Önşartlı task / zincirleme task :check_env do abort "environment variable FOO is not set" unless ENV['FOO'] end desc "say hello world" task :hello_world => [:check_env] do puts "hello world with FOO: #{ENV['FOO']}" end $ rake -T rake hello_world # say hello world $ rake hello_world environment variable FOO is not set $ FOO=1 rake hello_world hello world with FOO: 1
File task’leri file "/path/to/output" => "/path/to/input" do # your code here end file "/path/to/output" => ["/path/to/input1", "/path/to/input2"] do |t| # your code here end file "merged.txt" => ["file1", "file2"] do |t| sh "cat #{t.prerequisites.join(' ')} > #{t.name}" # cat file1 file2 > merged.txt end $ rake merged.txt
Paralel çalışan task’ler multitask copy_files: %w[copy_src copy_doc copy_bin] do puts "All Copies Complete" end task :copy_src do puts "copy src task" end task :copy_doc do puts "copy doc task" end task :copy_bin do puts "copy bin task" end $ rake copy_files copy bin task copy src task copy doc task All Copies Complete
Diğer özellikler: invoke task :check_settings do Rake ::Task["check_virtualenv"].invoke Rake ::Task["check_django_env"].invoke end task :check_virtualenv do abort "Please activate your virtual environment" unless ENV['VIRTUAL_ENV'] end task :check_django_env do abort "Please define DJANGO_ENV variable" unless ENV['DJANGO_ENV'] end task :check_settings => [:check_virtualenv, :check_django_env] do |t| puts "task #{t.name} called ..." end task :check_virtualenv do abort "Please activate your virtual environment" unless ENV['VIRTUAL_ENV'] end task :check_django_env do abort "Please define DJANGO_ENV variable" unless ENV['DJANGO_ENV'] end
Diğer özellikler: invoke task :default => [:run] task :run => [:step1, :step2] do Rake ::Task["step1"].invoke Rake ::Task["step1"].invoke Rake ::Task["step2"].invoke Rake ::Task["step2"].invoke end task :step1 do puts "step1 is called" end task :step2 do puts "step2 is called" end $ rake step1 is called step2 is called
Diğer özellikler: execute task :default => [:run] task :run => [:step1, :step2] do Rake ::Task["step1"].execute Rake ::Task["step1"].execute Rake ::Task["step2"].execute Rake ::Task["step2"].execute end task :step1 do puts "step1 is called" end task :step2 do puts "step2 is called" end $ rake step1 is called step2 is called step1 is called step1 is called step2 is called step2 is called https://medium.com/@sampatbadhe/rake-task-invoke-or-execute-419cd689c3bd
Diğer özellikler: invoke + argüman namespace :db do task :delete_db_file, [:db_file] do |_, args| psql = %x{ command -v psql } if psql.empty? fn = "project/db/ #{args.db_file}.sqlite3" if File.exists?(fn) puts "Deleting: #{fn}" rm(fn) else puts " #{fn} not exists ..." end else puts "Dropping and re-creating PostgreSQL database" system "dropdb #{POSTGRES_DB_NAME} --if-exists" system "createdb #{POSTGRES_DB_NAME}" end end task :delete_development_db do Rake ::Task["db:delete_db_file"].invoke('development') end end
task :default => [:install] desc "Remove/Delete build ..." task :clean do rm_rf %w(build dist) rm_rf Dir.glob("*.egg-info") puts "Build files are removed ..." end desc "Install package for local development purpose" task :install => [:build] do system "pip install -e ." end desc "Build package" task :build => [:clean] do system "python setup.py sdist bdist_wheel" end namespace :upload do desc "Upload package to main distro (release)" task :main => [:build] do puts "Uploading package to MAIN distro ..." system "twine upload --repository pypi dist /*" end desc "Upload package to test distro" task :test => [:build] do puts "Uploading package to TEST distro ..." system "twine upload --repository testpypi dist /*" end end AVAILABLE_REVISIONS = ["major", "minor", "patch"] desc "Bump version" task :bump, [:revision] do |t, args| args.with_defaults(revision: "patch") abort "Please provide valid revision: #{AVAILABLE_REVISIONS.join(',')}" unless AVAILABLE_REVISIONS.include?(args.revision) system "bumpversion #{args.revision}" end https://github.com/vbyazilim/django-vb-baseapp