Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
456fc2b5
Commit
456fc2b5
authored
Jan 19, 2016
by
Thomas Amland
Browse files
add python 3 support to fuse_gtest_files script
parent
d404af0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
googletest/scripts/fuse_gtest_files.py
googletest/scripts/fuse_gtest_files.py
+18
-15
No files found.
googletest/scripts/fuse_gtest_files.py
View file @
456fc2b5
...
@@ -60,7 +60,10 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
...
@@ -60,7 +60,10 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
os
import
re
import
re
import
sets
try
:
from
sets
import
Set
as
set
# For Python 2.3 compatibility
except
ImportError
:
pass
import
sys
import
sys
# We assume that this file is in the scripts/ directory in the Google
# We assume that this file is in the scripts/ directory in the Google
...
@@ -90,10 +93,10 @@ def VerifyFileExists(directory, relative_path):
...
@@ -90,10 +93,10 @@ def VerifyFileExists(directory, relative_path):
"""
"""
if
not
os
.
path
.
isfile
(
os
.
path
.
join
(
directory
,
relative_path
)):
if
not
os
.
path
.
isfile
(
os
.
path
.
join
(
directory
,
relative_path
)):
print
'ERROR: Cannot find %s in directory %s.'
%
(
relative_path
,
print
(
'ERROR: Cannot find %s in directory %s.'
%
(
relative_path
,
directory
)
directory
)
)
print
(
'Please either specify a valid project root directory '
print
(
'Please either specify a valid project root directory '
'or omit it on the command line.'
)
'or omit it on the command line.'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -119,11 +122,11 @@ def VerifyOutputFile(output_dir, relative_path):
...
@@ -119,11 +122,11 @@ def VerifyOutputFile(output_dir, relative_path):
# TODO(wan@google.com): The following user-interaction doesn't
# TODO(wan@google.com): The following user-interaction doesn't
# work with automated processes. We should provide a way for the
# work with automated processes. We should provide a way for the
# Makefile to force overwriting the files.
# Makefile to force overwriting the files.
print
(
'%s already exists in directory %s - overwrite it? (y/N) '
%
print
(
'%s already exists in directory %s - overwrite it? (y/N) '
%
(
relative_path
,
output_dir
))
(
relative_path
,
output_dir
))
answer
=
sys
.
stdin
.
readline
().
strip
()
answer
=
sys
.
stdin
.
readline
().
strip
()
if
answer
not
in
[
'y'
,
'Y'
]:
if
answer
not
in
[
'y'
,
'Y'
]:
print
'ABORTED.'
print
(
'ABORTED.'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
# Makes sure the directory holding the output file exists; creates
# Makes sure the directory holding the output file exists; creates
...
@@ -146,8 +149,8 @@ def ValidateOutputDir(output_dir):
...
@@ -146,8 +149,8 @@ def ValidateOutputDir(output_dir):
def
FuseGTestH
(
gtest_root
,
output_dir
):
def
FuseGTestH
(
gtest_root
,
output_dir
):
"""Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
"""Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
output_file
=
file
(
os
.
path
.
join
(
output_dir
,
GTEST_H_OUTPUT
),
'w'
)
output_file
=
open
(
os
.
path
.
join
(
output_dir
,
GTEST_H_OUTPUT
),
'w'
)
processed_files
=
set
s
.
Set
()
# Holds all gtest headers we've processed.
processed_files
=
set
()
# Holds all gtest headers we've processed.
def
ProcessFile
(
gtest_header_path
):
def
ProcessFile
(
gtest_header_path
):
"""Processes the given gtest header file."""
"""Processes the given gtest header file."""
...
@@ -159,7 +162,7 @@ def FuseGTestH(gtest_root, output_dir):
...
@@ -159,7 +162,7 @@ def FuseGTestH(gtest_root, output_dir):
processed_files
.
add
(
gtest_header_path
)
processed_files
.
add
(
gtest_header_path
)
# Reads each line in the given gtest header.
# Reads each line in the given gtest header.
for
line
in
file
(
os
.
path
.
join
(
gtest_root
,
gtest_header_path
),
'r'
):
for
line
in
open
(
os
.
path
.
join
(
gtest_root
,
gtest_header_path
),
'r'
):
m
=
INCLUDE_GTEST_FILE_REGEX
.
match
(
line
)
m
=
INCLUDE_GTEST_FILE_REGEX
.
match
(
line
)
if
m
:
if
m
:
# It's '#include "gtest/..."' - let's process it recursively.
# It's '#include "gtest/..."' - let's process it recursively.
...
@@ -175,7 +178,7 @@ def FuseGTestH(gtest_root, output_dir):
...
@@ -175,7 +178,7 @@ def FuseGTestH(gtest_root, output_dir):
def
FuseGTestAllCcToFile
(
gtest_root
,
output_file
):
def
FuseGTestAllCcToFile
(
gtest_root
,
output_file
):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
processed_files
=
set
s
.
Set
()
processed_files
=
set
()
def
ProcessFile
(
gtest_source_file
):
def
ProcessFile
(
gtest_source_file
):
"""Processes the given gtest source file."""
"""Processes the given gtest source file."""
...
@@ -187,7 +190,7 @@ def FuseGTestAllCcToFile(gtest_root, output_file):
...
@@ -187,7 +190,7 @@ def FuseGTestAllCcToFile(gtest_root, output_file):
processed_files
.
add
(
gtest_source_file
)
processed_files
.
add
(
gtest_source_file
)
# Reads each line in the given gtest source file.
# Reads each line in the given gtest source file.
for
line
in
file
(
os
.
path
.
join
(
gtest_root
,
gtest_source_file
),
'r'
):
for
line
in
open
(
os
.
path
.
join
(
gtest_root
,
gtest_source_file
),
'r'
):
m
=
INCLUDE_GTEST_FILE_REGEX
.
match
(
line
)
m
=
INCLUDE_GTEST_FILE_REGEX
.
match
(
line
)
if
m
:
if
m
:
if
'include/'
+
m
.
group
(
1
)
==
GTEST_SPI_H_SEED
:
if
'include/'
+
m
.
group
(
1
)
==
GTEST_SPI_H_SEED
:
...
@@ -218,7 +221,7 @@ def FuseGTestAllCcToFile(gtest_root, output_file):
...
@@ -218,7 +221,7 @@ def FuseGTestAllCcToFile(gtest_root, output_file):
def
FuseGTestAllCc
(
gtest_root
,
output_dir
):
def
FuseGTestAllCc
(
gtest_root
,
output_dir
):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
output_file
=
file
(
os
.
path
.
join
(
output_dir
,
GTEST_ALL_CC_OUTPUT
),
'w'
)
output_file
=
open
(
os
.
path
.
join
(
output_dir
,
GTEST_ALL_CC_OUTPUT
),
'w'
)
FuseGTestAllCcToFile
(
gtest_root
,
output_file
)
FuseGTestAllCcToFile
(
gtest_root
,
output_file
)
output_file
.
close
()
output_file
.
close
()
...
@@ -242,7 +245,7 @@ def main():
...
@@ -242,7 +245,7 @@ def main():
# fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
# fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
FuseGTest
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
FuseGTest
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
else
:
else
:
print
__doc__
print
(
__doc__
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
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