Skip to content

Conversation

@ccp-chargeback
Copy link
Collaborator

Allow filtering of included resource files based on rules defined in one or more supplied filter.ini files.
Same changes as in PR/14 (done to try to trigger TC build on new project after latest changes from template project were added)

The change contains:

  • Reading and parsing of .ini filter files.
  • Allow overrides of include/exclude rules
  • Support wildcard filters:
    • "*" = current folder
    • "..." = any subfolder
  • Define priorities for include/exclude filter:
    • Based on folder/file hierarcy
    • Include/Exclude sameName file based on its hierarcy in each
  • Add CLI integration
  • Add loads of test coverage

Make use of existing filePath test functions
Next step, add missing tests.
Also fixed clang-tidy suggestions
- Do some function name changes to reduce stuttering.
- It worked (wrong) on Windows
- Failed on macOS
- Caused a warning as error on macOS
- Wasn't being used so safe to remove.
- Fails to build on macOS (incorrect casing, warning as errors)
…ePaths

- Temporarily adding debug information to test in order to see why it is failing for macOS in TeamCity
Changed tests:
- ResourceFilter_Load_validSimpleExample1_ini_usingRelativePaths
- ResourceFilter_Load_validSimpleExample1_ini_usingAbsolutePaths
- ResourceFilter_Load_validComplexExample1_ini_usingRelativePaths
- ResourceFilter_Load2iniFiles_validComplexExample1_and_validSimpleExample1

New tests:
- ResourceFilter_Load_validComplexExample1_ini_usingAbsolutePaths
- Done to generate the missing "gold" compare files on macOS
Copy link
Collaborator

@CCPCookies CCPCookies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, left some comments.

Not managed to go through it completely yet but just wanted to submit this for now as I ran out of day.

} No newline at end of file
}

void CliTestFixture::CleanupTestOutputFiles( const std::vector<std::filesystem::path>& filesToRemove )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be called just RemoveFiles as it could be called with any file, not just test output files.

#include <FilterResourceFile.h>
#include <ResourceFilter.h>

TEST_F( ResourceFilterTest, Example1IniParsing )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name is not descriptive; from test name it should be obvious what the test is testing.


// -----------------------------------------

TEST_F( ResourceFilterTest, FilterResourceFilter_OnlyIncludeFilter )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From title I'm not sure what this test is supposed to do.

EXPECT_TRUE( excludes.empty() );
}

TEST_F( ResourceFilterTest, FilterResourceFilter_OnlyExcludeFilter_Toplevel )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, filter name is confusing.

EXPECT_EQ( includes[0], "*" ); // Wild-card added when no include filter specified for TOP-LEVEL filter
}

TEST_F( ResourceFilterTest, FilterResourceFilter_OnlyExcludeFilter_Inline )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


#include <string>
#include <map>
#include <vector>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

#define FILTERNAMEDSECTION_H

#include <string>
#include <vector>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

// Resolved PathMap for all named sections defined in a resource .ini file
std::map<std::string, FilterResourceFilter> m_iniFileResolvedPathMap;

void ParseIniFile();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of having a function below members.

Personally, I like to have two private: areas to split private functions and private members but I think our coding standards says not to do this.


bool HasFilters() const
{
return !m_filterFiles.empty();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inline this?

FilterResourceFile::FilterResourceFile( const std::filesystem::path& iniFilePath ) :
m_iniFilePath( iniFilePath )
{
m_iniFileResolvedPathMap.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this always be clear at this point anyway?

Copy link
Collaborator

@CCPCookies CCPCookies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely lots of stuff due to this being a draft.
Made a first pass of it now.

{

FilterResourceFilter::FilterResourceFilter( const std::string& rawFilter, bool isToplevelFilter /* = false */ ) :
m_rawFilter( rawFilter ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string being passed by const ref here, fine with that.
Previously in other areas std::move was used which I am also fine with.

Not huge deal but a bit strange to have two styles in the changes.

@@ -0,0 +1,20 @@
// Copyright © 2025 CCP ehf.

#include <stdexcept>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

m_respaths( respaths, parentPrefixMap, m_filter ),
m_resfile( resfile.empty() ? std::nullopt : std::make_optional<FilterResourcePathFile>( resfile, parentPrefixMap, m_filter ) )
{
m_resolvedCombinedPathMap.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already clear?

}

// Return empty map if no resfile present
static const std::map<std::string, FilterResourceFilter> emptyResfileMap;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels odd.Assuming this was a way for this function to sort of continue on fail.

Is it important to hide this failure from the caller?

  1. Have it return a bool and take in a ref to the map which gets populated on success. Though probably requires a copy.

  2. Perhaps it doesn't make full sense to have a function to GetResourceResfileMap from a named section? Perhaps caller should access resfile externally to this and so this function no longer is a wrapper around this data? (Hard to fully grasp from GitHub Diff sorry)


FilterPrefixMap::FilterPrefixMap( const std::string& rawPrefixMap )
{
m_prefixMapEntries.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, isn't this clear already?

{
// Replace ... with a unique token
std::string pat = pattern;
std::string token = "\x01";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to follow our constants coding guidelines

include/RollingChecksum.h
include/ScopedFile.h
include/StatusCallback.h
include/FilterResourceFile.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list was alphabetical :D but this can go down as a nitpick :D

src/ScopedFile.cpp
src/Patching.cpp
src/RollingChecksum.cpp
src/FilterResourceFile.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above :D

vcpkg_registry_cache/

### Ignored Test Run Files ###
/tests/testData/IgnoredTestOutputFiles/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? There are now output files generated in the repo during test?

include(cmake/CcpBuildConfigurations.cmake)

find_package(yaml-cpp CONFIG REQUIRED)
find_package(unofficial-inih CONFIG REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the unofficial name? Is it that we use features that are not strictly supported through just inih or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants