Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build.saved
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.recipe.build.saved
Commits
6ad77e34
Commit
6ad77e34
authored
Sep 02, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pep8ification.
parent
ea098efa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
17 deletions
+34
-17
slapos/recipe/build.py
slapos/recipe/build.py
+34
-17
No files found.
slapos/recipe/build.py
View file @
6ad77e34
...
@@ -40,6 +40,7 @@ ARCH_MAP = {
...
@@ -40,6 +40,7 @@ ARCH_MAP = {
'x86_64'
:
'x86-64'
'x86_64'
:
'x86-64'
}
}
def
readElfAsDict
(
f
):
def
readElfAsDict
(
f
):
"""Reads ELF information from file"""
"""Reads ELF information from file"""
popen
=
subprocess
.
Popen
([
'readelf'
,
'-d'
,
f
],
popen
=
subprocess
.
Popen
([
'readelf'
,
'-d'
,
f
],
...
@@ -54,9 +55,11 @@ def readElfAsDict(f):
...
@@ -54,9 +55,11 @@ def readElfAsDict(f):
if
'(NEEDED)'
in
l
:
if
'(NEEDED)'
in
l
:
library_list
.
append
(
l
.
split
(
':'
)[
1
].
strip
(
' []'
))
library_list
.
append
(
l
.
split
(
':'
)[
1
].
strip
(
' []'
))
elif
'(RPATH)'
in
l
:
elif
'(RPATH)'
in
l
:
rpath_list
=
[
q
.
rstrip
(
'/'
)
for
q
in
l
.
split
(
':'
,
1
)[
1
].
strip
(
' []'
).
split
(
':'
)]
rpath_list
=
[
q
.
rstrip
(
'/'
)
for
q
in
l
.
split
(
':'
,
1
)[
1
].
strip
(
' []'
).
split
(
':'
)]
elif
'(RUNPATH)'
in
l
:
elif
'(RUNPATH)'
in
l
:
runpath_list
=
[
q
.
rstrip
(
'/'
)
for
q
in
l
.
split
(
':'
,
1
)[
1
].
strip
(
' []'
).
split
(
':'
)]
runpath_list
=
[
q
.
rstrip
(
'/'
)
for
q
in
l
.
split
(
':'
,
1
)[
1
].
strip
(
' []'
).
split
(
':'
)]
if
len
(
runpath_list
)
==
0
:
if
len
(
runpath_list
)
==
0
:
runpath_list
=
rpath_list
runpath_list
=
rpath_list
elif
len
(
rpath_list
)
!=
0
and
runpath_list
!=
rpath_list
:
elif
len
(
rpath_list
)
!=
0
and
runpath_list
!=
rpath_list
:
...
@@ -66,6 +69,7 @@ def readElfAsDict(f):
...
@@ -66,6 +69,7 @@ def readElfAsDict(f):
runpath_list
=
sorted
(
runpath_list
)
runpath_list
=
sorted
(
runpath_list
)
)
)
def
call
(
*
args
,
**
kwargs
):
def
call
(
*
args
,
**
kwargs
):
"""Subprocess call with closed file descriptors and stdin"""
"""Subprocess call with closed file descriptors and stdin"""
kwargs
.
update
(
kwargs
.
update
(
...
@@ -79,21 +83,25 @@ def call(*args, **kwargs):
...
@@ -79,21 +83,25 @@ def call(*args, **kwargs):
if
popen
.
returncode
!=
0
:
if
popen
.
returncode
!=
0
:
raise
subprocess
.
CalledProcessError
(
popen
.
returncode
,
' '
.
join
(
args
[
0
]))
raise
subprocess
.
CalledProcessError
(
popen
.
returncode
,
' '
.
join
(
args
[
0
]))
def
calls
(
call_string
,
**
kwargs
):
def
calls
(
call_string
,
**
kwargs
):
"""Subprocesser caller which allows to pass arguments as string"""
"""Subprocesser caller which allows to pass arguments as string"""
call
(
call_string
.
split
(),
**
kwargs
)
call
(
call_string
.
split
(),
**
kwargs
)
def
guessworkdir
(
path
):
def
guessworkdir
(
path
):
if
len
(
os
.
listdir
(
path
))
==
1
:
if
len
(
os
.
listdir
(
path
))
==
1
:
return
os
.
path
.
join
(
path
,
os
.
listdir
(
path
)[
0
])
return
os
.
path
.
join
(
path
,
os
.
listdir
(
path
)[
0
])
return
path
return
path
def
guessPlatform
():
def
guessPlatform
():
arch
=
uname
()[
-
2
]
arch
=
uname
()[
-
2
]
target
=
ARCH_MAP
.
get
(
arch
)
target
=
ARCH_MAP
.
get
(
arch
)
assert
target
,
'Unknown architecture'
assert
target
,
'Unknown architecture'
return
target
return
target
class
Script
:
class
Script
:
"""Free script building system"""
"""Free script building system"""
def
_checkPromisee
(
self
,
location
):
def
_checkPromisee
(
self
,
location
):
...
@@ -140,16 +148,16 @@ class Script:
...
@@ -140,16 +148,16 @@ class Script:
else
:
else
:
elf_dict
=
readElfAsDict
(
os
.
path
.
join
(
location
,
path
))
elf_dict
=
readElfAsDict
(
os
.
path
.
join
(
location
,
path
))
if
sorted
(
link_list
)
!=
sorted
(
elf_dict
[
'library_list'
]):
if
sorted
(
link_list
)
!=
sorted
(
elf_dict
[
'library_list'
]):
a
(
'Promisee library list not met (wanted: %r, found: %r)'
%
(
a
(
'Promisee library list not met (wanted: %r, found: %r)'
%
(
link_list
,
elf_dict
[
'library_list'
]))
link_list
,
elf_dict
[
'library_list'
]))
if
sorted
(
rpath_list
)
!=
sorted
(
elf_dict
[
'runpath_list'
]):
if
sorted
(
rpath_list
)
!=
sorted
(
elf_dict
[
'runpath_list'
]):
a
(
'Promisee rpath list not met (wanted: %r, found: %r)'
%
(
a
(
'Promisee rpath list not met (wanted: %r, found: %r)'
%
(
rpath_list
,
elf_dict
[
'runpath_list'
]))
rpath_list
,
elf_dict
[
'runpath_list'
]))
else
:
else
:
raise
zc
.
buildout
.
UserError
(
'Unknown promisee %r'
%
promisee
)
raise
zc
.
buildout
.
UserError
(
'Unknown promisee %r'
%
promisee
)
if
len
(
promisee_problem_list
):
if
len
(
promisee_problem_list
):
raise
zc
.
buildout
.
UserError
(
'Promisee not met, found issues:
\
n
%s'
%
raise
zc
.
buildout
.
UserError
(
'Promisee not met, found issues:
\
n
%s'
%
' '
.
join
([
q
+
'
\
n
'
for
q
in
promisee_problem_list
]))
' '
.
join
([
q
+
'
\
n
'
for
q
in
promisee_problem_list
]))
def
download
(
self
,
url
,
md5sum
):
def
download
(
self
,
url
,
md5sum
):
download
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
download
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
...
@@ -180,17 +188,19 @@ class Script:
...
@@ -180,17 +188,19 @@ class Script:
ignore_dir_list
=
[]
ignore_dir_list
=
[]
try
:
try
:
shutil
.
copytree
(
origin
,
destination
,
shutil
.
copytree
(
origin
,
destination
,
ignore
=
lambda
src
,
names
:
ignore_dir_list
)
ignore
=
lambda
src
,
names
:
ignore_dir_list
)
except
(
shutil
.
Error
,
OSError
)
as
error
:
except
(
shutil
.
Error
,
OSError
)
as
error
:
# Cleanup in case of failure
# Cleanup in case of failure
try
:
try
:
shutil
.
rmtree
(
destination
,
ignore_errors
=
True
)
shutil
.
rmtree
(
destination
,
ignore_errors
=
True
)
except
(
shutil
.
Error
,
OSError
),
strerror
:
except
(
shutil
.
Error
,
OSError
),
strerror
:
self
.
logger
.
error
(
"Error occurred when cleaning after error: %s"
,
strerror
)
self
.
logger
.
error
(
"Error occurred when cleaning after error: %s"
,
strerror
)
raise
error
raise
error
return
True
return
True
script
=
'raise NotImplementedError'
script
=
'raise NotImplementedError'
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
cleanup_dir_list
=
[]
self
.
cleanup_dir_list
=
[]
self
.
options
=
options
self
.
options
=
options
...
@@ -204,7 +214,8 @@ class Script:
...
@@ -204,7 +214,8 @@ class Script:
# cleanup some variables
# cleanup some variables
for
k
in
[
'location'
,
'url'
,
'md5sum'
]:
for
k
in
[
'location'
,
'url'
,
'md5sum'
]:
self
.
options
[
k
]
=
self
.
options
.
get
(
k
,
''
).
strip
()
self
.
options
[
k
]
=
self
.
options
.
get
(
k
,
''
).
strip
()
self
.
options
[
'script'
]
=
self
.
options
.
get
(
'script'
,
self
.
script
)
%
self
.
options
self
.
options
[
'script'
]
=
self
.
options
.
get
(
'script'
,
self
.
script
)
%
\
self
.
options
def
getEnvironment
(
self
):
def
getEnvironment
(
self
):
# prepare cool dictionary
# prepare cool dictionary
...
@@ -214,7 +225,8 @@ class Script:
...
@@ -214,7 +225,8 @@ class Script:
if
not
line
:
if
not
line
:
continue
continue
if
not
'='
in
line
:
if
not
'='
in
line
:
raise
zc
.
buildout
.
UserError
(
'Line %r in environment is incorrect'
%
line
)
raise
zc
.
buildout
.
UserError
(
'Line %r in environment is incorrect'
%
line
)
key
,
value
=
line
.
split
(
'='
)
key
,
value
=
line
.
split
(
'='
)
key
=
key
.
strip
()
key
=
key
.
strip
()
...
@@ -223,14 +235,14 @@ class Script:
...
@@ -223,14 +235,14 @@ class Script:
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
key
)
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
key
)
wanted_env
[
key
]
=
value
wanted_env
[
key
]
=
value
env
=
{}
env
=
{}
for
k
,
v
in
os
.
environ
.
iteritems
():
for
k
,
v
in
os
.
environ
.
iteritems
():
change
=
wanted_env
.
pop
(
k
,
None
)
change
=
wanted_env
.
pop
(
k
,
None
)
if
change
is
not
None
:
if
change
is
not
None
:
env
[
k
]
=
change
%
os
.
environ
env
[
k
]
=
change
%
os
.
environ
self
.
logger
.
info
(
'Environment %r setup to %r'
%
(
k
,
env
[
k
]))
self
.
logger
.
info
(
'Environment %r setup to %r'
%
(
k
,
env
[
k
]))
else
:
else
:
env
[
k
]
=
v
env
[
k
]
=
v
for
k
,
v
in
wanted_env
.
iteritems
():
for
k
,
v
in
wanted_env
.
iteritems
():
self
.
logger
.
info
(
'Environment %r added with %r'
%
(
k
,
v
))
self
.
logger
.
info
(
'Environment %r added with %r'
%
(
k
,
v
))
env
[
k
]
=
v
env
[
k
]
=
v
return
env
return
env
...
@@ -243,7 +255,8 @@ class Script:
...
@@ -243,7 +255,8 @@ class Script:
self
.
_checkPromisee
(
self
.
options
[
'location'
])
self
.
_checkPromisee
(
self
.
options
[
'location'
])
except
Exception
:
except
Exception
:
if
os
.
path
.
exists
(
self
.
options
[
'location'
]):
if
os
.
path
.
exists
(
self
.
options
[
'location'
]):
self
.
logger
.
info
(
'Removing location %r because of error'
%
self
.
options
[
'location'
])
self
.
logger
.
info
(
'Removing location %r because of error'
%
self
.
options
[
'location'
])
shutil
.
rmtree
(
self
.
options
[
'location'
])
shutil
.
rmtree
(
self
.
options
[
'location'
])
raise
raise
finally
:
finally
:
...
@@ -257,13 +270,16 @@ class Script:
...
@@ -257,13 +270,16 @@ class Script:
def
update
(
self
):
def
update
(
self
):
pass
pass
class
Cmmi
(
Script
):
class
Cmmi
(
Script
):
"""Simple configure-make-make-insall compatible with hexagonit.recipe.cmmi
"""Simple configure-make-make-insall compatible with hexagonit.recipe.cmmi
Compatibility on parameter level, without bug-to-bug, hack-to-hack"""
Compatibility on parameter level, without bug-to-bug, hack-to-hack"""
script
=
"""
script
=
"""
extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
url = self.download(self.options['url']
md5sum = self.options.get('md5sum')
extract_dir = self.extract(url, md5sum)
workdir = guessworkdir(extract_dir)
workdir = guessworkdir(extract_dir)
configure_command = ["./configure", "--prefix=%(location)s"]
configure_command = ["./configure", "--prefix=%(location)s"]
configure_command.extend(%(configure-options)r.split())
configure_command.extend(%(configure-options)r.split())
...
@@ -276,5 +292,6 @@ call(["make", "install"], cwd=workdir, env=env)
...
@@ -276,5 +292,6 @@ call(["make", "install"], cwd=workdir, env=env)
"""
"""
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
options
[
'configure-options'
]
=
' '
.
join
(
options
.
get
(
'configure-options'
,
''
).
strip
().
splitlines
())
options
[
'configure-options'
]
=
' '
.
join
(
options
.
get
(
'configure-options'
,
''
).
strip
().
splitlines
())
Script
.
__init__
(
self
,
buildout
,
name
,
options
)
Script
.
__init__
(
self
,
buildout
,
name
,
options
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment