Skip to content

Commit cae365e

Browse files
committed
build: run configurations include a refresh-all target
1 parent d2f9c20 commit cae365e

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

CMakeUserPresets.json.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
},
216216
{
217217
"name": "release-macos-gcc",
218-
"displayName": "Release (macOS) (gcc)",
218+
"displayName": "Release (macOS: gcc)",
219219
"description": "Preset for building MrDocs in Release mode with the gcc compiler in macOS.",
220220
"inherits": "release",
221221
"binaryDir": "${sourceDir}/build/${presetName}",

bootstrap.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class InstallOptions:
9898

9999
# Libxml2
100100
libxml2_src_dir: str = "<third-party-src-dir>/libxml2"
101-
libxml2_build_type: str = "Release" # purposefully does not depend on mrdocs-build-type because we only need the executable
101+
libxml2_build_type: str = "Release" # purposefully does not depend on mrdocs-build-type because we only need the executable
102102
libxml2_build_dir: str = "<libxml2-src-dir>/build/<libxml2-build-type:lower><\"-\":if(cc)><cc:basename>"
103103
libxml2_install_dir: str = "<libxml2-src-dir>/install/<libxml2-build-type:lower><\"-\":if(cc)><cc:basename>"
104104
libxml2_repo: str = "https://github.com/GNOME/libxml2"
@@ -109,8 +109,9 @@ class InstallOptions:
109109
jetbrains_run_config_dir: str = "<mrdocs-src-dir>/.run"
110110
boost_src_dir: str = "<mrdocs-src-dir>/../boost"
111111

112-
# Meta
112+
# Command line arguments
113113
non_interactive: bool = False
114+
refresh_all: bool = False
114115

115116

116117
# Constant for option descriptions
@@ -154,7 +155,8 @@ class InstallOptions:
154155
"generate_run_configs": "Whether to generate run configurations for IDEs.",
155156
"jetbrains_run_config_dir": "Directory where JetBrains run configurations will be stored.",
156157
"boost_src_dir": "Directory where the source files of the Boost libraries are located.",
157-
"non_interactive": "Whether to use all default options without interactive prompts."
158+
"non_interactive": "Whether to use all default options without interactive prompts.",
159+
"refresh_all": "Call the command to refresh dependencies for all configurations"
158160
}
159161

160162

@@ -178,6 +180,7 @@ def __init__(self, cmd_line_args=None):
178180
else:
179181
raise TypeError(f"Unsupported type {field.type} for field {field.name} in InstallOptions.")
180182
self.options.non_interactive = self.cmd_line_args.get("non_interactive", False)
183+
self.options.refresh_all = self.cmd_line_args.get("refresh_all", False)
181184
self.prompted_options = set()
182185
self.compiler_info = {}
183186

@@ -1805,6 +1808,13 @@ def generate_run_configs(self):
18051808
"args": bootstrap_refresh_args,
18061809
"cwd": self.options.mrdocs_src_dir
18071810
})
1811+
configs.append({
1812+
"name": f"MrDocs Bootstrap Refresh All",
1813+
"script": os.path.join(self.options.mrdocs_src_dir, "bootstrap.py"),
1814+
"folder": "MrDocs Bootstrap Refresh",
1815+
"args": ["--refresh-all"],
1816+
"cwd": self.options.mrdocs_src_dir
1817+
})
18081818

18091819
# Targets for the pre-build steps
18101820
configs.append({
@@ -1956,6 +1966,33 @@ def install_all(self):
19561966
else:
19571967
print("Skipping run configurations generation as per user preference.")
19581968

1969+
def refresh_all(self):
1970+
# 1. Read all configurations in .vscode/launch.json
1971+
current_python_interpreter_path = sys.executable
1972+
this_script_path = os.path.abspath(__file__)
1973+
mrdocs_src_dir = os.path.dirname(this_script_path)
1974+
vscode_launch_path = os.path.join(mrdocs_src_dir, ".vscode", "launch.json")
1975+
if not os.path.exists(vscode_launch_path):
1976+
print("No existing Visual Studio Code launch configurations found.")
1977+
return
1978+
with open(vscode_launch_path, "r") as f:
1979+
vscode_launch_data = json.load(f)
1980+
vscode_configs = vscode_launch_data.get("configurations", [])
1981+
1982+
# 2. Filter configurations whose name starts with "MrDocs Bootstrap Refresh ("
1983+
bootstrap_refresh_configs = [
1984+
cfg for cfg in vscode_configs if cfg.get("name", "").startswith("MrDocs Bootstrap Refresh (")
1985+
]
1986+
if not bootstrap_refresh_configs:
1987+
print("No bootstrap refresh configurations found in Visual Studio Code launch configurations.")
1988+
return
1989+
1990+
# 3. For each configuration, run this very same bootstrap.py script with the same arguments
1991+
for config in bootstrap_refresh_configs:
1992+
args = [current_python_interpreter_path, this_script_path] + [
1993+
arg.replace("${workspaceFolder}", mrdocs_src_dir) for arg in config.get("args", [])]
1994+
print(f"Running bootstrap refresh with arguments: {args}")
1995+
subprocess.run(args, check=True)
19591996

19601997
def get_command_line_args():
19611998
"""
@@ -1999,6 +2036,9 @@ def get_command_line_args():
19992036
def main():
20002037
args = get_command_line_args()
20012038
installer = MrDocsInstaller(args)
2039+
if installer.options.refresh_all:
2040+
installer.refresh_all()
2041+
exit(0)
20022042
installer.install_all()
20032043

20042044

0 commit comments

Comments
 (0)