Commit e8ee98e669c25d0b8e67cdaace9a6b7e49c7a0c0

Werner Lemberg 2020-09-25T07:22:08

Move `scripts/make_distribution_archives.py` to `src/tools`. * scr/tools/scripts/make_distribution_archives.py: (_TOP_DIR, _SCRIPT_DIR): Updated to new location. (main): s/shutils.copyfile/shutils.copy/ to preserve file permissions. (main): Prefix source file paths with `git_dir` while copying files to allow calls of the script from other places than the top-level directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
diff --git a/ChangeLog b/ChangeLog
index 8ce3662..c7d074b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2020-09-25  Werner Lemberg  <wl@gnu.org>
+
+	Move `scripts/make_distribution_archives.py` to `src/tools`.
+
+	* scr/tools/scripts/make_distribution_archives.py: (_TOP_DIR,
+	_SCRIPT_DIR): Updated to new location.
+	(main): s/shutils.copyfile/shutils.copy/ to preserve file
+	permissions.
+	(main): Prefix source file paths with `git_dir` while copying files
+	to allow calls of the script from other places than the top-level
+	directory.
+
 2020-09-24  Werner Lemberg  <wl@gnu.org>
 
 	* src/cff/cffgload.c (cff_slot_load): Scale `vertBearingY`.
