Skip to content

Filter support added#16

Open
ccp-chargeback wants to merge 121 commits intocarbonengine:mainfrom
ccp-chargeback:filter-changes
Open

Filter support added#16
ccp-chargeback wants to merge 121 commits intocarbonengine:mainfrom
ccp-chargeback:filter-changes

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.
@ccp-chargeback ccp-chargeback marked this pull request as ready for review February 8, 2026 21:39
- One for .ini file that does not exist
- Another for .ini file with wrong format
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.

I love how many tests there are and the descriptions are super useful.

Some more comments.

I also think we should take advantage of your knowledge of the filter files and make add a file spec to the documentaiton for the filter ini files.

Here you can see resourceGroup file format https://carbonengine.github.io/resources/DesignDocuments/resourceGroupFileFormat.html

std::cout << "---------------------------" << std::endl;

TinyProcessLib::Process process1a(
arguments, workingDirectory,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need to change the working directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because the working directory is in the cmake made location for the generated exe where the tests are running.
I need the CLI to know what the working directory is in order to be able to resolve the relative contents of the .ini filter files correctly (as the files it wants to apply filter rules on are all relative to the TEST_DATA_BASE_PATH).
If I don't do that, then when it tries to resolve the relative paths from the .ini files it does so from the WRONG start position (i.e. not the TEST_DATA_BASE_PATH, but from the folder where the resources-cli.exe is located in CARBON_RESOURCES_CLI_EXE_FULLPATH)

This is also one of the reasons why I want to do the comparison on actual absolute lexical paths (see my earlier comment on: #16 (comment))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this base path be better passed in as an argument rather than relying on working directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Base path is being passed in now as an argument via the CLI (--filter-file-basepath)
The signature for the RunCLI() function takes in an optional parameter to set the working directory.
None of the tests however call it with an overriding working directory parameter.
All of them just use the default ("" empty string).

arguments.push_back( "--output-file" );
arguments.push_back( outputFilePath.lexically_normal().string() );

int res = RunCli( arguments, output, errorOutput, TEST_DATA_BASE_PATH );
Copy link
Collaborator

Choose a reason for hiding this comment

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

The working directory doesn't need to be changed, there is a helper to resolve paths that the other tests use.

e.g.
std::filesystem::path inputDirectory = GetTestFileFileAbsolutePath( "CreateResourceFiles/ResourceFiles" );

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See my other answers on the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Working directory is now not being passed in as a parameter to the RunCli() function.
The filter file basepath can however be set as a command line argument "--filter-file-basepath" which gets passed down as an argument to the tools library.

ccp-chargeback and others added 12 commits February 11, 2026 11:12
- Change the FilePathMatchesIncludeFilterRules() function to use relative paths for comparison on the incoming file vs the resolved path from the filter .ini file.
- Make sure that any path sent into the function or resolved from a .ini file are also force converted to their relative version, (from std::filesystem::current_path)
- Using relative paths for comparison can fail on Windows for a valid prefixmap entry of e.g. "rootRes:." where it has trouble interpreting e.g. a path of "./SomeFolder/*"
- Make sure to reset inFilePathAbs and resolvedPathAbs path variables to their normalized versions
- This should work for tests running on Windows ("gold" file comparison)
- Hope is that the macOS "gold" files will work as well (else re-run and generate those on a macOS machine and submit those)
- It is no longer needed after reliance on current working directory was removed.
…into filter-changes

Merge in correct macOS output files from upstream, and add a test for the new filter-changes functionality.
# Conflicts:
#	cli/src/CreateResourceGroupCliOperation.cpp
#	src/ResourceGroupImpl.cpp
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.

I left some comments but didn't finish completely.

I tried a build and was confused why my ini file was not being found. I pulled the code down to get a better idea. There are some issues with path handling still, confusion with relative/absolute path things.

I've managed to make a few local changes to sort most of it, I'll continue when I'm back on Thurs and push to this branch.


AddArgument( m_createResourceGroupExportResourcesDestinationPathId, "Represents the base path where the exported resources will be saved. Requires --export-resources", false, false, defaultImportParams.exportResourcesDestinationSettings.basePath.string() );

AddArgument( m_createResourceGroupIniFilterFilesArgumentId, "Path to INI file(s) for resource filtering.", false, true, "" );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should remove the (s) as it suggests this accepts a list.
The argument only accepts one path.

The append bool here being true results in docs added so user knows many can be supplied.
Path to INI file for resource filtering. [Accepts multiple] [default: ""]


AddArgument( m_createResourceGroupIniFilterFilesArgumentId, "Path to INI file(s) for resource filtering.", false, true, "" );

AddArgument( m_createResourceGroupIniFilterFilesBasePathArgumentId, "Base directory for resolving relative paths contained within filter INI file(s).", false, false, "" );
Copy link
Collaborator

Choose a reason for hiding this comment

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

(s) fine here


set (VCPKG_USE_HOST_TOOLS ON CACHE STRING "")
set (CMAKE_CXX_STANDARD 20 CACHE STRING "")
set (CMAKE_CXX_STANDARD 17 CACHE STRING "")
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 the story here?

// Check if the file, i.e. entry.path() should be included or excluded based on filtering rules
if( !resourceFilter.FilePathMatchesIncludeFilterRules( entry.path() ) )
{
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could add in a status update here.

fileProcessingInnerStatusSettings.Update( CarbonResources::StatusProgressType::UNBOUNDED, 0, 0, "Skipping file as it doesn't match filters: " + entry.path().string() );

Probably be very useful later.

Also, if all files are skipped then it will be a long time until any status updates were hit, might look like it's hanging.

int CliTestFixture::RunCli( std::vector<std::string>& arguments,
std::string* standardOutput /* = nullptr */,
std::string* errorOutput /* = nullptr */,
const std::string& workingDirectory /* = "" (empty = do not alter it) */ )
Copy link
Collaborator

Choose a reason for hiding this comment

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

working directory change here needs removing.
This way we stop others maybe creating changes that rely on working directory

// Only populate the output and errorOutput if the caller provided non-nullptr for them, otherwise discard them
TinyProcessLib::Process process1a(
arguments,
workingDirectory,
Copy link
Collaborator

Choose a reason for hiding this comment

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

workingDirectory doesn't need setting same reasoning as the previous one

{

int RunCli( std::vector<std::string>& arguments, std::string& output );
int RunCli( std::vector<std::string>& arguments, std::string* standardOutput = nullptr, std::string* errorOutput = nullptr, const std::string& workingDirectory = "" );
Copy link
Collaborator

Choose a reason for hiding this comment

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

working directory setting removal

std::string output;
std::string errorOutput;
std::vector<std::string> arguments;
std::filesystem::path inputDirectoryPath = GetTestFileFileAbsolutePath( "" ); // The base testData directory
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this give TEST_DATA_BASE_PATH?
Could use that instead

m_createResourceGroupExportResourcesDestinationPathId( "--export-resources-destination-path" )
m_createResourceGroupExportResourcesDestinationPathId( "--export-resources-destination-path" ),
m_createResourceGroupIniFilterFilesArgumentId( "--filter-file" ),
m_createResourceGroupIniFilterFilesBasePathArgumentId( "--filter-file-basepath" )
Copy link
Collaborator

Choose a reason for hiding this comment

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

The argument name is misleading. This isn't the base path of the filter file.
This is the base path from where the prefix maps are based

{
try
{
resourceFilter.Initialize( params.resourceFilterIniFiles, params.resourceFilterIniFilesBaseDirectory, params.directory );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would the filter file require the directory passed in?

I think there is still some confusion with paths happening here

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.

3 participants