2016-02-19 14:41:16 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import os
|
2016-06-06 08:55:13 +00:00
|
|
|
import sys
|
2016-02-19 14:41:16 +00:00
|
|
|
import tarfile
|
2016-06-06 08:55:13 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
# In GN we expect the path to a stamp file as an argument.
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
STAMP_FILE = os.path.abspath(sys.argv[1])
|
2016-02-19 14:41:16 +00:00
|
|
|
|
|
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
[Swarming] work around slow calls in archive.py
Apparently, the tarfile Python module spends a lot of time in
grp.getgrid for retrieving a piece information (the name of the
primary group) which we don't need anyway. There is no
proper way to disable these slow calls, but there's a workaround
which relies on the way in which grp (and pwd) is used.
In fact, pwd and grp are imported in this fashion:
try:
import grp, pwd
except ImportError:
grp = pwd = None
and then used with the following pattern [2]:
if grp:
try:
tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
except KeyError:
pass
By setting grp and pwd to None, thus skipping the calls, I was
able to achieve a 35x speedup on my workstation.
The user and group names are set to test262 when building the tar.
The downside to this approach is that we are relying on an
implementation detail, which is not in the public API.
However, the blamelist shows that the relevant bits of the module
have not been updated since 2003 [3], so we might as well assume
that the workaround will keep working, on cPython 2.x at least.
---
[1] https://hg.python.org/cpython/file/2.7/Lib/tarfile.py#l56
[2] https://hg.python.org/cpython/file/2.7/Lib/tarfile.py#l1933
[3] https://hg.python.org/cpython/rev/f9a5ed092660
BUG=chromium:535160
LOG=N
Review URL: https://codereview.chromium.org/1727773002
Cr-Commit-Position: refs/heads/master@{#34245}
2016-02-24 11:04:01 +00:00
|
|
|
# Workaround for slow grp and pwd calls.
|
|
|
|
tarfile.grp = None
|
|
|
|
tarfile.pwd = None
|
|
|
|
|
2016-02-19 14:41:16 +00:00
|
|
|
def filter_git(tar_info):
|
2016-07-22 15:25:06 +00:00
|
|
|
if tar_info.name.startswith(os.path.join('data', '.git')) or \
|
|
|
|
tar_info.name.startswith(os.path.join('harness', '.git')):
|
2016-02-19 14:41:16 +00:00
|
|
|
return None
|
|
|
|
else:
|
[Swarming] work around slow calls in archive.py
Apparently, the tarfile Python module spends a lot of time in
grp.getgrid for retrieving a piece information (the name of the
primary group) which we don't need anyway. There is no
proper way to disable these slow calls, but there's a workaround
which relies on the way in which grp (and pwd) is used.
In fact, pwd and grp are imported in this fashion:
try:
import grp, pwd
except ImportError:
grp = pwd = None
and then used with the following pattern [2]:
if grp:
try:
tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
except KeyError:
pass
By setting grp and pwd to None, thus skipping the calls, I was
able to achieve a 35x speedup on my workstation.
The user and group names are set to test262 when building the tar.
The downside to this approach is that we are relying on an
implementation detail, which is not in the public API.
However, the blamelist shows that the relevant bits of the module
have not been updated since 2003 [3], so we might as well assume
that the workaround will keep working, on cPython 2.x at least.
---
[1] https://hg.python.org/cpython/file/2.7/Lib/tarfile.py#l56
[2] https://hg.python.org/cpython/file/2.7/Lib/tarfile.py#l1933
[3] https://hg.python.org/cpython/rev/f9a5ed092660
BUG=chromium:535160
LOG=N
Review URL: https://codereview.chromium.org/1727773002
Cr-Commit-Position: refs/heads/master@{#34245}
2016-02-24 11:04:01 +00:00
|
|
|
tar_info.uname = tar_info.gname = "test262"
|
2016-02-19 14:41:16 +00:00
|
|
|
return tar_info
|
|
|
|
|
|
|
|
with tarfile.open('data.tar', 'w') as tar:
|
|
|
|
tar.add('data', filter=filter_git)
|
2016-07-22 15:25:06 +00:00
|
|
|
tar.add('harness', filter=filter_git)
|
2016-06-06 08:55:13 +00:00
|
|
|
|
|
|
|
# Workaround for GN. We can't specify the tarfile as output because it's
|
|
|
|
# not in the product directory. Therefore we track running of this script
|
|
|
|
# with an extra stamp file in the product directory.
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
with open(STAMP_FILE, 'w') as f:
|
|
|
|
f.write(str(time.time()))
|