1- import shutil
21import sys
32from argparse import ArgumentParser
43from pathlib import Path
54from typing import Any
65
76from ..cli .utils import check_dir_path , dir_path
8- from .config import KBUILD_DIR , PROJECT_FILE_NAME
7+ from .config import DIST_DIR_NAME , PROJECT_FILE_NAME
98from .kbuild import KBuild
10- from .package import Package
9+ from .project import Project
1110from .utils import find_file_upwards
1211
1312
1413def main () -> None :
1514 args = vars (_argument_parser ().parse_args ())
1615 command = args ['command' ]
1716
18- if command == 'clean' :
19- return do_clean (** args )
20-
2117 if command == 'kompile' :
2218 return do_kompile (** args )
2319
@@ -35,38 +31,52 @@ def _argument_parser() -> ArgumentParser:
3531
3632 command_parser = parser .add_subparsers (dest = 'command' , metavar = 'COMMAND' , required = True )
3733
38- command_parser .add_parser ('clean' , help = 'clean build cache' )
39-
4034 kompile_parser = command_parser .add_parser ('kompile' , help = 'kompile target' )
4135 kompile_parser .add_argument ('target_name' , metavar = 'TARGET' , help = 'target to build' )
36+ kompile_parser .add_argument (
37+ '-o' ,
38+ '--output' ,
39+ dest = 'output_dir' ,
40+ metavar = 'OUTPUT' ,
41+ type = Path ,
42+ help = 'output directory' ,
43+ )
4244
4345 which_parser = command_parser .add_parser ('which' , help = 'print definition directory for target' )
4446 which_parser .add_argument ('target_name' , metavar = 'TARGET' , help = 'target to print definition directory for' )
47+ which_parser .add_argument (
48+ '-o' ,
49+ '--output' ,
50+ dest = 'output_dir' ,
51+ metavar = 'OUTPUT' ,
52+ type = Path ,
53+ help = 'output directory' ,
54+ )
4555
4656 return parser
4757
4858
49- def _package (start_dir : Path ) -> Package :
50- project_file = find_file_upwards (PROJECT_FILE_NAME , start_dir )
51- return Package .create (project_file )
52-
59+ def _project_file (start_dir : Path ) -> Path :
60+ return find_file_upwards (PROJECT_FILE_NAME , start_dir )
5361
54- def do_clean (** kwargs : Any ) -> None :
55- shutil .rmtree (KBUILD_DIR , ignore_errors = True )
5662
63+ def do_kompile (start_dir : Path , target_name : str , output_dir : Path | None , ** kwargs : Any ) -> None :
64+ project_file = _project_file (start_dir )
65+ project = Project .load (project_file )
66+ kdist_dir = output_dir or project_file .parent / DIST_DIR_NAME
67+ kbuild = KBuild (kdist_dir )
5768
58- def do_kompile (start_dir : Path , target_name : str , ** kwargs : Any ) -> None :
59- package = _package (start_dir )
60- kbuild = KBuild ()
61- definition_dir = kbuild .kompile (package , target_name )
69+ definition_dir = kbuild .kompile (project , target_name )
6270 print (definition_dir )
6371
6472
65- def do_which (start_dir : Path , target_name : str , ** kwargs : Any ) -> None :
66- package = _package (start_dir )
67- kbuild = KBuild ()
68- definition_dir = kbuild .definition_dir (package , target_name )
73+ def do_which (start_dir : Path , target_name : str , output_dir : Path | None , ** kwargs : Any ) -> None :
74+ project_file = _project_file (start_dir )
75+ project = Project .load (project_file )
76+ kdist_dir = output_dir or project_file .parent / DIST_DIR_NAME
77+ kbuild = KBuild (kdist_dir )
6978
79+ definition_dir = kbuild .definition_dir (project , target_name )
7080 try :
7181 check_dir_path (definition_dir )
7282 except ValueError as e :
0 commit comments