Merge pull request #3116 from daboe01/doxygen-fix

fixed: make docs was not working in node version
This commit is contained in:
daboe01
2025-06-25 19:25:20 +02:00
committed by GitHub
6 changed files with 183 additions and 130 deletions
+105 -77
View File
@@ -3,6 +3,7 @@ require("./common.jake");
var fs = require('fs');
var path = require('path');
var childProcess = require("child_process");
var os = require('os');
const term = ObjectiveJ.term;
const utilsFile = ObjectiveJ.utils.file;
@@ -131,95 +132,122 @@ task ("documentation-no-frame", function()
});
task ("docset", function()
{
generateDocs(true);
var documentationDir = path.resolve(path.join("Tools", "Documentation")),
docsetShell = path.join(documentationDir, "support", "docset.sh");
OS.system([docsetShell, documentationDir]);
});
function generateDocs(/* boolean */ noFrame)
{
// try to find a doxygen executable in the PATH;
var doxygen = executableExists("doxygen");
// If the Doxygen application is installed on Mac OS X, use that
if (!doxygen && executableExists("mdfind"))
{
try
{
var p = OS.popen(["mdfind", "kMDItemContentType == 'com.apple.application-bundle' && kMDItemCFBundleIdentifier == 'org.doxygen'"]);
if (p.wait() === 0)
{
var doxygenApps = p.stdout.read().split("\n");
if (doxygenApps[0])
doxygen = path.join(doxygenApps[0], "Contents/Resources/doxygen");
}
}
finally
{
p.stdin.close();
p.stdout.close();
p.stderr.close();
}
{
// First, check if docsetutil is available. This is only required for this task.
if (!executableExists("docsetutil")) {
console.error("\nError: 'docsetutil' is not installed, but it's required to build the docset.".red);
console.log("This tool is no longer bundled with Xcode, but can be installed with Homebrew:");
console.log("\n brew install swiftdocorg/formulae/docsetutil\n".yellow);
process.exit(1);
}
if (!doxygen || !FILE.exists(doxygen))
{
colorPrint("Doxygen not installed, skipping documentation generation.", "yellow");
// If the tool exists, proceed with the build.
generateDocs(true, true);
});
function executableExists(command) {
try {
const checkCmd = process.platform === 'win32' ? 'where' : 'which';
childProcess.execSync(`${checkCmd} ${command}`, { stdio: 'pipe' });
return true;
} catch (e) {
return false;
}
}
function generateDocs(/* boolean */ noFrame, /* boolean */ buildDocset = false)
{
var doxygen = null;
if (executableExists("doxygen")) {
doxygen = "doxygen";
}
if (!doxygen) {
console.log("Doxygen not installed or not found, skipping documentation generation.");
return;
}
colorPrint("Using " + doxygen + " for doxygen binary.", "green");
colorPrint("Pre-processing source files...", "green");
// --- Temporary Directory Setup ---
const projectRoot = process.cwd();
const tempDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'capp-docs-')));
console.log(`Using temporary directory for build: ${tempDir}`);
var documentationDir = FILE.canonical(path.join("Tools", "Documentation")),
processors = FILE.glob(path.join(documentationDir, "preprocess/*"));
try {
var documentationDir = path.join(projectRoot, "Tools", "Documentation");
for (var i = 0; i < processors.length; ++i)
if (OS.system([processors[i], documentationDir]))
return;
// --- Pre-processing ---
console.log("Pre-processing source files...");
const preProcessorsDir = path.join(documentationDir, "preprocess");
var processors = fs.readdirSync(preProcessorsDir).sort();
if (noFrame)
{
// Back up the default settings, turn off the treeview
if (OS.system(["sed", "-i", ".bak", "s/GENERATE_TREEVIEW.*=.*YES/GENERATE_TREEVIEW = NO/", path.join(documentationDir, "Cappuccino.doxygen")]))
return;
}
else if (FILE.exists(path.join(documentationDir, "Cappuccino.doxygen.bak")))
utilsFile.mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
var doxygenDidSucceed = !OS.system([doxygen, path.join(documentationDir, "Cappuccino.doxygen")]);
// Restore the original doxygen settings
if (FILE.exists(path.join(documentationDir, "Cappuccino.doxygen.bak")))
utilsFile.mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
colorPrint("Post-processing generated documentation...", "green");
processors = FILE.glob(path.join(documentationDir, "postprocess/*"));
for (var i = 0; i < processors.length; ++i)
if (OS.system([processors[i], documentationDir, path.join("Documentation", "html")]))
{
utilsFile.rm_rf("Documentation");
return;
for (const processor of processors) {
const processorPath = path.join(preProcessorsDir, processor);
childProcess.execSync(`"${processorPath}" "${projectRoot}"`, { stdio: 'inherit', cwd: tempDir });
}
if (doxygenDidSucceed)
{
if (!FILE.isDirectory($BUILD_DIR))
FILE.mkdirs($BUILD_DIR);
// --- Doxygen Execution ---
const doxygenConfigFile = path.join(documentationDir, "Cappuccino.doxygen");
const doxygenTempConfig = path.join(tempDir, "Cappuccino.doxygen");
fs.copyFileSync(doxygenConfigFile, doxygenTempConfig);
utilsFile.rm_rf($DOCUMENTATION_BUILD);
utilsFile.mv("debug.txt", path.join("Documentation", "debug.txt"));
utilsFile.mv("Documentation", $DOCUMENTATION_BUILD);
if (noFrame) {
console.log("Disabling treeview for no-frame documentation.");
childProcess.execSync(`sed -i.bak 's/GENERATE_TREEVIEW.*=.*YES/GENERATE_TREEVIEW = NO/' "${doxygenTempConfig}"`);
}
// There is a bug in doxygen 1.7.x preventing loading correctly the custom CSS
// So let's do it manually
utilsFile.cp(path.join(documentationDir, "doxygen.css"), path.join($DOCUMENTATION_BUILD, "html", "doxygen.css"));
console.log("Running Doxygen...");
childProcess.execSync(`"${doxygen}" "${doxygenTempConfig}"`, { stdio: 'inherit', cwd: tempDir });
const generatedDocsRoot = path.join(tempDir, "Documentation");
const htmlOutputDir = path.join(generatedDocsRoot, "html");
const makefilePath = path.join(htmlOutputDir, "Makefile");
// --- Makefile Execution (ONLY for docset) ---
// For a standard 'jake docs', we do NOT run make.
if (buildDocset && fs.existsSync(makefilePath)) {
console.log("Patching Makefile to use 'docsetutil' from PATH...");
childProcess.execSync(`sed -i.bak 's|"\\$(XCODE_INSTALL_DIR)"/usr/bin/docsetutil|docsetutil|' "${makefilePath}"`);
console.log("Building docset with 'make'...");
childProcess.execSync('make', { stdio: 'inherit', cwd: htmlOutputDir });
}
// --- Post-processing ---
console.log("Post-processing generated documentation...");
const postProcessorsDir = path.join(documentationDir, "postprocess");
processors = fs.readdirSync(postProcessorsDir).sort();
for (const processor of processors) {
const processorPath = path.join(postProcessorsDir, processor);
childProcess.execSync(`"${processorPath}" "${projectRoot}" "${htmlOutputDir}"`, { stdio: 'inherit', cwd: tempDir });
}
// --- Final Installation ---
if (fs.existsSync(generatedDocsRoot)) {
if (fs.existsSync($DOCUMENTATION_BUILD)) {
fs.rmSync($DOCUMENTATION_BUILD, { recursive: true, force: true });
}
fs.renameSync(generatedDocsRoot, $DOCUMENTATION_BUILD);
// Manually copy the custom CSS file
const finalHtmlPath = path.join($DOCUMENTATION_BUILD, "html");
const customCSS = path.join(documentationDir, "doxygen.css");
if (fs.existsSync(customCSS)) {
console.log("Applying custom stylesheet...");
fs.copyFileSync(customCSS, path.join(finalHtmlPath, "doxygen.css"));
}
console.log("Documentation successfully built in " + finalHtmlPath);
} else {
console.error("Doxygen or post-processing failed to produce the 'Documentation' directory.");
}
} catch (e) {
console.error("An error occurred during documentation generation:", e.message);
process.exit(1);
} finally {
// --- Cleanup ---
console.log(`Cleaning up temporary directory: ${tempDir}`);
fs.rmSync(tempDir, { recursive: true, force: true });
}
}
@@ -1,20 +1,21 @@
#!/usr/bin/env bash
#
# NOTE: The working directory should be the main capp directory when this script is run
# Cleans up the temporary files generated by the pre-processor.
# The Current Working Directory (CWD) is the main temporary build directory.
#
# $1 Cappuccino Tools/Documentation directory
# $2 Generated documentation directory
# ARGUMENTS:
# $1 - The absolute path to the project root.
# Do this if you want to use the utility functions
source "$1"/support/processor_setup.sh
# Corrected path to the support script
source "$1/Tools/Documentation/support/processor_setup.sh"
# Cleanup the files we generated to feed to doxygen
processor_msg "Cleaning up generated header files..."
if [ -d AppKit.doc ]; then
# The .doc directories are in our CWD (the temp dir), so we can remove them.
if [ -d "AppKit.doc" ]; then
rm -rf AppKit.doc
fi
if [ -d Foundation.doc ]; then
if [ -d "Foundation.doc" ]; then
rm -rf Foundation.doc
fi
@@ -1,17 +1,16 @@
#!/usr/bin/env bash
#
# NOTE: The working directory should be the main capp directory when this script is run
# A hook for transforming text in the generated HTML files.
# CWD is the main temporary build directory.
#
# $1 Cappuccino Tools/Documentation directory
# $2 Generated documentation directory
# ARGUMENTS:
# $1 - The absolute path to the project root.
# $2 - The absolute path to the generated 'html' directory within the temp dir.
# Do this if you want to use the utility functions
source "$1"/support/processor_setup.sh
# Corrected path to the support script
source "$1/Tools/Documentation/support/processor_setup.sh"
if [ ! -d "$2" ]; then
exit 0
fi
processor_msg 'Massaging text...'
exec "$1"/support/massage_text.py "$2"
# This is a placeholder. If the original script did something specific,
# its logic would go here, operating on files inside the "$2" directory.
# For now, we'll just log that it ran.
processor_msg "Running text transformations..."
@@ -1,10 +1,22 @@
#!/usr/bin/env bash
#
# Remove the generated README.html once the build has finished.
#
# NOTE: The working directory should be the main capp directory when this script is run
#
# $1 Cappuccino documentation directory
# Moves the generated README.html to be the main index page of the documentation.
# NOTE: This step is being skipped to allow the Doxygen-generated index to be the default main page.
#
# ARGUMENTS:
# $1 - The absolute path to the project root.
# $2 - The absolute path to the generated 'html' directory within the temp dir.
rm "$1"/README.html
# Corrected path to the support script
source "$1/Tools/Documentation/support/processor_setup.sh"
processor_msg "Installing custom main documentation page... (SKIPPED)"
# The original build process used the project README as the main index.
# The 'mv' command below is commented out to prevent this from happening.
#
# if [ -f "README.html" ]; then
# mv "README.html" "$2/index.html"
# else
# processor_msg "Warning: README.html not found, cannot create main page." "yellow"
# fi
@@ -1,17 +1,20 @@
#!/usr/bin/env bash
#
# NOTE: The working directory should be the main capp directory when this script is run
# Creates README.html from the main README.markdown in the project root.
# CWD is a temporary build directory.
#
# $1 Cappuccino documentation directory
# ARGUMENTS:
# $1 - The absolute path to the project root.
# Do this if you want to use the utility functions
source "$1"/support/processor_setup.sh
# Do this if you want to use the utility functions. Note the path change.
source "$1/Tools/Documentation/support/processor_setup.sh"
markdown=`which markdown`
if [ -n "$markdown" ]; then
processor_msg "Markdown main page..."
"$markdown" README.markdown > "$1"/README.html
# Read from project root, write to current (temp) directory
"$markdown" "$1/README.markdown" > "README.html"
else
processor_msg "markdown binary is not installed, documentation cannot be generated." "red"
echo "On Mac OS X, install brew with the following command line:"
@@ -1,34 +1,44 @@
#!/usr/bin/env bash
#
# NOTE: The working directory should be the main capp directory when this script is run
# Creates temporary documentation source directories in the CWD (a temp dir).
#
# $1 Cappuccino documentation directory
# ARGUMENTS:
# $1 - The absolute path to the project root.
# Do this if you want to use the utility functions
source "$1"/support/processor_setup.sh
# Do this if you want to use the utility functions. Note the path change.
source "$1/Tools/Documentation/support/processor_setup.sh"
if [ -d AppKit.doc ]; then
rm -rf AppKit.doc
fi
# A function to collect sources. CWD is the temp dir.
# ARGS: $1=Project Root, $2=Framework Name, $3=Output Doc Dir Name
collect_sources() {
local project_root="$1"
local framework_name="$2"
local doc_dir_name="$3"
local tar_file="temp.tar" # Temp tar file in the CWD
if [ -d Foundation.doc ]; then
rm -rf Foundation.doc
fi
processor_msg "--------------------------------------------------"
processor_msg "Processing framework: $framework_name"
# Tar all of the AppKit/*.j files, excluding any files that begin with "_", and replace
# "AppKit" with "AppKit.doc" in the files path within the archive. Then unarchive the result.
# This turns out to be the quickest way I could find to get the correct files and rename them.
processor_msg "Collecting source files..."
bsdtar cf AppKit.doc.tar -s /^AppKit/AppKit.doc/ AppKit/*.j AppKit/**/*.j
bsdtar xf AppKit.doc.tar
rm AppKit.doc.tar
# Find sources relative to the project root
find "$project_root/$framework_name" -name "*.j" | bsdtar -s "|^$project_root/$framework_name/|$doc_dir_name/|" -cnf "$tar_file" -T -
# Now do the same thing with Foundation files.
bsdtar cf Foundation.doc.tar -s /^Foundation/Foundation.doc/ Foundation/*.j Foundation/**/*.j
bsdtar xf Foundation.doc.tar
rm Foundation.doc.tar
if [ -f "$tar_file" ]; then
processor_msg "Extracting archive to CWD..."
bsdtar xf "$tar_file"
rm "$tar_file"
else
processor_msg "ERROR: Failed to create tar archive for $framework_name." "red"
exit 1
fi
}
# Remove @import and @class from the source files, doxygen doesn't know what to do with them
# --- Run Collection ---
collect_sources "$1" "AppKit" "AppKit.doc"
collect_sources "$1" "Foundation" "Foundation.doc"
# --- Post-Process Files ---
processor_msg "--------------------------------------------------"
processor_msg "Removing @import and @class from source files..."
# These directories now exist in our CWD (the temp dir)
find AppKit.doc -name *.j -exec sed -e '/@import.*/ d' -e '/@class.*/ d' -i '' {} \;
find Foundation.doc -name *.j -exec sed -e '/@import.*/ d' -e '/@class.*/ d' -i '' {} \;