Skip to content

Commit

Permalink
Merge pull request #176 from tetengo/tetengo_home
Browse files Browse the repository at this point in the history
Tetengo home
  • Loading branch information
kaorut authored Jul 31, 2021
2 parents adce02e + 995bb24 commit 6df8d88
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 47 deletions.
1 change: 1 addition & 0 deletions setup/installer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ script_files = \
EXTRA_DIST = \
${script_files} \
COPYING.rtf \
envvars_to_install.txt \
file_guid_map.txt \
files_to_install.txt \
installer.vcxproj \
Expand Down
2 changes: 1 addition & 1 deletion setup/installer/Makefile.nmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $(OBJDIR)\content.wixobj: $(OBJDIR)\content.wxs
$(OBJDIR)\content.wxs: $(OBJDIR)\content_wxs_source.txt
$(PYTHON) "$(WORKDIR)\generate_content_wxs.py" $** $@

$(OBJDIR)\content_wxs_source.txt: $(WORKDIR)\files_to_install.txt $(WORKDIR)\file_guid_map.txt
$(OBJDIR)\content_wxs_source.txt: $(WORKDIR)\files_to_install.txt $(WORKDIR)\file_guid_map.txt $(WORKDIR)\envvars_to_install.txt
$(PYTHON) "$(WORKDIR)\generate_content_wxs_source.py" $** $@ $(SOLUTIONDIR)

