Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eic_tools
Spack
Commits
27e9bc6d
Commit
27e9bc6d
authored
8 years ago
by
Todd Gamblin
Browse files
Options
Downloads
Patches
Plain Diff
Make sbang handle lua
- use --! instead of #! for patched lua scripts.
parent
86893e3d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/sbang
+11
-0
11 additions, 0 deletions
bin/sbang
lib/spack/spack/hooks/sbang.py
+6
-1
6 additions, 1 deletion
lib/spack/spack/hooks/sbang.py
lib/spack/spack/test/sbang.py
+18
-5
18 additions, 5 deletions
lib/spack/spack/test/sbang.py
with
35 additions
and
6 deletions
bin/sbang
+
11
−
0
View file @
27e9bc6d
...
@@ -79,6 +79,15 @@
...
@@ -79,6 +79,15 @@
# Obviously, for this to work, `sbang` needs to have a short enough
# Obviously, for this to work, `sbang` needs to have a short enough
# path that *it* will run without hitting OS limits.
# path that *it* will run without hitting OS limits.
#
#
# For Lua, scripts the second line can't start with #!, as # is not
# the comment character in lua (even though lua ignores #! on the
# *first* line of a script). So, instrument a lua script like this,
# using -- instead of # on the second line:
#
# 1 #!/bin/bash /path/to/sbang
# 2 --!/long/path/to/lua with arguments
# 3
# 4 print "success!"
#
#
# How it works
# How it works
# -----------------------------
# -----------------------------
...
@@ -95,6 +104,8 @@ lines=0
...
@@ -95,6 +104,8 @@ lines=0
while
read
line
&&
((
lines < 2
))
;
do
while
read
line
&&
((
lines < 2
))
;
do
if
[[
"
$line
"
=
'#!'
*
]]
;
then
if
[[
"
$line
"
=
'#!'
*
]]
;
then
interpreter
=
"
${
line
#\#!
}
"
interpreter
=
"
${
line
#\#!
}
"
elif
[[
"
$line
"
=
'--!'
*
lua
*
]]
;
then
interpreter
=
"
${
line
#--!
}
"
fi
fi
lines
=
$((
lines+1
))
lines
=
$((
lines+1
))
done
<
"
$script
"
done
<
"
$script
"
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/hooks/sbang.py
+
6
−
1
View file @
27e9bc6d
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
##############################################################################
import
os
import
os
import
re
import
llnl.util.tty
as
tty
import
llnl.util.tty
as
tty
...
@@ -57,11 +58,15 @@ def filter_shebang(path):
...
@@ -57,11 +58,15 @@ def filter_shebang(path):
if
original
.
startswith
(
new_sbang_line
):
if
original
.
startswith
(
new_sbang_line
):
return
return
# Use --! instead of #! on second line for lua.
if
re
.
search
(
r
'
^#!(/[^/]*)*lua\b
'
,
original
):
original
=
re
.
sub
(
r
'
^#
'
,
'
--
'
,
original
)
with
open
(
path
,
'
w
'
)
as
new_file
:
with
open
(
path
,
'
w
'
)
as
new_file
:
new_file
.
write
(
new_sbang_line
)
new_file
.
write
(
new_sbang_line
)
new_file
.
write
(
original
)
new_file
.
write
(
original
)
tty
.
warn
(
"
Patched over
ly
long shebang in %s
"
%
path
)
tty
.
warn
(
"
Patched overlong shebang in %s
"
%
path
)
def
filter_shebangs_in_directory
(
directory
):
def
filter_shebangs_in_directory
(
directory
):
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/test/sbang.py
+
18
−
5
View file @
27e9bc6d
...
@@ -34,10 +34,12 @@
...
@@ -34,10 +34,12 @@
from
spack.hooks.sbang
import
filter_shebangs_in_directory
from
spack.hooks.sbang
import
filter_shebangs_in_directory
import
spack
import
spack
short_line
=
"
#!/this/is/short/bin/bash
\n
"
short_line
=
"
#!/this/is/short/bin/bash
\n
"
long_line
=
"
#!/this/
"
+
(
'
x
'
*
200
)
+
"
/is/long
\n
"
long_line
=
"
#!/this/
"
+
(
'
x
'
*
200
)
+
"
/is/long
\n
"
sbang_line
=
'
#!/bin/bash %s/bin/sbang
\n
'
%
spack
.
spack_root
lua_line
=
"
#!/this/
"
+
(
'
x
'
*
200
)
+
"
/is/lua
\n
"
last_line
=
"
last!
\n
"
lua_line_patched
=
"
--!/this/
"
+
(
'
x
'
*
200
)
+
"
/is/lua
\n
"
sbang_line
=
'
#!/bin/bash %s/bin/sbang
\n
'
%
spack
.
spack_root
last_line
=
"
last!
\n
"
class
SbangTest
(
unittest
.
TestCase
):
class
SbangTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -59,6 +61,12 @@ def setUp(self):
...
@@ -59,6 +61,12 @@ def setUp(self):
f
.
write
(
long_line
)
f
.
write
(
long_line
)
f
.
write
(
last_line
)
f
.
write
(
last_line
)
# Lua script with long shebang
self
.
lua_shebang
=
os
.
path
.
join
(
self
.
tempdir
,
'
lua
'
)
with
open
(
self
.
lua_shebang
,
'
w
'
)
as
f
:
f
.
write
(
lua_line
)
f
.
write
(
last_line
)
# Script already using sbang.
# Script already using sbang.
self
.
has_shebang
=
os
.
path
.
join
(
self
.
tempdir
,
'
shebang
'
)
self
.
has_shebang
=
os
.
path
.
join
(
self
.
tempdir
,
'
shebang
'
)
with
open
(
self
.
has_shebang
,
'
w
'
)
as
f
:
with
open
(
self
.
has_shebang
,
'
w
'
)
as
f
:
...
@@ -71,7 +79,6 @@ def tearDown(self):
...
@@ -71,7 +79,6 @@ def tearDown(self):
shutil
.
rmtree
(
self
.
tempdir
,
ignore_errors
=
True
)
shutil
.
rmtree
(
self
.
tempdir
,
ignore_errors
=
True
)
def
test_shebang_handling
(
self
):
def
test_shebang_handling
(
self
):
filter_shebangs_in_directory
(
self
.
tempdir
)
filter_shebangs_in_directory
(
self
.
tempdir
)
...
@@ -86,6 +93,12 @@ def test_shebang_handling(self):
...
@@ -86,6 +93,12 @@ def test_shebang_handling(self):
self
.
assertEqual
(
f
.
readline
(),
long_line
)
self
.
assertEqual
(
f
.
readline
(),
long_line
)
self
.
assertEqual
(
f
.
readline
(),
last_line
)
self
.
assertEqual
(
f
.
readline
(),
last_line
)
# Make sure this got patched.
with
open
(
self
.
lua_shebang
,
'
r
'
)
as
f
:
self
.
assertEqual
(
f
.
readline
(),
sbang_line
)
self
.
assertEqual
(
f
.
readline
(),
lua_line_patched
)
self
.
assertEqual
(
f
.
readline
(),
last_line
)
# Make sure this is untouched
# Make sure this is untouched
with
open
(
self
.
has_shebang
,
'
r
'
)
as
f
:
with
open
(
self
.
has_shebang
,
'
r
'
)
as
f
:
self
.
assertEqual
(
f
.
readline
(),
sbang_line
)
self
.
assertEqual
(
f
.
readline
(),
sbang_line
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment