Compare commits
3 Commits
b045271a80
...
b9b66b096d
Author | SHA1 | Date | |
---|---|---|---|
b9b66b096d | |||
2e7626a67f | |||
7da8988205 |
@ -7,10 +7,45 @@
|
|||||||
import platform
|
import platform
|
||||||
import warnings
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple, Optional, Union
|
||||||
|
|
||||||
from lib_not_dr.types import Options, Version, VersionRequirement
|
from lib_not_dr.types import Options, Version, VersionRequirement
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_cmd_readable(cmd: str) -> str:
|
||||||
|
"""
|
||||||
|
保证 参数中 不含空格
|
||||||
|
:param cmd: 要格式化的命令行参数
|
||||||
|
:return: 格式化后的命令行参数
|
||||||
|
"""
|
||||||
|
if ' ' in cmd:
|
||||||
|
return f'"{cmd}"'
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
|
def format_cmd(arg_name: Optional[str] = None,
|
||||||
|
arg_value: Optional[Union[str, List[str]]] = None,
|
||||||
|
write: Optional[bool] = True) -> List[str]:
|
||||||
|
"""
|
||||||
|
用来格式化输出命令行参数
|
||||||
|
:param arg_name: 类似 --show-memory 之类的主项
|
||||||
|
:param arg_value: 类似 xxx 类的内容
|
||||||
|
:param write: 是否写入
|
||||||
|
:return: 直接拼接好的命令行参数 不带 =
|
||||||
|
"""
|
||||||
|
if not write:
|
||||||
|
return []
|
||||||
|
if arg_name is None:
|
||||||
|
return []
|
||||||
|
if arg_value is None:
|
||||||
|
return [arg_name]
|
||||||
|
if isinstance(arg_value, list):
|
||||||
|
arg_value = ','.join([ensure_cmd_readable(value) for value in arg_value])
|
||||||
|
return [f'{arg_name}{arg_value}']
|
||||||
|
arg_value = ensure_cmd_readable(arg_value)
|
||||||
|
return [f'{arg_name}{arg_value}']
|
||||||
|
|
||||||
|
|
||||||
def _add_cmd(cmd: List[str], string: Optional[str]) -> List[str]:
|
def _add_cmd(cmd: List[str], string: Optional[str]) -> List[str]:
|
||||||
if string is not None and string:
|
if string is not None and string:
|
||||||
cmd.append(string)
|
cmd.append(string)
|
||||||
@ -124,28 +159,30 @@ class CompilerHelper(Options):
|
|||||||
elif platform.system() == 'Linux':
|
elif platform.system() == 'Linux':
|
||||||
_add_cmd(cmd_list, f'--linux-icon={self.icon_path.absolute()}' if self.icon_path else None)
|
_add_cmd(cmd_list, f'--linux-icon={self.icon_path.absolute()}' if self.icon_path else None)
|
||||||
|
|
||||||
_add_cmd(cmd_list, '--lto=yes' if self.use_lto else '--lto=no')
|
cmd_list += format_cmd('lto=', 'yes' if self.use_lto else 'no')
|
||||||
_add_cmd(cmd_list, '--clang' if self.use_clang else None)
|
cmd_list += format_cmd('--clang' if self.use_clang else None)
|
||||||
_add_cmd(cmd_list, '--msvc=latest' if self.use_msvc else None)
|
cmd_list += format_cmd('--msvc=latest' if self.use_msvc else None)
|
||||||
_add_cmd(cmd_list, '--mingw64' if self.use_mingw else None)
|
cmd_list += format_cmd('--mingw64' if self.use_mingw else None)
|
||||||
_add_cmd(cmd_list, '--standalone' if self.standalone else None)
|
cmd_list += format_cmd('--standalone' if self.standalone else None)
|
||||||
|
|
||||||
_add_cmd(cmd_list, '--disable-ccache' if not self.use_ccache else None)
|
cmd_list += format_cmd('--disable-ccache' if not self.use_ccache else None)
|
||||||
_add_cmd(cmd_list, '--show-progress' if self.show_progress else None)
|
cmd_list += format_cmd('--show-progress' if self.show_progress else None)
|
||||||
_add_cmd(cmd_list, '--show-memory' if self.show_memory else None)
|
cmd_list += format_cmd('--show-memory' if self.show_memory else None)
|
||||||
_add_cmd(cmd_list, '--remove-output' if self.remove_output else None)
|
cmd_list += format_cmd('--remove-output' if self.remove_output else None)
|
||||||
_add_cmd(cmd_list, '--assume-yes-for-download' if self.download_confirm else None)
|
cmd_list += format_cmd('--assume-yes-for-download' if self.download_confirm else None)
|
||||||
_add_cmd(cmd_list, '--run' if self.run_after_build else None)
|
cmd_list += format_cmd('--run' if self.run_after_build else None)
|
||||||
_add_cmd(cmd_list, '--enable-console' if self.enable_console else '--disable-console')
|
cmd_list += format_cmd('--enable-console' if self.enable_console else '--disable-console')
|
||||||
|
|
||||||
_add_cmd(cmd_list, f'--xml={self.xml_path.absolute()}' if self.save_xml else None)
|
cmd_list += format_cmd('--xml=', str(self.xml_path.absolute()), self.save_xml)
|
||||||
_add_cmd(cmd_list, f'--output-dir={self.output_path.absolute()}' if self.output_path else None)
|
cmd_list += format_cmd('--output_dir=', )
|
||||||
_add_cmd(cmd_list, f'--company-name={self.company_name}' if self.company_name else None)
|
# _add_cmd(cmd_list, f'--xml={self.xml_path.absolute()}' if self.save_xml else None)
|
||||||
_add_cmd(cmd_list, f'--product-name={self.product_name}' if self.product_name else None)
|
# _add_cmd(cmd_list, f'--output-dir={self.output_path.absolute()}' if self.output_path else None)
|
||||||
_add_cmd(cmd_list, f'--file-version={self.file_version}' if self.file_version else None)
|
# _add_cmd(cmd_list, f'--company-name={self.company_name}' if self.company_name else None)
|
||||||
_add_cmd(cmd_list, f'--product-version={self.product_version}' if self.product_version else None)
|
# _add_cmd(cmd_list, f'--product-name={self.product_name}' if self.product_name else None)
|
||||||
_add_cmd(cmd_list, f'--file-description={self.file_description}' if self.file_description else None)
|
# _add_cmd(cmd_list, f'--file-version={self.file_version}' if self.file_version else None)
|
||||||
_add_cmd(cmd_list, f'--copyright={self.copy_right}' if self.copy_right else None)
|
# _add_cmd(cmd_list, f'--product-version={self.product_version}' if self.product_version else None)
|
||||||
|
# _add_cmd(cmd_list, f'--file-description={self.file_description}' if self.file_description else None)
|
||||||
|
# _add_cmd(cmd_list, f'--copyright={self.copy_right}' if self.copy_right else None)
|
||||||
|
|
||||||
_add_cmd(cmd_list, f'--follow-import-to={",".join(self.follow_import)}' if self.follow_import else None)
|
_add_cmd(cmd_list, f'--follow-import-to={",".join(self.follow_import)}' if self.follow_import else None)
|
||||||
_add_cmd(cmd_list, f'--nofollow-import-to={",".join(self.no_follow_import)}' if self.no_follow_import else None)
|
_add_cmd(cmd_list, f'--nofollow-import-to={",".join(self.no_follow_import)}' if self.no_follow_import else None)
|
||||||
|
Loading…
Reference in New Issue
Block a user