Add PATH manipulation methods - close #126
This commit is contained in:
parent
80d52f25b8
commit
f011b23499
3
build_tests/simple/path_append/foobar
Executable file
3
build_tests/simple/path_append/foobar
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "foobar!"
|
3
build_tests/simple/path_append/gcc
Executable file
3
build_tests/simple/path_append/gcc
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
exit 42
|
3
build_tests/simple/path_prepend/flex
Executable file
3
build_tests/simple/path_prepend/flex
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "flex!"
|
10
build_tests/simple/pathing.rb
Normal file
10
build_tests/simple/pathing.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
path_prepend "path_prepend"
|
||||||
|
path_append "path_append"
|
||||||
|
|
||||||
|
build do
|
||||||
|
Environment.new do |env|
|
||||||
|
system("flex")
|
||||||
|
system("foobar")
|
||||||
|
env.Object("simple.o", "simple.c")
|
||||||
|
end
|
||||||
|
end
|
@ -932,6 +932,22 @@ subsidiary build script.
|
|||||||
Subsidiary build scripts are executed from within the directory containing the
|
Subsidiary build scripts are executed from within the directory containing the
|
||||||
build script.
|
build script.
|
||||||
|
|
||||||
|
###> PATH Management
|
||||||
|
|
||||||
|
`rscons` provides methods for management of the `PATH` environment variable.
|
||||||
|
|
||||||
|
The `path_append` and `path_prepend` methods can be used to append or prepend
|
||||||
|
a path to the `PATH` environment variable.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
path_prepend "i686-elf-gcc/bin"
|
||||||
|
```
|
||||||
|
|
||||||
|
The `path_set` method sets the `PATH` environment variable to the given
|
||||||
|
Array or String.
|
||||||
|
The `path_components` method returns an Array of the components in the `PATH`
|
||||||
|
environment variable.
|
||||||
|
|
||||||
##> Extending Rscons
|
##> Extending Rscons
|
||||||
|
|
||||||
### Adding New Languages
|
### Adding New Languages
|
||||||
|
@ -6,6 +6,47 @@ module Rscons
|
|||||||
# Global DSL methods.
|
# Global DSL methods.
|
||||||
class GlobalDsl
|
class GlobalDsl
|
||||||
|
|
||||||
|
# Return path components from the PATH variable.
|
||||||
|
#
|
||||||
|
# @return [Array<String>]
|
||||||
|
# Path components from the PATH variable.
|
||||||
|
def path_components
|
||||||
|
ENV["PATH"].split(File::PATH_SEPARATOR)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Prepend a path component to the PATH variable.
|
||||||
|
#
|
||||||
|
# @param path [String]
|
||||||
|
# Path to prepend.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def path_prepend(path)
|
||||||
|
path_set([File.expand_path(path)] + path_components)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Append a path component to the PATH variable.
|
||||||
|
#
|
||||||
|
# @param path [String]
|
||||||
|
# Path to append.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def path_append(path)
|
||||||
|
path_set(path_components + [File.expand_path(path)])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set the PATH variable.
|
||||||
|
#
|
||||||
|
# @param new_path [String, Array<String>]
|
||||||
|
# New PATH variable value as an array or string.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def path_set(new_path)
|
||||||
|
if new_path.is_a?(Array)
|
||||||
|
new_path = new_path.join(File::PATH_SEPARATOR)
|
||||||
|
end
|
||||||
|
ENV["PATH"] = new_path
|
||||||
|
end
|
||||||
|
|
||||||
# Invoke rscons in a subprocess for a subsidiary Rsconscript file.
|
# Invoke rscons in a subprocess for a subsidiary Rsconscript file.
|
||||||
#
|
#
|
||||||
# @param path [String]
|
# @param path [String]
|
||||||
|
@ -1475,6 +1475,15 @@ EOF
|
|||||||
expect(result.status).to eq 0
|
expect(result.status).to eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows prepending and appending to PATH" do
|
||||||
|
test_dir "simple"
|
||||||
|
result = run_rscons(rsconscript: "pathing.rb")
|
||||||
|
expect(result.stderr).to eq ""
|
||||||
|
expect(result.stdout).to match /flex!/
|
||||||
|
expect(result.stdout).to match /foobar!/
|
||||||
|
expect(File.exist?("simple.o")).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
context "debugging" do
|
context "debugging" do
|
||||||
it "prints a message when the target does not exist" do
|
it "prints a message when the target does not exist" do
|
||||||
test_dir("simple")
|
test_dir("simple")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user