diff --git a/scripts/make_distribution_archives.py b/scripts/make_distribution_archives.py
deleted file mode 100755
index f0ffe81..0000000
--- a/scripts/make_distribution_archives.py
+++ /dev/null
@@ -1,208 +0,0 @@
-#!/usr/bin/env python3
-"""Generate distribution archives for a given FreeType 2 release."""
-
-from __future__ import print_function
-
-import argparse
-import atexit
-import os
-import shutil
-import subprocess
-import sys
-import tempfile
-
-_SCRIPT_DIR = os.path.dirname(__file__)
-_TOP_DIR = os.path.abspath(os.path.join(_SCRIPT_DIR, ".."))
-
-
-def get_cmd_output(cmd, cwd=None):
-    """Run a command and return its output as a string."""
-    if cwd is not None:
-        out = subprocess.check_output(cmd, cwd=cwd)
-    else:
-        out = subprocess.check_output(cmd)
-    return out.decode("utf-8").rstrip()
-
-
-def is_git_dir_clean(git_dir):
-    """Return True iff |git_dir| is a git directory in clean state."""
-    out = get_cmd_output(["git", "status", "--porcelain"], cwd=git_dir)
-    return len(out) == 0
-
-
-def main():
-    parser = argparse.ArgumentParser(description=__doc__)
-
-    parser.add_argument(
-        "--source_dir", default=_TOP_DIR, help="Source directory path."
-    )
-
-    parser.add_argument(
-        "--version",
-        help=(
-            "Specify alternate FreeType version (it is otherwise extracted"
-            " from current sources by default)."
-        ),
-    )
-
-    parser.add_argument(
-        "--gnu-config-dir",
-        help=(
-            "Path of input directory containing recent `config.guess` and"
-            " `config.sub` files from GNU config."
-        ),
-    )
-
-    parser.add_argument(
-        "--build-dir",
-        help="Specify build directory. Only used for debugging this script.",
-    )
-
-    parser.add_argument(
-        "--ignore-clean-check",
-        action="store_true",
-        help=(
-            "Do not check for a clean source git repository. Only used for"
-            " debugging this script."
-        ),
-    )
-
-    parser.add_argument(
-        "output_dir", help="Output directory for generated archives."
-    )
-
-    args = parser.parse_args()
-
-    git_dir = args.source_dir if args.source_dir else _TOP_DIR
-    if not args.ignore_clean_check and not is_git_dir_clean(git_dir):
-        sys.stderr.write(
-            "ERROR: Your git repository is not in a clean state: %s\n"
-            % git_dir
-        )
-        return 1
-
-    if args.version:
-        version = args.version
-    else:
-        # Extract FreeType version from sources.
-        version = get_cmd_output(
-            [
-                sys.executable,
-                os.path.join(_SCRIPT_DIR, "extract_freetype_version.py"),
-                os.path.join(_TOP_DIR, "include", "freetype", "freetype.h"),
-            ]
-        )
-
-    # Determine the build directory. This will be a temporary file that is
-    # cleaned up on script exit by default, unless --build-dir=DIR is used,
-    # in which case we only create and empty the directory, but never remove
-    # its content on exit.
-    if args.build_dir:
-        build_dir = args.build_dir
-        if not os.path.exists(build_dir):
-            os.makedirs(build_dir)
-        else:
-            # Remove anything from the build directory, if any.
-            for item in os.listdir(build_dir):
-                file_path = os.path.join(build_dir, item)
-                if os.path.isdir(file_path):
-                    shutil.rmtree(file_path)
-                else:
-                    os.unlink(file_path)
-    else:
-        # Create a temporary directory, and ensure it is removed on exit.
-        build_dir = tempfile.mkdtemp(prefix="freetype-dist-")
-
-        def clean_build_dir():
-            shutil.rmtree(build_dir)
-
-        atexit.register(clean_build_dir)
-
-    # Copy all source files known to git into $BUILD_DIR/freetype-$VERSION
-    # with the exception of .gitignore and .mailmap files.
-    source_files = [
-        f
-        for f in get_cmd_output(["git", "ls-files"], cwd=git_dir).split("\n")
-        if os.path.basename(f) not in (".gitignore", ".mailmap")
-    ]
-
-    freetype_dir = "freetype-" + version
-    tmp_src_dir = os.path.join(build_dir, freetype_dir)
-    os.makedirs(tmp_src_dir)
-
-    for src in source_files:
-        dst = os.path.join(tmp_src_dir, src)
-        dst_dir = os.path.dirname(dst)
-        if not os.path.exists(dst_dir):
-            os.makedirs(dst_dir)
-        shutil.copyfile(src, dst)
-
-    # Run autogen.sh in directory.
-    subprocess.check_call(["/bin/sh", "autogen.sh"], cwd=tmp_src_dir)
-    shutil.rmtree(
-        os.path.join(tmp_src_dir, "builds", "unix", "autom4te.cache")
-    )
-
-    # Copy config.guess and config.sub if possible!
-    if args.gnu_config_dir:
-        for f in ("config.guess", "config.sub"):
-            shutil.copyfile(
-                os.path.join(args.gnu_config_dir, f),
-                os.path.join(tmp_src_dir, "builds", "unix", f),
-            )
-
-    # Generate reference documentation under docs/
-    subprocess.check_call(
-        [
-            sys.executable,
-            os.path.join(_SCRIPT_DIR, "generate_reference_docs.py"),
-            "--input-dir",
-            tmp_src_dir,
-            "--version",
-            version,
-            "--output-dir",
-            os.path.join(tmp_src_dir, "docs"),
-        ]
-    )
-
-    shutil.rmtree(os.path.join(tmp_src_dir, "docs", "markdown"))
-    os.unlink(os.path.join(tmp_src_dir, "docs", "mkdocs.yml"))
-
-    # Generate our archives
-    freetype_tar = freetype_dir + ".tar"
-
-    subprocess.check_call(
-        ["tar", "-H", "ustar", "-chf", freetype_tar, freetype_dir],
-        cwd=build_dir,
-    )
-
-    subprocess.check_call(
-        ["gzip", "-9", "--keep", freetype_tar], cwd=build_dir
-    )
-
-    subprocess.check_call(["xz", "--keep", freetype_tar], cwd=build_dir)
-
-    ftwinversion = "ft" + "".join(version.split("."))
-    subprocess.check_call(
-        ["zip", "-qlr9", ftwinversion + ".zip", freetype_dir], cwd=build_dir
-    )
-
-    # Copy file to output directory now.
-    if not os.path.exists(args.output_dir):
-        os.makedirs(args.output_dir)
-
-    for f in (
-        freetype_tar + ".gz",
-        freetype_tar + ".xz",
-        ftwinversion + ".zip",
-    ):
-        shutil.copyfile(
-            os.path.join(build_dir, f), os.path.join(args.output_dir, f)
-        )
-
-    # Done!
-    return 0
-
-
-if __name__ == "__main__":
-    sys.exit(main())
diff --git a/src/tools/make_distribution_archives.py b/src/tools/make_distribution_archives.py
new file mode 100755
index 0000000..f29eb12
--- /dev/null
+++ b/src/tools/make_distribution_archives.py
@@ -0,0 +1,208 @@
+#!/usr/bin/env python3
+"""Generate distribution archives for a given FreeType 2 release."""
+
+from __future__ import print_function
+
+import argparse
+import atexit
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
+
+_TOP_DIR = os.path.abspath(os.path.join(__file__, "..", "..", ".."))
+_SCRIPT_DIR = os.path.dirname(os.path.join(_TOP_DIR, "builds", "meson", ""))
+
+
+def get_cmd_output(cmd, cwd=None):
+    """Run a command and return its output as a string."""
+    if cwd is not None:
+        out = subprocess.check_output(cmd, cwd=cwd)
+    else:
+        out = subprocess.check_output(cmd)
+    return out.decode("utf-8").rstrip()
+
+
+def is_git_dir_clean(git_dir):
+    """Return True iff |git_dir| is a git directory in clean state."""
+    out = get_cmd_output(["git", "status", "--porcelain"], cwd=git_dir)
+    return len(out) == 0
+
+
+def main():
+    parser = argparse.ArgumentParser(description=__doc__)
+
+    parser.add_argument(
+        "--source_dir", default=_TOP_DIR, help="Source directory path."
+    )
+
+    parser.add_argument(
+        "--version",
+        help=(
+            "Specify alternate FreeType version (it is otherwise extracted"
+            " from current sources by default)."
+        ),
+    )
+
+    parser.add_argument(
+        "--gnu-config-dir",
+        help=(
+            "Path of input directory containing recent `config.guess` and"
+            " `config.sub` files from GNU config."
+        ),
+    )
+
+    parser.add_argument(
+        "--build-dir",
+        help="Specify build directory. Only used for debugging this script.",
+    )
+
+    parser.add_argument(
+        "--ignore-clean-check",
+        action="store_true",
+        help=(
+            "Do not check for a clean source git repository. Only used for"
+            " debugging this script."
+        ),
+    )
+
+    parser.add_argument(
+        "output_dir", help="Output directory for generated archives."
+    )
+
+    args = parser.parse_args()
+
+    git_dir = args.source_dir if args.source_dir else _TOP_DIR
+    if not args.ignore_clean_check and not is_git_dir_clean(git_dir):
+        sys.stderr.write(
+            "ERROR: Your git repository is not in a clean state: %s\n"
+            % git_dir
+        )
+        return 1
+
+    if args.version:
+        version = args.version
+    else:
+        # Extract FreeType version from sources.
+        version = get_cmd_output(
+            [
+                sys.executable,
+                os.path.join(_SCRIPT_DIR, "extract_freetype_version.py"),
+                os.path.join(_TOP_DIR, "include", "freetype", "freetype.h"),
+            ]
+        )
+
+    # Determine the build directory. This will be a temporary file that is
+    # cleaned up on script exit by default, unless --build-dir=DIR is used,
+    # in which case we only create and empty the directory, but never remove
+    # its content on exit.
+    if args.build_dir:
+        build_dir = args.build_dir
+        if not os.path.exists(build_dir):
+            os.makedirs(build_dir)
+        else:
+            # Remove anything from the build directory, if any.
+            for item in os.listdir(build_dir):
+                file_path = os.path.join(build_dir, item)
+                if os.path.isdir(file_path):
+                    shutil.rmtree(file_path)
+                else:
+                    os.unlink(file_path)
+    else:
+        # Create a temporary directory, and ensure it is removed on exit.
+        build_dir = tempfile.mkdtemp(prefix="freetype-dist-")
+
+        def clean_build_dir():
+            shutil.rmtree(build_dir)
+
+        atexit.register(clean_build_dir)
+
+    # Copy all source files known to git into $BUILD_DIR/freetype-$VERSION
+    # with the exception of .gitignore and .mailmap files.
+    source_files = [
+        f
+        for f in get_cmd_output(["git", "ls-files"], cwd=git_dir).split("\n")
+        if os.path.basename(f) not in (".gitignore", ".mailmap")
+    ]
+
+    freetype_dir = "freetype-" + version
+    tmp_src_dir = os.path.join(build_dir, freetype_dir)
+    os.makedirs(tmp_src_dir)
+
+    for src in source_files:
+        dst = os.path.join(tmp_src_dir, src)
+        dst_dir = os.path.dirname(dst)
+        if not os.path.exists(dst_dir):
+            os.makedirs(dst_dir)
+        shutil.copy(os.path.join(git_dir, src), dst)
+
+    # Run autogen.sh in directory.
+    subprocess.check_call(["/bin/sh", "autogen.sh"], cwd=tmp_src_dir)
+    shutil.rmtree(
+        os.path.join(tmp_src_dir, "builds", "unix", "autom4te.cache")
+    )
+
+    # Copy config.guess and config.sub if possible!
+    if args.gnu_config_dir:
+        for f in ("config.guess", "config.sub"):
+            shutil.copy(
+                os.path.join(args.gnu_config_dir, f),
+                os.path.join(tmp_src_dir, "builds", "unix", f),
+            )
+
+    # Generate reference documentation under docs/
+    subprocess.check_call(
+        [
+            sys.executable,
+            os.path.join(_SCRIPT_DIR, "generate_reference_docs.py"),
+            "--input-dir",
+            tmp_src_dir,
+            "--version",
+            version,
+            "--output-dir",
+            os.path.join(tmp_src_dir, "docs"),
+        ]
+    )
+
+    shutil.rmtree(os.path.join(tmp_src_dir, "docs", "markdown"))
+    os.unlink(os.path.join(tmp_src_dir, "docs", "mkdocs.yml"))
+
+    # Generate our archives
+    freetype_tar = freetype_dir + ".tar"
+
+    subprocess.check_call(
+        ["tar", "-H", "ustar", "-chf", freetype_tar, freetype_dir],
+        cwd=build_dir,
+    )
+
+    subprocess.check_call(
+        ["gzip", "-9", "--keep", freetype_tar], cwd=build_dir
+    )
+
+    subprocess.check_call(["xz", "--keep", freetype_tar], cwd=build_dir)
+
+    ftwinversion = "ft" + "".join(version.split("."))
+    subprocess.check_call(
+        ["zip", "-qlr9", ftwinversion + ".zip", freetype_dir], cwd=build_dir
+    )
+
+    # Copy file to output directory now.
+    if not os.path.exists(args.output_dir):
+        os.makedirs(args.output_dir)
+
+    for f in (
+        freetype_tar + ".gz",
+        freetype_tar + ".xz",
+        ftwinversion + ".zip",
+    ):
+        shutil.copy(
+            os.path.join(build_dir, f), os.path.join(args.output_dir, f)
+        )
+
+    # Done!
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())