2"""Generate distribution archives for a given FreeType 2 release."""
4from __future__
import print_function
14_TOP_DIR = os.path.abspath(os.path.join(__file__,
"..",
"..",
".."))
15_SCRIPT_DIR = os.path.dirname(os.path.join(_TOP_DIR,
"builds",
"meson",
""))
19 """Run a command and return its output as a string."""
21 out = subprocess.check_output(cmd, cwd=cwd)
23 out = subprocess.check_output(cmd)
24 return out.decode(
"utf-8").rstrip()
28 """Return True iff |git_dir| is a git directory in clean state."""
29 out =
get_cmd_output([
"git",
"status",
"--porcelain"], cwd=git_dir)
34 parser = argparse.ArgumentParser(description=__doc__)
37 "--source_dir", default=_TOP_DIR, help=
"Source directory path."
43 "Specify alternate FreeType version (it is otherwise extracted"
44 " from current sources by default)."
51 "Path of input directory containing recent `config.guess` and"
52 " `config.sub` files from GNU config."
58 help=
"Specify build directory. Only used for debugging this script.",
62 "--ignore-clean-check",
65 "Do not check for a clean source git repository. Only used for"
66 " debugging this script."
71 "output_dir", help=
"Output directory for generated archives."
74 args = parser.parse_args()
76 git_dir = args.source_dir
if args.source_dir
else _TOP_DIR
79 "ERROR: Your git repository is not in a clean state: %s\n"
85 version = args.version
91 os.path.join(_SCRIPT_DIR,
"extract_freetype_version.py"),
92 os.path.join(_TOP_DIR,
"include",
"freetype",
"freetype.h"),
101 build_dir = args.build_dir
102 if not os.path.exists(build_dir):
103 os.makedirs(build_dir)
106 for item
in os.listdir(build_dir):
107 file_path = os.path.join(build_dir, item)
108 if os.path.isdir(file_path):
109 shutil.rmtree(file_path)
114 build_dir = tempfile.mkdtemp(prefix=
"freetype-dist-")
116 def clean_build_dir():
117 shutil.rmtree(build_dir)
119 atexit.register(clean_build_dir)
125 for f
in get_cmd_output([
"git",
"ls-files"], cwd=git_dir).split(
"\n")
126 if os.path.basename(f)
not in (
".gitignore",
".mailmap")
129 freetype_dir =
"freetype-" + version
130 tmp_src_dir = os.path.join(build_dir, freetype_dir)
131 os.makedirs(tmp_src_dir)
133 for src
in source_files:
134 dst = os.path.join(tmp_src_dir, src)
135 dst_dir = os.path.dirname(dst)
136 if not os.path.exists(dst_dir):
138 shutil.copy(os.path.join(git_dir, src), dst)
141 subprocess.check_call([
"/bin/sh",
"autogen.sh"], cwd=tmp_src_dir)
143 os.path.join(tmp_src_dir,
"builds",
"unix",
"autom4te.cache")
147 if args.gnu_config_dir:
148 for f
in (
"config.guess",
"config.sub"):
150 os.path.join(args.gnu_config_dir, f),
151 os.path.join(tmp_src_dir,
"builds",
"unix", f),
155 subprocess.check_call(
158 os.path.join(_SCRIPT_DIR,
"generate_reference_docs.py"),
164 os.path.join(tmp_src_dir,
"docs"),
168 shutil.rmtree(os.path.join(tmp_src_dir,
"docs",
"markdown"))
169 os.unlink(os.path.join(tmp_src_dir,
"docs",
"mkdocs.yml"))
172 freetype_tar = freetype_dir +
".tar"
174 subprocess.check_call(
175 [
"tar",
"-H",
"ustar",
"-chf", freetype_tar, freetype_dir],
179 subprocess.check_call(
180 [
"gzip",
"-9",
"--keep", freetype_tar], cwd=build_dir
183 subprocess.check_call([
"xz",
"--keep", freetype_tar], cwd=build_dir)
185 ftwinversion =
"ft" +
"".join(version.split(
"."))
186 subprocess.check_call(
187 [
"zip",
"-qlr9", ftwinversion +
".zip", freetype_dir], cwd=build_dir
191 if not os.path.exists(args.output_dir):
192 os.makedirs(args.output_dir)
195 freetype_tar +
".gz",
196 freetype_tar +
".xz",
197 ftwinversion +
".zip",
200 os.path.join(build_dir, f), os.path.join(args.output_dir, f)
207if __name__ ==
"__main__":
get_cmd_output(cmd, cwd=None)
is_git_dir_clean(git_dir)