Skip to content

Commit

Permalink
feat: find addons relative to executable
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Dec 2, 2023
1 parent f005291 commit 437c3f6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
- name: Install mrdocs from release package
run: |
set -x
sudo find packages -name 'MrDocs-*-Linux.tar.gz' -exec tar -xzf {} -C /usr/local --strip-components=1 \;
sudo find packages -name 'MrDocs-*-Linux.tar.gz' -exec tar -vxzf {} -C /usr/local --strip-components=1 \;
mrdocs --version
- name: Clone Boost.URL
Expand Down Expand Up @@ -358,7 +358,7 @@ jobs:
[[ $variant = multi ]] && multiline="true" || multiline="false"
printf "$config_template\n" $format $multiline > $(pwd)/boost/libs/url/mrdocs.yml
mkdir -p "demos/boost-url/$variant/$format"
mrdocs --config="$(pwd)/boost/libs/url/mrdocs.yml" "$(pwd)/boost/libs/url/__build__/compile_commands.json" --addons="$(pwd)/share/mrdocs/addons" --output="$(pwd)/demos/boost-url/$variant/$format"
mrdocs --config="$(pwd)/boost/libs/url/mrdocs.yml" "$(pwd)/boost/libs/url/__build__/compile_commands.json" --output="$(pwd)/demos/boost-url/$variant/$format"
done
asciidoctor -R "$(pwd)/demos/boost-url/$variant/adoc" -D "$(pwd)/demos/boost-url/$variant/adoc-asciidoc" "$(pwd)/demos/boost-url/$variant/adoc/**/*.adoc"
done
Expand Down
2 changes: 1 addition & 1 deletion include/mrdocs/Support/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ namespace detail

/// Check existing expected-like type
# define MRDOCS_CHECK_VOID(var) \
if (!detail::failed(var)) { \
if (detail::failed(var)) { \
return Unexpected(detail::error(var)); \
} \
void(0)
Expand Down
9 changes: 9 additions & 0 deletions include/mrdocs/Support/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ appendPath(
std::string_view name2,
std::string_view name3);

MRDOCS_DECL
std::string
appendPath(
std::string_view basePath,
std::string_view name1,
std::string_view name2,
std::string_view name3,
std::string_view name4);

/** Return an error if the path is not a directory.
*/
MRDOCS_DECL
Expand Down
16 changes: 16 additions & 0 deletions src/lib/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ appendPath(
return static_cast<std::string>(temp.str());
}

std::string
appendPath(
std::string_view basePath,
std::string_view name1,
std::string_view name2,
std::string_view name3,
std::string_view name4)
{
namespace path = llvm::sys::path;

SmallPathString temp(makeDirsy(basePath));
path::append(temp, name1, name2, name3, name4);
path::remove_dots(temp, true);
return static_cast<std::string>(temp.str());
}

Error
requireDirectory(
std::string_view pathName)
Expand Down
30 changes: 15 additions & 15 deletions src/tool/Addons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ setupAddonsDir(
return {};
}

// Set addons dir from process working directory
std::string addonsDir = llvm::sys::fs::getMainExecutable(argv0, addressOfMain);
MRDOCS_CHECK(addonsDir, "getMainExecutable failed");
addonsDir = files::makeDirsy(files::appendPath(
files::getParentDir(addonsDir), "addons"));
Error err = files::requireDirectory(addonsDir);
if (!err.failed())
// Set addons dir from environment variable
auto addonsEnvVar = llvm::sys::Process::GetEnv("MRDOCS_ADDONS_DIR");
if (addonsEnvVar)
{
MRDOCS_CHECK(*addonsEnvVar, "MRDOCS_ADDONS_DIR is empty");
std::string addonsDir = files::makeDirsy(files::normalizePath(*addonsEnvVar));
MRDOCS_TRY(files::requireAbsolute(addonsDir));
MRDOCS_TRY(files::requireDirectory(addonsDir));
addonsDirArg.getValue() = addonsDir;
return {};
}

// Set addons dir from environment variable
MRDOCS_TRY(
std::string addonsEnvVar,
llvm::sys::Process::GetEnv("MRDOCS_ADDONS_DIR"),
"no MRDOCS_ADDONS_DIR in environment");
addonsDir = files::makeDirsy(files::normalizePath(addonsEnvVar));
MRDOCS_TRY(files::requireAbsolute(addonsDir));
MRDOCS_TRY(files::requireDirectory(addonsDir));
// Set addons dir from process working directory
std::string execPath = llvm::sys::fs::getMainExecutable(argv0, addressOfMain);
MRDOCS_CHECK(execPath, "getMainExecutable failed");
std::string binDir = files::getParentDir(execPath);
std::string addonsDir = files::makeDirsy(files::appendPath(
binDir, "..", "share", "mrdocs", "addons"));
Error err = files::requireDirectory(addonsDir);
MRDOCS_CHECK(err);
addonsDirArg.getValue() = addonsDir;
return {};
}
Expand Down

0 comments on commit 437c3f6

Please sign in to comment.