-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from nikitalita/ppj-parsing
PPJ support and pre-scan namespace resolution
- Loading branch information
Showing
18 changed files
with
1,405 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,13 @@ on: | |
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
release: | ||
types: [created] | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Release | ||
PROJECT_NAME: Caprica | ||
CMAKE_ARGS: "-DCHAMPOLLION_USE_STATIC_RUNTIME:BOOL=TRUE -DENABLE_STATIC_RUNTIME:BOOL=TRUE -DCMAKE_INSTALL_PREFIX:STRING=build/extern -DVCPKG_TARGET_TRIPLET:STRING=x64-windows-static -DCMAKE_TOOLCHAIN_FILE:STRING=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" | ||
|
||
jobs: | ||
|
@@ -51,8 +54,32 @@ jobs: | |
uses: actions/[email protected] | ||
with: | ||
# Artifact name | ||
name: Caprica | ||
name: ${{ env.PROJECT_NAME }} | ||
# A file, directory or wildcard pattern that describes what to upload | ||
path: build/Caprica/Release/Caprica.exe | ||
# The desired behavior if no files are found using the provided path. | ||
retention-days: 90 | ||
|
||
|
||
release: | ||
if: startsWith(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
needs: build | ||
steps: | ||
- name: Download artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{ env.PROJECT_NAME }} | ||
path: artifacts/${{ env.PROJECT_NAME }} | ||
- name: Zip artifacts | ||
run: | | ||
ls -la artifacts/* | ||
cd artifacts/${{ env.PROJECT_NAME }} | ||
zip -r9 "../${{ env.PROJECT_NAME }}-${{ github.ref_name }}.zip" * | ||
- name: Release | ||
uses: nikitalita/[email protected] | ||
with: | ||
files: | | ||
artifacts/${{ env.PROJECT_NAME }}-${{ github.ref_name }}.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
#include "CapricaInputFile.h" | ||
#include <common/CapricaConfig.h> | ||
#include <common/CapricaInputFile.h> | ||
#include <common/FSUtils.h> | ||
#include <common/parser/PapyrusProject.h> | ||
#include <filesystem> | ||
|
||
namespace caprica { | ||
|
||
std::filesystem::path IInputFile::resolved_relative() const { | ||
if (!resolved) | ||
return {}; | ||
auto rel = absPath.lexically_relative(absBaseDir); | ||
if (rel == ".") | ||
return {}; | ||
return rel; | ||
} | ||
|
||
std::filesystem::path IInputFile::resolved_absolute() const { | ||
if (!resolved) | ||
return {}; | ||
return absPath; | ||
} | ||
|
||
std::filesystem::path IInputFile::resolved_absolute_basedir() const { | ||
if (!resolved) | ||
return {}; | ||
return absBaseDir; | ||
} | ||
|
||
std::filesystem::path IInputFile::resolved_relative_parent() const { | ||
if (!resolved) | ||
return {}; | ||
auto rel = resolved_relative(); | ||
if (rel.empty()) | ||
return {}; | ||
return rel.parent_path(); | ||
} | ||
|
||
std::filesystem::path IInputFile::find_import_dir(const std::filesystem::path& path) { | ||
for (auto& dir : conf::Papyrus::importDirectories) | ||
if (dirContains(path, dir.resolved_absolute())) | ||
return dir.resolved_absolute(); | ||
return {}; | ||
} | ||
|
||
bool IInputFile::dirContains(const std::filesystem::path& path, const std::filesystem::path& dir) { | ||
if (path.is_absolute()) { | ||
// check if the path is contained in the import directory | ||
auto rel = path.lexically_relative(dir).string(); | ||
if (!rel.empty() && !rel.starts_with("..")) | ||
return true; | ||
} else { | ||
if (std::filesystem::exists(dir / path)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
IInputFile::IInputFile(const std::filesystem::path& _path, bool noRecurse, const std::filesystem::path& _cwd) | ||
: noRecurse(noRecurse), | ||
rawPath(std::move(_path)), | ||
cwd(_cwd.empty() ? std::filesystem::current_path() : std::move(FSUtils::canonicalFS(_cwd))) { | ||
} | ||
|
||
bool IInputFile::exists() const { | ||
if (!resolved) | ||
return false; | ||
return std::filesystem::exists(resolved_absolute()); | ||
} | ||
|
||
static constexpr char const curDir[3] = { '.', FSUtils::SEP, 0 }; | ||
static constexpr char const parent[4] = { '.', '.', FSUtils::SEP, 0 }; | ||
std::filesystem::path getCorrectBaseDir(const std::filesystem::path& normalPath, | ||
const std::filesystem::path& absBaseDir) { | ||
// for every 2 ..s in the path, remove a directory from the base dir | ||
auto str = normalPath.string(); | ||
auto ret = absBaseDir; | ||
while (str.starts_with(parent)) { | ||
ret = ret.parent_path(); | ||
str = str.substr(3); | ||
} | ||
return ret; | ||
} | ||
|
||
InputFile::InputFile(const std::filesystem::path& _path, bool noRecurse, const std::filesystem::path& _cwd) | ||
: IInputFile(_path, noRecurse, _cwd) { | ||
requiresPreParse = true; // we always require pre-parse for non-PCompiler-compatible input files | ||
} | ||
|
||
bool InputFile::resolve() { | ||
auto normalPath = FSUtils::normalize(rawPath); | ||
if (!normalPath.is_absolute()) { | ||
absPath = FSUtils::canonicalFS(cwd / normalPath); | ||
absBaseDir = find_import_dir(absPath); | ||
if (absBaseDir.empty()) { | ||
absBaseDir = getCorrectBaseDir(normalPath, cwd); | ||
} | ||
} else { | ||
absPath = FSUtils::canonicalFS(normalPath); | ||
absBaseDir = find_import_dir(absPath); | ||
if (absBaseDir.empty()) { | ||
absBaseDir = absPath.parent_path(); | ||
} | ||
} | ||
|
||
if (std::filesystem::exists(absPath)) { | ||
if (std::filesystem::is_directory(absPath)) | ||
isFolder = true; | ||
resolved = true; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
ImportDir::ImportDir(const std::filesystem::path& _path, bool noRecurse, const std::filesystem::path& _cwd) | ||
: IInputFile(_path, noRecurse, _cwd) { | ||
requiresPreParse = true; // we always require pre-parse for import dirs | ||
import = true; | ||
isFolder = true; | ||
resolve(); // we resolve import dirs immediately | ||
} | ||
|
||
bool ImportDir::resolve() { | ||
if (!rawPath.is_absolute()) | ||
absPath = FSUtils::canonicalFS(cwd / rawPath); | ||
else | ||
absPath = FSUtils::canonicalFS(rawPath); | ||
absBaseDir = absPath; | ||
if (std::filesystem::exists(absPath) && std::filesystem::is_directory(absPath)) { | ||
resolved = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
PCompInputFile::PCompInputFile(const std::filesystem::path& _path, | ||
bool noRecurse, | ||
bool isFolder, | ||
const std::filesystem::path& _cwd) | ||
: IInputFile(_path, noRecurse, _cwd) { | ||
isFolder = isFolder; | ||
} | ||
|
||
bool PCompInputFile::resolve() { | ||
std::filesystem::path normalPath = FSUtils::objectNameToPath(rawPath.string()); | ||
if (!isFolder && normalPath.extension().empty()) | ||
normalPath.replace_extension(".psc"); | ||
normalPath = FSUtils::normalize(normalPath); | ||
std::string str = normalPath.string(); | ||
// special case for relative paths that contain parent/cwd refs | ||
if (!normalPath.is_absolute() && (str == "." || str == ".." || str.starts_with(curDir) || str.contains(parent))) { | ||
absPath = FSUtils::canonicalFS(cwd / normalPath); | ||
absBaseDir = getCorrectBaseDir(normalPath, cwd); | ||
|
||
if (!std::filesystem::exists(absPath)) | ||
return false; | ||
resolved = true; | ||
return true; | ||
} | ||
|
||
// if this is a relative folder path, and the folder is in the cwd, use cwd as the base dir | ||
if (isFolder && !normalPath.is_absolute() && dirContains(normalPath, cwd)) | ||
absBaseDir = getCorrectBaseDir(normalPath, cwd); | ||
else | ||
absBaseDir = find_import_dir(normalPath); | ||
|
||
if (absBaseDir.empty()) | ||
return false; | ||
|
||
if (!normalPath.is_absolute()) | ||
absPath = FSUtils::canonicalFS(absBaseDir / normalPath); | ||
else | ||
absPath = FSUtils::canonicalFS(normalPath); | ||
|
||
if (!std::filesystem::exists(absPath)) | ||
return false; | ||
if (isFolder && !std::filesystem::is_directory(absPath)) | ||
return false; | ||
|
||
resolved = true; | ||
return true; | ||
} | ||
|
||
} // namespace caprica |
Oops, something went wrong.