Skip to content

Commit

Permalink
[fontc] Add --experimental-single-source flag
Browse files Browse the repository at this point in the history
This instructs gftools to only build the single named source file.
  • Loading branch information
cmyr committed Oct 25, 2024
1 parent fff69cd commit 890dec9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Lib/gftools/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from os import chdir
from pathlib import Path
from tempfile import NamedTemporaryFile, gettempdir
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Tuple, Union

from gftools.builder.fontc import FontcArgs
import networkx as nx
Expand Down Expand Up @@ -401,6 +401,12 @@ def main(args=None):
type=Path,
)

parser.add_argument(
"--experimental-single-source",
help="only compile the single named source file",
type=str,
)

parser.add_argument("config", help="Path to config file or source file", nargs="+")
args = parser.parse_args(args)
fontc_args = FontcArgs(args)
Expand Down
10 changes: 10 additions & 0 deletions Lib/gftools/builder/fontc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
class FontcArgs:
simple_output_path: Union[Path, None]
fontc_bin_path: Union[Path, None]
single_source: Union[str, None]

# init with 'None' returns a default obj where everything is None
def __init__(self, args: Union[Namespace, None]) -> None:
if not args:
return None
self.simple_output_path = abspath(args.experimental_simple_output)
self.fontc_bin_path = abspath(args.experimental_fontc)
self.single_source = args.experimental_single_source
if self.fontc_bin_path:
if not self.fontc_bin_path.is_file():
raise ValueError(f"fontc does not exist at {self.fontc_bin_path}")
Expand Down Expand Up @@ -51,6 +53,14 @@ def modify_config(self, config: dict):
config["outputDir"] = str(output_dir)
config["ttDir"] = str(output_dir)
config["otDir"] = str(output_dir)
if self.single_source:
filtered_sources = [s for s in config["sources"] if self.single_source in s]
n_sources = len(filtered_sources)
if n_sources != 1:
raise ValueError(
f"--exerimental-single-source {self.single_source} must match exactly one of {config['sources']} (matched {n_sources}) "
)
config["sources"] = filtered_sources


def abspath(path: Union[Path, None]) -> Union[Path, None]:
Expand Down

0 comments on commit 890dec9

Please sign in to comment.