Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow target:fileconfig() for headerfiles #4831

Closed
charlesseizilles opened this issue Mar 13, 2024 · 8 comments
Closed

Allow target:fileconfig() for headerfiles #4831

charlesseizilles opened this issue Mar 13, 2024 · 8 comments

Comments

@charlesseizilles
Copy link
Contributor

charlesseizilles commented Mar 13, 2024

Is your feature request related to a problem? Please describe.

I have a custom rule that calls clang-format on my code on before_build, but I wish for some files not to be auto-formatted. I added a config like so:

add_files("**.cpp")
add_headerfiles("**.hpp")
add_files("source.cpp", {do_not_format = true})
add_headerfiles("source.hpp", {do_not_format = true})

but when the rule runs, fileconfig always returns nil for headers

local files = table.join(target:sourcefiles(), target:headerfiles())

for _, v in pairs(files) do
	local fileconfig = target:fileconfig(v, "do_not_format")

	local do_format = true
	if fileconfig then
		do_format = not fileconfig.do_not_format
	end

	if do_format then
		os.vexecv(clangformat, {"--style=file", "-i", v})
	end
end

Describe the solution you'd like

I would like for target:fileconfig() to return the configuration specified when calling add_headerfiles

Describe alternatives you've considered

Specifing the files I do not want to format at the target-level like so

add_values("not_formatted_files", "source.cpp")
add_values("not_formatted_files", "source.hpp")

But it is much less idiomatic, less elegant, and increases my rule's complexity

Additional context

No response

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Allow target:fileconfig() for header files

@waruqi
Copy link
Member

waruqi commented Mar 14, 2024

it works for me. and target:fileconfig has only one argument.

target("test")
    set_kind("binary")
    add_files("src/*.cpp", {do_not_format = true})
    on_config(function (target)
        for _, file in ipairs(target:sourcefiles()) do
            local fileconfig = target:fileconfig(file)
            print(file, fileconfig)
        end
    end)
ruki-2:test ruki$ xmake
src/main.cpp {
  do_not_format = true
}

[100%]: build ok, spent 0.511s

But it only supports add_files now.

@charlesseizilles
Copy link
Contributor Author

oh, but this issue is about header files

target("test")
    set_kind("binary")
    add_files("source.cpp", {do_not_format = true})
    add_headerfiles("header.hpp", {do_not_format = true})
    on_config(function (target)
        for _, file in ipairs(table.join(target:sourcefiles(), target:headerfiles())) do
            local fileconfig = target:fileconfig(file)
            print(file, fileconfig)
        end
    end)
> xmake f
source.cpp {
  do_not_format = true
}

header.hpp

But it only supports add_files now.

I know, that's why I opened this feature request

@waruqi
Copy link
Member

waruqi commented Mar 14, 2024

try this patch #4836

xmake update -s github:xmake-io#fileconfig
target("test")
    set_kind("static")
    add_files("src/*.cpp", {do_not_format = true})
    add_headerfiles("src/*.h", {do_not_format = true})
    on_config(function (target)
        print(target:fileconfig("src/main.cpp")) -- add_files
        print(target:fileconfig("src/test.h", {filetype = "headerfiles"})) -- add_headerfiles
    end)

@waruqi waruqi added this to the v2.8.9 milestone Mar 14, 2024
@charlesseizilles
Copy link
Contributor Author

xmake update -s github:xmake-io#fileconfig returned

> xmake update -s github:xmake-io#fileconfig
error: ssh: Could not resolve hostname github: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I could update with xmake update -s https://github.com/xmake-io/xmake.git#fileconfig
Then the output is

> xmake f
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.38.33133
{
  do_not_format = true
}


with the script

@waruqi
Copy link
Member

waruqi commented Mar 14, 2024

It works for me.

Please make sure it has been updated.

$xmake
{
  do_not_format = true
}

{
  do_not_format = true
}

@charlesseizilles
Copy link
Contributor Author

Sorry, my header was test.hpp, and not test.h. It works well!

@waruqi
Copy link
Member

waruqi commented Mar 15, 2024

I have merged this patch and fix some issues. xmake update -s dev

@waruqi waruqi closed this as completed Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants