Skip to content

Commit 83525d3

Browse files
committed
build: bootstrap documentation run configurations
1 parent b546c26 commit 83525d3

File tree

4 files changed

+183
-29
lines changed

4 files changed

+183
-29
lines changed

bootstrap.py

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -863,33 +863,59 @@ def generate_clion_run_configs(self, configs):
863863
name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask",
864864
enabled="true")
865865
elif 'script' in config:
866-
clion_config = ET.SubElement(root, "configuration", {
867-
"default": "false",
868-
"name": config["name"],
869-
"type": "PythonConfigurationType",
870-
"factoryName": "Python",
871-
"nameIsGenerated": "false"
872-
})
873-
ET.SubElement(clion_config, "module", name="mrdocs")
874-
ET.SubElement(clion_config, "option", name="ENV_FILES", value="")
875-
ET.SubElement(clion_config, "option", name="INTERPRETER_OPTIONS", value="")
876-
ET.SubElement(clion_config, "option", name="PARENT_ENVS", value="true")
877-
envs = ET.SubElement(clion_config, "envs")
878-
ET.SubElement(envs, "env", name="PYTHONUNBUFFERED", value="1")
879-
ET.SubElement(clion_config, "option", name="SDK_HOME", value="")
880-
ET.SubElement(clion_config, "option", name="WORKING_DIRECTORY", value="$PROJECT_DIR$")
881-
ET.SubElement(clion_config, "option", name="IS_MODULE_SDK", value="true")
882-
ET.SubElement(clion_config, "option", name="ADD_CONTENT_ROOTS", value="true")
883-
ET.SubElement(clion_config, "option", name="ADD_SOURCE_ROOTS", value="true")
884-
ET.SubElement(clion_config, "option", name="SCRIPT_NAME", value=config["script"])
885-
ET.SubElement(clion_config, "option", name="PARAMETERS",
886-
value=' '.join(shlex.quote(arg) for arg in config["args"]))
887-
ET.SubElement(clion_config, "option", name="SHOW_COMMAND_LINE", value="false")
888-
ET.SubElement(clion_config, "option", name="EMULATE_TERMINAL", value="false")
889-
ET.SubElement(clion_config, "option", name="MODULE_MODE", value="false")
890-
ET.SubElement(clion_config, "option", name="REDIRECT_INPUT", value="false")
891-
ET.SubElement(clion_config, "option", name="INPUT_FILE", value="")
892-
ET.SubElement(clion_config, "method", v="2")
866+
if config["script"].endswith(".py"):
867+
clion_config = ET.SubElement(root, "configuration", {
868+
"default": "false",
869+
"name": config["name"],
870+
"type": "PythonConfigurationType",
871+
"factoryName": "Python",
872+
"nameIsGenerated": "false"
873+
})
874+
ET.SubElement(clion_config, "module", name="mrdocs")
875+
ET.SubElement(clion_config, "option", name="ENV_FILES", value="")
876+
ET.SubElement(clion_config, "option", name="INTERPRETER_OPTIONS", value="")
877+
ET.SubElement(clion_config, "option", name="PARENT_ENVS", value="true")
878+
envs = ET.SubElement(clion_config, "envs")
879+
ET.SubElement(envs, "env", name="PYTHONUNBUFFERED", value="1")
880+
ET.SubElement(clion_config, "option", name="SDK_HOME", value="")
881+
if 'cwd' in config and config["cwd"] != self.options.mrdocs_src_dir:
882+
ET.SubElement(clion_config, "option", name="WORKING_DIRECTORY", value=config["cwd"])
883+
else:
884+
ET.SubElement(clion_config, "option", name="WORKING_DIRECTORY", value="$PROJECT_DIR$")
885+
ET.SubElement(clion_config, "option", name="IS_MODULE_SDK", value="true")
886+
ET.SubElement(clion_config, "option", name="ADD_CONTENT_ROOTS", value="true")
887+
ET.SubElement(clion_config, "option", name="ADD_SOURCE_ROOTS", value="true")
888+
ET.SubElement(clion_config, "option", name="SCRIPT_NAME", value=config["script"])
889+
ET.SubElement(clion_config, "option", name="PARAMETERS",
890+
value=' '.join(shlex.quote(arg) for arg in config["args"]))
891+
ET.SubElement(clion_config, "option", name="SHOW_COMMAND_LINE", value="false")
892+
ET.SubElement(clion_config, "option", name="EMULATE_TERMINAL", value="false")
893+
ET.SubElement(clion_config, "option", name="MODULE_MODE", value="false")
894+
ET.SubElement(clion_config, "option", name="REDIRECT_INPUT", value="false")
895+
ET.SubElement(clion_config, "option", name="INPUT_FILE", value="")
896+
ET.SubElement(clion_config, "method", v="2")
897+
elif config["script"].endswith(".sh"):
898+
clion_config = ET.SubElement(root, "configuration", {
899+
"default": "false",
900+
"name": config["name"],
901+
"type": "ShConfigurationType"
902+
})
903+
ET.SubElement(clion_config, "option", name="SCRIPT_TEXT", value=f"bash {shlex.quote(config['script'])}")
904+
ET.SubElement(clion_config, "option", name="INDEPENDENT_SCRIPT_PATH", value="true")
905+
ET.SubElement(clion_config, "option", name="SCRIPT_PATH", value=config["script"])
906+
ET.SubElement(clion_config, "option", name="SCRIPT_OPTIONS", value="")
907+
ET.SubElement(clion_config, "option", name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY", value="true")
908+
if 'cwd' in config and config["cwd"] != self.options.mrdocs_src_dir:
909+
ET.SubElement(clion_config, "option", name="SCRIPT_WORKING_DIRECTORY", value=config["cwd"])
910+
else:
911+
ET.SubElement(clion_config, "option", name="SCRIPT_WORKING_DIRECTORY", value="$PROJECT_DIR$")
912+
ET.SubElement(clion_config, "option", name="INDEPENDENT_INTERPRETER_PATH", value="true")
913+
ET.SubElement(clion_config, "option", name="INTERPRETER_PATH", value="")
914+
ET.SubElement(clion_config, "option", name="INTERPRETER_OPTIONS", value="")
915+
ET.SubElement(clion_config, "option", name="EXECUTE_IN_TERMINAL", value="true")
916+
ET.SubElement(clion_config, "option", name="EXECUTE_SCRIPT_FILE", value="true")
917+
ET.SubElement(clion_config, "envs")
918+
ET.SubElement(clion_config, "method", v="2")
893919
tree = ET.ElementTree(root)
894920
tree.write(run_config_path, encoding="utf-8", xml_declaration=False)
895921

@@ -1039,7 +1065,6 @@ def generate_run_configs(self):
10391065
"args": bootstrap_args,
10401066
"cwd": self.options.mrdocs_src_dir
10411067
})
1042-
# make a copy of the args for the refresh config
10431068
bootstrap_refresh_args = bootstrap_args.copy()
10441069
bootstrap_refresh_args.append("--non-interactive")
10451070
configs.append({
@@ -1049,21 +1074,44 @@ def generate_run_configs(self):
10491074
"cwd": self.options.mrdocs_src_dir
10501075
})
10511076

1077+
# Targets for the pre-build steps
10521078
configs.append({
10531079
"name": f"MrDocs Generate Config Info ({bootstrap_refresh_config_name})",
10541080
"script": os.path.join(self.options.mrdocs_src_dir, 'util', 'generate-config-info.py'),
10551081
"args": [os.path.join(self.options.mrdocs_src_dir, 'src', 'lib', 'ConfigOptions.json'),
10561082
os.path.join(self.options.mrdocs_build_dir)],
10571083
"cwd": self.options.mrdocs_src_dir
10581084
})
1059-
10601085
configs.append({
10611086
"name": f"MrDocs Generate YAML Schema",
10621087
"script": os.path.join(self.options.mrdocs_src_dir, 'util', 'generate-yaml-schema.py'),
10631088
"args": [],
10641089
"cwd": self.options.mrdocs_src_dir
10651090
})
10661091

1092+
# Documentation generation targets
1093+
mrdocs_docs_dir = os.path.join(self.options.mrdocs_src_dir, "docs")
1094+
mrdocs_docs_ui_dir = os.path.join(mrdocs_docs_dir, "ui")
1095+
mrdocs_docs_script_ext = "bat" if self.is_windows() else "sh"
1096+
configs.append({
1097+
"name": "MrDocs Build Local Docs",
1098+
"script": os.path.join(mrdocs_docs_dir, f"build_local_docs.{mrdocs_docs_script_ext}"),
1099+
"args": [],
1100+
"cwd": mrdocs_docs_dir
1101+
})
1102+
configs.append({
1103+
"name": "MrDocs Build Docs",
1104+
"script": os.path.join(mrdocs_docs_dir, f"build_docs.{mrdocs_docs_script_ext}"),
1105+
"args": [],
1106+
"cwd": mrdocs_docs_dir
1107+
})
1108+
configs.append({
1109+
"name": "MrDocs Build UI Bundle",
1110+
"script": os.path.join(mrdocs_docs_ui_dir, f"build.{mrdocs_docs_script_ext}"),
1111+
"args": [],
1112+
"cwd": mrdocs_docs_ui_dir
1113+
})
1114+
10671115
print("Generating CLion run configurations for MrDocs...")
10681116
self.generate_clion_run_configs(configs)
10691117
print("Generating Visual Studio run configurations for MrDocs...")

