Skip to content

Commit 48608bc

Browse files
committed
Always taring WITH_JDK by python, patch tarinfo in python taring
commit_hash:34dbae394624660e81ae61f12d5b87569025cdda
1 parent 17e4756 commit 48608bc

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

build/conf/java.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ macro WITH_JDK() {
19281928
_OK=no
19291929
}
19301930
otherwise {
1931-
_PACK_JDK= && ${YMAKE_PYTHON3} ${input:"build/scripts/tar_directory.py"} --exclude "resource_info.json" --exclude "INSTALLED" --exclude "lnk" ${tared;output:"jdk.tar"} $WITH_JDK_RESOURCE $WITH_JDK_RESOURCE
1931+
_PACK_JDK= && ${YMAKE_PYTHON3} ${input:"build/scripts/tar_directory.py"} --tar-by-py --exclude "resource_info.json" --exclude "INSTALLED" --exclude "lnk" ${tared;output:"jdk.tar"} $WITH_JDK_RESOURCE $WITH_JDK_RESOURCE
19321932
WITH_JDK_VALUE=yes
19331933
}
19341934
ASSERT(_OK [[alt1]]jdk[[rst]] name is prohibited for [[imp]]JAVA_PROGRAM[[rst]] module when [[imp]]WITH_JDK[[rst]] is used, [[imp]]WITH_JDK[[rst]] will be ignored.)

build/scripts/tar_directory.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
import argparse
33
import tarfile
44
import subprocess
5+
import stat
56

67

7-
def is_exe(fpath):
8+
def is_exe(fpath: str) -> bool:
89
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
910

1011

1112
def _usage() -> str:
1213
return "\n".join(
1314
[
1415
"Usage:",
15-
f"`tar_directory.py archive.tar directory [skip prefix] [--exclude fileOrDir0 ... --exclude fileOrDirN]`",
16+
f"`tar_directory.py [--tar-by-py] [--exclude fileOrDir0 ... --exclude fileOrDirN] archive.tar directory [skip prefix]`",
1617
"or",
17-
f"`tar_directory.py archive.tar output_directory --extract`",
18+
f"`tar_directory.py [--tar-by-py] --extract archive.tar output_directory`",
1819
]
1920
)
2021

2122

2223
def main():
2324
parser = argparse.ArgumentParser(description='Make or extract tar archive')
2425
parser.add_argument('--extract', action="store_true", default=False, help="Extract archive")
26+
parser.add_argument('--tar-by-py', action="store_true", default=False, help="Force use taring by python")
2527
parser.add_argument(
2628
'--exclude', type=str, action='append', default=[], help="Exclude for create archive (can use multiply times)"
2729
)
@@ -42,14 +44,16 @@ def main():
4244
directory = args.directory
4345
prefix = args.prefix
4446

45-
for tar_exe in ('/usr/bin/tar', '/bin/tar'):
47+
if args.extract:
48+
dest = os.path.abspath(directory)
49+
if not os.path.exists(dest):
50+
os.makedirs(dest)
51+
52+
for tar_exe in ('/usr/bin/tar', '/bin/tar') if not args.tar_by_py else []:
4653
if not is_exe(tar_exe):
4754
continue
4855
if args.extract:
49-
dest = os.path.abspath(directory)
50-
if not os.path.exists(dest):
51-
os.makedirs(dest)
52-
os.execv(tar_exe, [tar_exe, '-xf', tar, '-C', dest])
56+
command = [tar_exe, '-xf', tar, '-C', dest]
5357
else:
5458
source = os.path.relpath(directory, prefix) if prefix else directory
5559
command = (
@@ -59,29 +63,39 @@ def main():
5963
+ (['-C', prefix] if prefix else [])
6064
+ [source]
6165
)
62-
subprocess.run(command, check=True)
66+
subprocess.run(command, check=True)
6367
break
6468
else:
6569
if args.extract:
66-
dest = os.path.abspath(directory)
67-
if not os.path.exists(dest):
68-
os.makedirs(dest)
6970
with tarfile.open(tar, 'r') as tar_file:
7071
tar_file.extractall(dest)
7172
else:
7273
source = directory
7374
with tarfile.open(tar, 'w') as out:
7475

75-
def filter(tarinfo):
76-
for exclude in args.exclude:
77-
if tarinfo.name.endswith(exclude):
78-
return None
76+
def filter(tarinfo: tarfile.TarInfo):
77+
if args.exclude:
78+
for exclude in args.exclude:
79+
if tarinfo.name.endswith(exclude):
80+
return None
81+
tarinfo.mode = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if tarinfo.mode | stat.S_IXUSR else 0
82+
tarinfo.mode = (
83+
tarinfo.mode | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH
84+
)
85+
# Set mtime to 1970-01-01 00:00:01, else if mtime == 0
86+
# it not used here https://a.yandex-team.ru/arcadia/contrib/python/python-libarchive/py3/libarchive/__init__.py#L355
87+
# But mtime != 0 also ignored by libarchive too :((
88+
tarinfo.mtime = 1
89+
tarinfo.uid = 0
90+
tarinfo.gid = 0
91+
tarinfo.uname = 'dummy'
92+
tarinfo.gname = 'dummy'
7993
return tarinfo
8094

8195
out.add(
8296
os.path.abspath(source),
8397
arcname=os.path.relpath(source, prefix) if prefix else source,
84-
filter=filter if args.exclude else None,
98+
filter=filter,
8599
)
86100

87101

0 commit comments

Comments
 (0)