Skip to content

Commit 6df8d88

Browse files
authored
Merge pull request #176 from tetengo/tetengo_home
Tetengo home
2 parents adce02e + 995bb24 commit 6df8d88

File tree

8 files changed

+125
-47
lines changed

8 files changed

+125
-47
lines changed

setup/installer/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ script_files = \
99
EXTRA_DIST = \
1010
${script_files} \
1111
COPYING.rtf \
12+
envvars_to_install.txt \
1213
file_guid_map.txt \
1314
files_to_install.txt \
1415
installer.vcxproj \

setup/installer/Makefile.nmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $(OBJDIR)\content.wixobj: $(OBJDIR)\content.wxs
5555
$(OBJDIR)\content.wxs: $(OBJDIR)\content_wxs_source.txt
5656
$(PYTHON) "$(WORKDIR)\generate_content_wxs.py" $** $@
5757

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

6161
$(BINDIR)\setup.exe: $(TETENGOOUTDIR)\setup.exe

setup/installer/copy_libimage_files.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@ def _list_files(source_path: pathlib.Path) -> List[Tuple[pathlib.Path, pathlib.P
3232
with source_path.open(mode="r", encoding="UTF-8") as stream:
3333
for line in stream:
3434
matched: Optional[re.Match[str]] = re.match(
35-
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
35+
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
3636
)
3737
if not matched:
3838
continue
39-
feature: str = matched.group(1)
40-
source_directory = pathlib.Path(matched.group(2))
41-
source_path = pathlib.Path(matched.group(3))
42-
destination = pathlib.Path(matched.group(4))
43-
if (
44-
feature != "include"
45-
and feature != "lib.Release.Win32"
46-
and feature != "lib.Release.x64"
47-
):
48-
continue
49-
files.append(
50-
(source_directory / source_path, (destination / source_path).parent)
51-
)
39+
kind: str = matched.group(1)
40+
if kind == "file":
41+
feature: str = matched.group(2)
42+
source_directory = pathlib.Path(matched.group(3))
43+
source_path = pathlib.Path(matched.group(4))
44+
destination = pathlib.Path(matched.group(5))
45+
if (
46+
feature != "include"
47+
and feature != "lib.Release.Win32"
48+
and feature != "lib.Release.x64"
49+
):
50+
continue
51+
files.append(
52+
(source_directory / source_path, (destination / source_path).parent)
53+
)
5254
return files
5355

5456

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TETENGO_HOME [INSTALLDIR] 425575A0-AFF2-4A8D-94F5-51988F648AB1

setup/installer/generate_content_wxs.py

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ def __init__(
5353
self.source = source
5454

5555

56+
class EnvVar:
57+
id: str
58+
59+
name: str
60+
61+
value: str
62+
63+
guid: str
64+
65+
def __init__(self, id: str, name: str, value: str, guid: str):
66+
self.id = id
67+
self.name = name
68+
self.value = value
69+
self.guid = guid
70+
71+
5672
class _DestinationDirectory:
5773
id: str
5874

@@ -64,14 +80,17 @@ class _DestinationDirectory:
6480

6581
files: List[File]
6682

83+
envvars: List[EnvVar]
84+
6785
def __init__(self, id: str, name: str, level: int):
6886
self.id = id
6987
self.name = name
7088
self.level = level
7189
self.children: Dict[str, _DestinationDirectory] = {}
7290
self.files = []
91+
self.envvars = []
7392

74-
def add(
93+
def add_file(
7594
self, path: pathlib.Path, feature: str, guid: str, source_path: pathlib.Path
7695
) -> None:
7796
if len(path.parents) > 1:
@@ -83,32 +102,55 @@ def add(
83102
child_id, child_name, self.level + 1
84103
)
85104
grandchild_path = pathlib.Path(str(path)[len(child_name) + 1 :])
86-
self.children[child_name].add(grandchild_path, feature, guid, source_path)
105+
self.children[child_name].add_file(
106+
grandchild_path, feature, guid, source_path
107+
)
87108
else:
88109
file_name: str = str(path)
89110
file_id: str = self.id + "." + file_name
90111
file_id = file_id[-72:]
91112
self.files.append(File(file_id, file_name, feature, guid, source_path))
92113

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

94119
def _build_destination_tree(source_path: pathlib.Path) -> _DestinationDirectory:
95120
destination_tree = _DestinationDirectory("tetengo", "", 0)
96121
with source_path.open(mode="r", encoding="UTF-8") as stream:
97122
for line in stream:
98123
line = line.rstrip("\r\n")
99-
matched: Optional[re.Match[str]] = re.match(
100-
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
101-
)
102-
if not matched:
103-
continue
104-
feature: str = matched.group(1)
105-
source_directory = pathlib.Path(matched.group(2))
106-
source_path = pathlib.Path(matched.group(3))
107-
destination = pathlib.Path(matched.group(4))
108-
guid = matched.group(5)
109-
destination_tree.add(
110-
destination / source_path, feature, guid, source_directory / source_path
124+
matched_as_file: Optional[re.Match[str]] = re.match(
125+
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
111126
)
127+
if matched_as_file:
128+
kind_as_file: str = matched_as_file.group(1)
129+
if kind_as_file == "file":
130+
feature_as_file: str = matched_as_file.group(2)
131+
source_directory_as_file = pathlib.Path(matched_as_file.group(3))
132+
source_path_as_file = pathlib.Path(matched_as_file.group(4))
133+
destination_as_file = pathlib.Path(matched_as_file.group(5))
134+
guid_as_file = matched_as_file.group(6)
135+
destination_tree.add_file(
136+
destination_as_file / source_path_as_file,
137+
feature_as_file,
138+
guid_as_file,
139+
source_directory_as_file / source_path_as_file,
140+
)
141+
else:
142+
matched_as_envvar: Optional[re.Match[str]] = re.match(
143+
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
144+
)
145+
if matched_as_envvar:
146+
kind_as_envvar: str = matched_as_envvar.group(1)
147+
if kind_as_envvar == "envvar":
148+
name_as_envvar: str = matched_as_envvar.group(2)
149+
value_as_envvar: str = matched_as_envvar.group(3)
150+
guid_as_envvar: str = matched_as_envvar.group(4)
151+
destination_tree.add_envvar(
152+
name_as_envvar, value_as_envvar, guid_as_envvar
153+
)
112154
return destination_tree
113155

114156

@@ -127,6 +169,10 @@ def _build_feature_map_iter(
127169
feature_map[file.feature].append(file.id)
128170
for child_key in destination_tree.children:
129171
_build_feature_map_iter(destination_tree.children[child_key], feature_map)
172+
for envvar in destination_tree.envvars:
173+
if not "environment_variable" in feature_map:
174+
feature_map["environment_variable"] = []
175+
feature_map["environment_variable"].append(envvar.id)
130176

131177

132178
def _save_wxs(
@@ -183,6 +229,19 @@ def _write_directory_fragment_iter(
183229
file=stream,
184230
)
185231
print("{} </Component>".format(indent), file=stream)
232+
for envvar in destination_tree.envvars:
233+
print(
234+
'{} <Component Id="{}" Guid="{}">'.format(indent, envvar.id, envvar.guid),
235+
file=stream,
236+
)
237+
print("{} <CreateFolder/>".format(indent), file=stream)
238+
print(
239+
'{} <Environment Id="{}" Name="{}" Action="set" System="yes" Part="all" Value="{}"/>'.format(
240+
indent, envvar.id, envvar.name, envvar.value
241+
),
242+
file=stream,
243+
)
244+
print("{} </Component>".format(indent), file=stream)
186245
if len(destination_tree.name) == 0:
187246
print("{}</DirectoryRef>".format(indent), file=stream)
188247
else:

setup/installer/generate_content_wxs_source.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,27 @@ def main(args: List[str]) -> None:
2121
if len(args) < 4:
2222
print(
2323
"Usage: ./generate_content_wxs_source.py "
24-
"files_to_install.txt file_guid_map.txt content_wxs_source.txt solution_path",
24+
"files_to_install.txt file_guid_map.txt envvars_to_install.txt content_wxs_source.txt solution_path",
2525
file=sys.stderr,
2626
)
2727
sys.exit(0)
2828

2929
files_to_install_path = pathlib.Path(args[0])
3030
file_guid_map_path = pathlib.Path(args[1])
31-
content_wxs_source_path = pathlib.Path(args[2])
32-
solution_path = pathlib.Path(args[3])
31+
envvars_to_install_path = pathlib.Path(args[2])
32+
content_wxs_source_path = pathlib.Path(args[3])
33+
solution_path = pathlib.Path(args[4])
3334

3435
files_to_install = _load_files_to_install(files_to_install_path)
3536
file_guid_map = _FileGuidMap(file_guid_map_path, solution_path)
37+
envvars_to_install = _load_envvars_to_install(envvars_to_install_path)
3638

3739
_make_content_wxs_source(
38-
files_to_install, file_guid_map, content_wxs_source_path, solution_path
40+
files_to_install,
41+
file_guid_map,
42+
envvars_to_install,
43+
content_wxs_source_path,
44+
solution_path,
3945
)
4046
file_guid_map.save(file_guid_map_path)
4147

@@ -62,6 +68,19 @@ def _load_files_to_install(
6268
return files
6369

6470

71+
def _load_envvars_to_install(path: pathlib.Path) -> List[Tuple[str, str, str]]:
72+
envvars: List[Tuple[str, str, str]] = []
73+
with path.open(mode="r", encoding="UTF-8") as stream:
74+
for line in stream:
75+
matched: Optional[re.Match[str]] = re.match(
76+
"^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)", line
77+
)
78+
if not matched:
79+
continue
80+
envvars.append((matched.group(1), matched.group(2), matched.group(3)))
81+
return envvars
82+
83+
6584
class _FileGuidMap:
6685
_map: Dict[pathlib.Path, Tuple[str, bool]] = {}
6786

@@ -94,6 +113,7 @@ def save(self, file_guid_map_path: pathlib.Path) -> None:
94113
def _make_content_wxs_source(
95114
files_to_install: List[Tuple[str, pathlib.Path, pathlib.Path]],
96115
file_guid_map: _FileGuidMap,
116+
envvars_to_install: List[Tuple[str, str, str]],
97117
content_wxs_source_path: pathlib.Path,
98118
solution_path: pathlib.Path,
99119
) -> None:
@@ -106,7 +126,7 @@ def _make_content_wxs_source(
106126
continue
107127
extended_file_name: str = extended[len(source_directory) + 1 :]
108128
print(
109-
"{} {} {} {} {}".format(
129+
"file {} {} {} {} {}".format(
110130
wildcard[0],
111131
source_directory,
112132
extended_file_name,
@@ -117,19 +137,10 @@ def _make_content_wxs_source(
117137
),
118138
file=stream,
119139
)
120-
121-
122-
def _remove_solution_path(
123-
path: pathlib.Path, solution_path: pathlib.Path
124-
) -> pathlib.Path:
125-
path_str = str(path)
126-
solution_path_str = str(solution_path)
127-
if path_str.find(solution_path_str) != 0:
128-
return path
129-
removed = path_str[len(solution_path_str) :]
130-
if len(solution_path_str) > 0 and removed[0] == "\\":
131-
removed = removed[1:]
132-
return pathlib.Path(removed)
140+
for envvar in envvars_to_install:
141+
print(
142+
"envvar {} {} {}".format(envvar[0], envvar[1], envvar[2]), file=stream
143+
)
133144

134145

135146
if __name__ == "__main__":

setup/installer/installer.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<None Include="Makefile.nmake" />
106106
</ItemGroup>
107107
<ItemGroup>
108+
<Text Include="envvars_to_install.txt" />
108109
<Text Include="files_to_install.txt" />
109110
</ItemGroup>
110111
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

setup/installer/installer.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@
3333
<Text Include="files_to_install.txt">
3434
<Filter>src</Filter>
3535
</Text>
36+
<Text Include="envvars_to_install.txt">
37+
<Filter>src</Filter>
38+
</Text>
3639
</ItemGroup>
3740
</Project>

0 commit comments

Comments
 (0)