docs/build_docs.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
REM
3+
REM Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
REM See https://llvm.org/LICENSE.txt for license information.
5+
REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
REM
7+
REM Copyright (c) 2025 Alan de Freitas ([email protected])
8+
REM
9+
REM Official repository: https://github.com/cppalliance/mrdocs
10+
REM
11+
12+
echo Building documentation UI
13+
set "cwd=%CD%"
14+
set "script_dir=%~dp0"
15+
if not exist "%script_dir%ui\build\ui-bundle.zip" (
16+
echo Building antora-ui
17+
pushd "%script_dir%ui"
18+
call build.bat
19+
popd
20+
)
21+
22+
echo Building documentation with Antora...
23+
echo Installing npm dependencies...
24+
call npm ci
25+
26+
echo Building docs in custom dir...
27+
call npx antora --clean --fetch antora-playbook.yml
28+
echo Done

docs/build_local_docs.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
REM
3+
REM Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
REM See https://llvm.org/LICENSE.txt for license information.
5+
REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
REM
7+
REM Copyright (c) 2025 Alan de Freitas ([email protected])
8+
REM
9+
REM Official repository: https://github.com/cppalliance/mrdocs
10+
REM
11+
12+
echo Building documentation UI
13+
set "cwd=%CD%"
14+
set "script_dir=%~dp0"
15+
if not exist "%script_dir%ui\build\ui-bundle.zip" (
16+
echo Building antora-ui
17+
pushd "%script_dir%ui"
18+
call build.bat
19+
popd
20+
)
21+
22+
echo Building documentation with Antora...
23+
echo Installing npm dependencies...
24+
call npm ci
25+
26+
echo Building docs in custom dir...
27+
call npx antora --clean --fetch antora-playbook.yml --attribute branchesarray=HEAD
28+
echo Done

docs/ui/build.bat

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@echo off
2+
REM
3+
REM Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
REM See https://llvm.org/LICENSE.txt for license information.
5+
REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
REM
7+
REM Copyright (c) 2025 Alan de Freitas ([email protected])
8+
REM
9+
REM Official repository: https://github.com/cppalliance/mrdocs
10+
REM
11+
12+
REM Check for npm
13+
where npm >nul 2>nul
14+
if errorlevel 1 (
15+
echo npm is not installed
16+
exit /b 1
17+
)
18+
19+
REM Check for npx
20+
where npx >nul 2>nul
21+
if errorlevel 1 (
22+
echo npx is not installed
23+
exit /b 1
24+
)
25+
26+
REM Install modules if needed
27+
if not exist node_modules (
28+
call npm ci
29+
) else (
30+
for %%F in (package.json) do set package_json_time=%%~tF
31+
for %%F in (node_modules) do set node_modules_time=%%~tF
32+
if "%package_json_time%" GTR "%node_modules_time%" (
33+
call npm ci
34+
)
35+
)
36+
37+
REM Lint
38+
call npx gulp lint
39+
if errorlevel 1 (
40+
set msg=Linting failed. Please run `npx gulp format` before pushing your code.
41+
if "%GITHUB_ACTIONS%"=="true" (
42+
echo ::error::%msg%
43+
) else (
44+
echo %msg%
45+
call npx gulp format
46+
)
47+
)
48+
49+
REM Build
50+
call npx gulp

0 commit comments

Comments
 (0)