$(BINDIR)\setup.exe: $(TETENGOOUTDIR)\setup.exe
Expand Down
30 changes: 16 additions & 14 deletions setup/installer/copy_libimage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,25 @@ def _list_files(source_path: pathlib.Path) -> List[Tuple[pathlib.Path, pathlib.P
with source_path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
matched: Optional[re.Match[str]] = re.match(
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
)
if not matched:
continue
feature: str = matched.group(1)
source_directory = pathlib.Path(matched.group(2))
source_path = pathlib.Path(matched.group(3))
destination = pathlib.Path(matched.group(4))
if (
feature != "include"
and feature != "lib.Release.Win32"
and feature != "lib.Release.x64"
):
continue
files.append(
(source_directory / source_path, (destination / source_path).parent)
)
kind: str = matched.group(1)
if kind == "file":
feature: str = matched.group(2)
source_directory = pathlib.Path(matched.group(3))
source_path = pathlib.Path(matched.group(4))
destination = pathlib.Path(matched.group(5))
if (
feature != "include"
and feature != "lib.Release.Win32"
and feature != "lib.Release.x64"
):
continue
files.append(
(source_directory / source_path, (destination / source_path).parent)
)
return files


Expand Down
1 change: 1 addition & 0 deletions setup/installer/envvars_to_install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TETENGO_HOME [INSTALLDIR] 425575A0-AFF2-4A8D-94F5-51988F648AB1
87 changes: 73 additions & 14 deletions setup/installer/generate_content_wxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ def __init__(
self.source = source


class EnvVar:
id: str

name: str

value: str

guid: str

def __init__(self, id: str, name: str, value: str, guid: str):
self.id = id
self.name = name
self.value = value
self.guid = guid


class _DestinationDirectory:
id: str

Expand All @@ -64,14 +80,17 @@ class _DestinationDirectory:

files: List[File]

envvars: List[EnvVar]

def __init__(self, id: str, name: str, level: int):
self.id = id
self.name = name
self.level = level
self.children: Dict[str, _DestinationDirectory] = {}
self.files = []
self.envvars = []

def add(
def add_file(
self, path: pathlib.Path, feature: str, guid: str, source_path: pathlib.Path
) -> None:
if len(path.parents) > 1:
Expand All @@ -83,32 +102,55 @@ def add(
child_id, child_name, self.level + 1
)
grandchild_path = pathlib.Path(str(path)[len(child_name) + 1 :])
self.children[child_name].add(grandchild_path, feature, guid, source_path)
self.children[child_name].add_file(
grandchild_path, feature, guid, source_path
)
else:
file_name: str = str(path)
file_id: str = self.id + "." + file_name
file_id = file_id[-72:]
self.files.append(File(file_id, file_name, feature, guid, source_path))

def add_envvar(self, name: str, value: str, guid: str) -> None:
envvar_id: str = self.id + "." + name
self.envvars.append(EnvVar(envvar_id, name, value, guid))


def _build_destination_tree(source_path: pathlib.Path) -> _DestinationDirectory:
destination_tree = _DestinationDirectory("tetengo", "", 0)
with source_path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
line = line.rstrip("\r\n")
matched: Optional[re.Match[str]] = re.match(
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
)
if not matched:
continue
feature: str = matched.group(1)
source_directory = pathlib.Path(matched.group(2))
source_path = pathlib.Path(matched.group(3))
destination = pathlib.Path(matched.group(4))
guid = matched.group(5)
destination_tree.add(
destination / source_path, feature, guid, source_directory / source_path
matched_as_file: Optional[re.Match[str]] = re.match(
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
)
if matched_as_file:
kind_as_file: str = matched_as_file.group(1)
if kind_as_file == "file":
feature_as_file: str = matched_as_file.group(2)
source_directory_as_file = pathlib.Path(matched_as_file.group(3))
source_path_as_file = pathlib.Path(matched_as_file.group(4))
destination_as_file = pathlib.Path(matched_as_file.group(5))
guid_as_file = matched_as_file.group(6)
destination_tree.add_file(
destination_as_file / source_path_as_file,
feature_as_file,
guid_as_file,
source_directory_as_file / source_path_as_file,
)
else:
matched_as_envvar: Optional[re.Match[str]] = re.match(
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
)
if matched_as_envvar:
kind_as_envvar: str = matched_as_envvar.group(1)
if kind_as_envvar == "envvar":
name_as_envvar: str = matched_as_envvar.group(2)
value_as_envvar: str = matched_as_envvar.group(3)
guid_as_envvar: str = matched_as_envvar.group(4)
destination_tree.add_envvar(
name_as_envvar, value_as_envvar, guid_as_envvar
)
return destination_tree


Expand All @@ -127,6 +169,10 @@ def _build_feature_map_iter(
feature_map[file.feature].append(file.id)
for child_key in destination_tree.children:
_build_feature_map_iter(destination_tree.children[child_key], feature_map)
for envvar in destination_tree.envvars:
if not "environment_variable" in feature_map:
feature_map["environment_variable"] = []
feature_map["environment_variable"].append(envvar.id)


def _save_wxs(
Expand Down Expand Up @@ -183,6 +229,19 @@ def _write_directory_fragment_iter(
file=stream,
)
print("{} </Component>".format(indent), file=stream)
for envvar in destination_tree.envvars:
print(
'{} <Component Id="{}" Guid="{}">'.format(indent, envvar.id, envvar.guid),
file=stream,
)
print("{} <CreateFolder/>".format(indent), file=stream)
print(
'{} <Environment Id="{}" Name="{}" Action="set" System="yes" Part="all" Value="{}"/>'.format(
indent, envvar.id, envvar.name, envvar.value
),
file=stream,
)
print("{} </Component>".format(indent), file=stream)
if len(destination_tree.name) == 0:
print("{}</DirectoryRef>".format(indent), file=stream)
else:
Expand Down
47 changes: 29 additions & 18 deletions setup/installer/generate_content_wxs_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ def main(args: List[str]) -> None:
if len(args) < 4:
print(
"Usage: ./generate_content_wxs_source.py "
"files_to_install.txt file_guid_map.txt content_wxs_source.txt solution_path",
"files_to_install.txt file_guid_map.txt envvars_to_install.txt content_wxs_source.txt solution_path",
file=sys.stderr,
)
sys.exit(0)

files_to_install_path = pathlib.Path(args[0])
file_guid_map_path = pathlib.Path(args[1])
content_wxs_source_path = pathlib.Path(args[2])
solution_path = pathlib.Path(args[3])
envvars_to_install_path = pathlib.Path(args[2])
content_wxs_source_path = pathlib.Path(args[3])
solution_path = pathlib.Path(args[4])

files_to_install = _load_files_to_install(files_to_install_path)
file_guid_map = _FileGuidMap(file_guid_map_path, solution_path)
envvars_to_install = _load_envvars_to_install(envvars_to_install_path)

_make_content_wxs_source(
files_to_install, file_guid_map, content_wxs_source_path, solution_path
files_to_install,
file_guid_map,
envvars_to_install,
content_wxs_source_path,
solution_path,
)
file_guid_map.save(file_guid_map_path)

Expand All @@ -62,6 +68,19 @@ def _load_files_to_install(
return files


def _load_envvars_to_install(path: pathlib.Path) -> List[Tuple[str, str, str]]:
envvars: List[Tuple[str, str, str]] = []
with path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
matched: Optional[re.Match[str]] = re.match(
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
)
if not matched:
continue
envvars.append((matched.group(1), matched.group(2), matched.group(3)))
return envvars


class _FileGuidMap:
_map: Dict[pathlib.Path, Tuple[str, bool]] = {}

Expand Down Expand Up @@ -94,6 +113,7 @@ def save(self, file_guid_map_path: pathlib.Path) -> None:
def _make_content_wxs_source(
files_to_install: List[Tuple[str, pathlib.Path, pathlib.Path]],
file_guid_map: _FileGuidMap,
envvars_to_install: List[Tuple[str, str, str]],
content_wxs_source_path: pathlib.Path,
solution_path: pathlib.Path,
) -> None:
Expand All @@ -106,7 +126,7 @@ def _make_content_wxs_source(
continue
extended_file_name: str = extended[len(source_directory) + 1 :]
print(
"{} {} {} {} {}".format(
"file {} {} {} {} {}".format(
wildcard[0],
source_directory,
extended_file_name,
Expand All @@ -117,19 +137,10 @@ def _make_content_wxs_source(
),
file=stream,
)


def _remove_solution_path(
path: pathlib.Path, solution_path: pathlib.Path
) -> pathlib.Path:
path_str = str(path)
solution_path_str = str(solution_path)
if path_str.find(solution_path_str) != 0:
return path
removed = path_str[len(solution_path_str) :]
if len(solution_path_str) > 0 and removed[0] == "\\":
removed = removed[1:]
return pathlib.Path(removed)
for envvar in envvars_to_install:
print(
"envvar {} {} {}".format(envvar[0], envvar[1], envvar[2]), file=stream
)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions setup/installer/installer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<None Include="Makefile.nmake" />
</ItemGroup>
<ItemGroup>
<Text Include="envvars_to_install.txt" />
<Text Include="files_to_install.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
3 changes: 3 additions & 0 deletions setup/installer/installer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
<Text Include="files_to_install.txt">
<Filter>src</Filter>
</Text>
<Text Include="envvars_to_install.txt">
<Filter>src</Filter>
</Text>
</ItemGroup>
</Project>

0 comments on commit 6df8d88

Please sign in to comment.