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

Automatic project update #1079

Closed
SirLynix opened this issue Nov 27, 2020 · 23 comments
Closed

Automatic project update #1079

SirLynix opened this issue Nov 27, 2020 · 23 comments

Comments

@SirLynix
Copy link
Member

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

When working on a project, using a makefile, visual studio and more, it happens we edit the xmake file, or add some files and we have to open a shell to rerun xmake project generation, which is a bit frustrating.

Describe the solution you'd like

It would be nice to have an option allowing xmake to regenerate the project (with the same parameters passed the first time) on start, or having a phony target doing so.

CMake is already doing something like that (even though it's much more slower than xmake)

However if something like that happens, it would be very nice for xmake to detect if a project regeneration is required and not do it if nothing changed (as regenerating a project everytime makes VS ask you to reload it and such), as CMake and Premake do for example.

I don't know if xmake already has something to know if something changed between runs.

Describe alternatives you've considered

Adding a phony target that regenerate the project myself, but I'm not sure how to detect the parameters and kind of project.

@waruqi
Copy link
Member

waruqi commented Nov 27, 2020

I tried it once before, but encountered many problems, I will continue to consider this feature, but I cannot guarantee that the current version will implement it.

@waruqi waruqi added this to the todo milestone Nov 27, 2020
@waruqi
Copy link
Member

waruqi commented Dec 7, 2020

We need only add a target named autoupdate to update it automatically.

target("autoupdate")
    set_kind("binary")
    on_build(function (target)
        if os.getenv("XMAKE_IN_VSTUDIO") then
            os.execv("xmake", {"project", "-k", "vsxmake"}, {detach = true, envs = {XMAKE_CONFIGDIR = os.tmpfile() .. ".xmake"}})
        end
    end)

@SirLynix
Copy link
Member Author

SirLynix commented Dec 7, 2020

Will try. Shouldn't it be a phony target?

@waruqi
Copy link
Member

waruqi commented Dec 8, 2020

Will try. Shouldn't it be a phony target?

Of course you can, but after setting to phony, the autoupdate target is invisible in vs. We cannot select it in vs to manually perform the update.

@SirLynix
Copy link
Member Author

So I had the chance to test it. It works but it will always regenerate visual studio files, causing the IDE to ask to reload the solution everytime I hit build everything.

Would it be possible to not regenerate a project file if they're up to date?

@SirLynix
Copy link
Member Author

Woops, I hit the wrong button.

@SirLynix SirLynix reopened this Dec 10, 2020
@waruqi
Copy link
Member

waruqi commented Dec 10, 2020

So I had the chance to test it. It works but it will always regenerate visual studio files, causing the IDE to ask to reload the solution everytime I hit build everything.

Would it be possible to not regenerate a project file if they're up to date?

target("autoupdate")
    set_kind("binary")
    on_build(function (target)
        import("core.project.depend")
        if os.getenv("XMAKE_IN_VSTUDIO") then
            depend.on_changed(function ()
                os.execv("xmake", {"project", "-k", "vsxmake"}, {detach = true, envs = {XMAKE_CONFIGDIR = os.tmpfile() .. ".xmake"}})
            end, {files = path.join(os.projectdir(), "vsxmake2019", "xxx.sln")}) -- this file is changed?
        end
    end)

@SirLynix
Copy link
Member Author

I get strange behavior with that, and it's still regenerating everytime.

lynix@SirLynixVanDesktop:/mnt/c/Projets/Burgwar/BurgWar$ xmake.exe -b update_xmake
[100%]: build ok!
lynix@SirLynixVanDesktop:/mnt/c/Projets/Burgwar/BurgWar$ xmake.exe install -o test_curl
error: please run `$xmake [target]` to build the following targets first:
  -> update_xmake

@waruqi
Copy link
Member

waruqi commented Dec 11, 2020

set kind as phony or override on_install()

target("autoupdate")
    set_kind("binary") -- or use phony
    on_install(function target() end)
    on_build(function (target)
        import("core.project.depend")
        if os.getenv("XMAKE_IN_VSTUDIO") then
            depend.on_changed(function ()
                os.execv("xmake", {"project", "-k", "vsxmake"}, {detach = true, envs = {XMAKE_CONFIGDIR = os.tmpfile() .. ".xmake"}})
            end, {files = path.join(os.projectdir(), "vsxmake2019", "xxx.sln")}) -- this file is changed?
        end
    end)

@SirLynix
Copy link
Member Author

It seems to fix the install but sadly it doesn't prevent the regeneration when I build the solution.

@waruqi
Copy link
Member

waruqi commented Dec 12, 2020

depend.on_changed does not work?

@SirLynix
Copy link
Member Author

I don't think so, everytime I build autoupdate (directly or via solution generation) the project is regenerated.

@waruqi
Copy link
Member

waruqi commented Dec 12, 2020

Ok, I will try it.

@waruqi waruqi modified the milestones: todo, v2.5.1 Dec 12, 2020
@waruqi
Copy link
Member

waruqi commented Dec 12, 2020

I have added a plugin.vsxmake.autoupdate rule in xmake on dev branch.

add_rules("mode.debug", "mode.release")
add_rules("plugin.vsxmake.autoupdate")

target("test")
    set_kind("binary")
    add_files("src/*.c")

@waruqi
Copy link
Member

waruqi commented Dec 12, 2020

It should work already.

@waruqi waruqi closed this as completed Dec 12, 2020
@SirLynix
Copy link
Member Author

It's working, but is there a way to have xmake automatically detects new .cpp files and regenerate the VS project if yes?
Ideally what would be great would be to regenerate each vsxmake file in memory and compare them with their current content on disk, and if it doesn't match then write it. That's what premake does.

@waruqi
Copy link
Member

waruqi commented Dec 27, 2020

? If the cpp file list in xmake.lua is changed, then it will also cause xmake.lua to be changed, and the vs project will be automatically generated during the next build.

@SirLynix
Copy link
Member Author

I'm not talking of a xmake.lua change but a filesystem one. Like having a add_files("src/*.cpp") and creating a cpp file.

@waruqi
Copy link
Member

waruqi commented Dec 27, 2020

I will try to improve it if I have time.

@waruqi waruqi reopened this Dec 27, 2020
@waruqi
Copy link
Member

waruqi commented Dec 27, 2020

I have improved it, you can try it again. (dev)

@SirLynix
Copy link
Member Author

Well now it's triggering everytime 😅

@waruqi
Copy link
Member

waruqi commented Dec 28, 2020

I works for me, you can create a simple project to test it.

@waruqi
Copy link
Member

waruqi commented Jan 19, 2021

I have fixed it.

@waruqi waruqi closed this as completed Jan 19, 2021
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

2 participants