Add FileUtils class methods to script DSL - close #144

This commit is contained in:
Josh Holtrop 2022-01-17 16:41:36 -05:00
parent 034dbcd9a6
commit c1dcfa297f
4 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,11 @@
build do
mkdir "foo"
cd "foo" do
mkdir_p ["bar/baz", "bar/booz"]
end
mv "foo/bar", "foobar"
rmdir "foo"
touch "foobar/booz/a.txt"
cp "foobar/booz/a.txt", "foobar/baz/b.txt"
rm_rf "foobar/booz"
end

View File

@ -233,6 +233,33 @@ The `Rsconscript` file is a Ruby script.
* `rscons` (see ${#Using Subsidiary Build Scripts: The rscons Method}) * `rscons` (see ${#Using Subsidiary Build Scripts: The rscons Method})
* `sh` (see (${#Executing Commands: The sh Method}) * `sh` (see (${#Executing Commands: The sh Method})
Additionally, the following methods from the Ruby
[FileUtils](https://ruby-doc.org/stdlib-3.1.0/libdoc/fileutils/rdoc/FileUtils.html)
module are made available for the build script to call directly:
* `cd`
* `chmod`
* `chmod_R`
* `chown`
* `chown_R`
* `cp`
* `cp_lr`
* `cp_r`
* `install`
* `ln`
* `ln_s`
* `ln_sf`
* `mkdir`
* `mkdir_p`
* `mv`
* `pwd`
* `rm`
* `rm_f`
* `rm_r`
* `rm_rf`
* `rmdir`
* `touch`
###> Finding Files: The glob Method ###> Finding Files: The glob Method
The [`glob`](../yard/Rscons/Script/GlobalDsl.html#glob-instance_method) method can be The [`glob`](../yard/Rscons/Script/GlobalDsl.html#glob-instance_method) method can be

View File

@ -159,6 +159,35 @@ module Rscons
end end
end end
[
:cd,
:chmod,
:chmod_R,
:chown,
:chown_R,
:cp,
:cp_lr,
:cp_r,
:install,
:ln,
:ln_s,
:ln_sf,
:mkdir,
:mkdir_p,
:mv,
:pwd,
:rm,
:rm_f,
:rm_r,
:rm_rf,
:rmdir,
:touch,
].each do |method|
define_method(method) do |*args, **kwargs, &block|
FileUtils.__send__(method, *args, **kwargs, &block)
end
end
end end
# Top-level DSL available to the Rsconscript. # Top-level DSL available to the Rsconscript.

View File

@ -2844,4 +2844,16 @@ EOF
end end
end end
context "FileUtils methods" do
it "defines FileUtils methods to be available in the build script" do
test_dir "typical"
result = run_rscons(rsconscript: "fileutils_methods.rb")
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(Dir.exist?("foobar")).to be_truthy
expect(Dir.exist?("foo")).to be_falsey
expect(File.exist?("foobar/baz/b.txt")).to be_truthy
end
end
end end