Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Dietrich
clang-hash
Commits
5458918b
Commit
5458918b
authored
Jan 16, 2017
by
Christian Dietrich
Browse files
fogot lib.py
parent
15462d94
Pipeline
#3004
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
experiments/lib.py
0 → 100644
View file @
5458918b
import
os
import
fnmatch
import
time
from
versuchung.execute
import
shell
,
CommandFailed
import
logging
def
read_hash_directory
(
hash_dir
,
remove_keys
=
[]):
"""Read in all records from a hash dir
"""
ret
=
[]
for
root
,
dirnames
,
filenames
in
os
.
walk
(
hash_dir
):
for
filename
in
fnmatch
.
filter
(
filenames
,
'*.info'
):
with
open
(
os
.
path
.
join
(
root
,
filename
))
as
fd
:
data
=
"[%s]"
%
(
","
.
join
(
fd
.
readlines
()))
data
=
eval
(
data
)
for
record
in
data
:
for
key
in
remove_keys
:
del
record
[
key
]
ret
.
extend
(
data
)
print
len
(
ret
)
return
ret
class
ClangHashHelper
:
def
project_name
(
self
):
return
os
.
path
.
basename
(
self
.
metadata
[
'project-clone-url'
])
def
setup_compiler_paths
(
self
,
clang_path
):
if
"ccache"
in
self
.
mode
.
value
:
cache_dir
=
os
.
path
.
join
(
self
.
tmp_directory
.
path
,
"ccache"
)
os
.
mkdir
(
cache_dir
)
os
.
environ
[
"CCACHE_DIR"
]
=
cache_dir
if
self
.
mode
.
value
==
"normal"
:
CC
=
os
.
path
.
join
(
clang_path
,
"build/wrappers/clang-normal"
)
elif
self
.
mode
.
value
==
"clang-hash"
:
CC
=
os
.
path
.
join
(
clang_path
,
"build/wrappers/clang-hash-stop"
)
elif
self
.
mode
.
value
==
"ccache-clang-hash"
:
CC
=
os
.
path
.
join
(
clang_path
,
"build/wrappers/clang-ccache-hash-stop"
)
elif
self
.
mode
.
value
==
"ccache"
:
CC
=
os
.
path
.
join
(
clang_path
,
"build/wrappers/clang-ccache"
)
else
:
raise
RuntimeError
(
"Not a valid mode"
)
os
.
environ
[
'CC'
]
=
CC
self
.
CC
=
CC
def
call_configure
(
self
,
path
):
if
self
.
project_name
()
==
"postgresql"
:
shell
(
"cd %s; ./configure --enable-depend"
,
path
)
elif
self
.
project_name
()
in
(
"musl"
,
"cpython"
,
"bash"
,
"samba"
):
shell
(
"cd %s; ./configure"
,
path
)
elif
self
.
project_name
()
in
(
'mbedtls'
):
shell
(
"cd %s; cmake . -DCMAKE_C_COMPILER=$CC"
,
path
)
elif
self
.
project_name
()
in
(
'lua'
,):
# This is an ugly hack to make it possible to override the
# CC variable from the outsite.
with
open
(
"%s/makefile"
%
path
)
as
fd
:
content
=
fd
.
readlines
()
for
i
in
range
(
0
,
len
(
content
)):
if
content
[
i
].
startswith
(
"CC"
):
content
[
i
]
=
"
\n
"
with
open
(
"%s/makefile"
%
path
,
"w"
)
as
fd
:
fd
.
write
(
""
.
join
(
content
))
else
:
raise
RuntimeError
(
"Not a valid project"
)
def
call_make
(
self
,
path
):
return
shell
(
"cd %s; make -j %s"
,
path
,
str
(
self
.
jobs
.
value
))
def
rebuild
(
self
,
path
,
info
,
fail_ok
=
False
):
# Recompile!
start_time
=
time
.
time
()
try
:
ret
=
self
.
call_make
(
path
)
except
CommandFailed
as
e
:
if
not
fail_ok
:
raise
else
:
info
[
'failed'
]
=
True
ret
=
(
""
,
1
)
end_time
=
time
.
time
()
# Account only nano seconds, everywhere
build_time
=
int
((
end_time
-
start_time
)
*
1e9
)
info
[
'build-time'
]
=
build_time
logging
.
info
(
"Rebuild done[%s]: %s s; failed=%s"
,
info
.
get
(
"filename"
)
or
info
.
get
(
"commit"
),
build_time
/
1e9
,
info
.
get
(
"failed"
,
False
))
return
info
Write
Preview
Supports
Markdown
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