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

"phony target" request #68

Closed
TitanSnow opened this Issue Apr 8, 2017 · 11 comments

Comments

Projects
None yet
2 participants
@TitanSnow
Contributor

TitanSnow commented Apr 8, 2017

Feature request!

The idea of phony target comes from makefile. It is a target that do not actually build anything.

I think it has meanings to add this feature. For example, I have testadd, testsub... So a phony target testsuite might be needed to build all tests together then put them into a certain directory. It's also possible in xmake today but a little troublesome.

There is also an another feature request. That is, $(xmake). makefile has $(MAKE) to let script use make itself. I found it's also useful to add such.

Oh, finally I suddenly get an idea. To let commandline pass vars to script. I think we could do things as below at last:

target("greet")
    set_phony(true)
    on_build(function (target)    -- on_build? or another better?
        print("Hello, $(name)")
    end)
$ xmake build greet name=World
Hello, World
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 9, 2017

Member

You can add a phony target without target kind to only add target's building deps. For example:

target("testsuite")
    set_default(false)
    add_deps("testprogadd", "testprogsub", "testprogmul", "testprogdiv", "testprogmod")

And run command to build these tests:

$ xmake build testsuite

xmake also support $(name) variable, for example:

option("name")
    set_showmenu(true)
    set_default("world")

target("test")
    set_kind("binary")
    add_files("*.c")
    after_build(function (target)
        print("hello $(name)!")
    end)

So the default value of this variable $(name) is world and you can also modify it:

$ xmake f --name=xmake

The result is:

hello xmake!

And you also can add $(name) variable to files:

target("test")
    set_kind("binary")
    add_files("$(name)/*c")
    add_links("$(name)_$(arch)")
    ...

Please checkout the lastest commit 23ffe01, I fixed print("$(name)") problem and supported phony target without target kind.

Thanks!

Member

waruqi commented Apr 9, 2017

You can add a phony target without target kind to only add target's building deps. For example:

target("testsuite")
    set_default(false)
    add_deps("testprogadd", "testprogsub", "testprogmul", "testprogdiv", "testprogmod")

And run command to build these tests:

$ xmake build testsuite

xmake also support $(name) variable, for example:

option("name")
    set_showmenu(true)
    set_default("world")

target("test")
    set_kind("binary")
    add_files("*.c")
    after_build(function (target)
        print("hello $(name)!")
    end)

So the default value of this variable $(name) is world and you can also modify it:

$ xmake f --name=xmake

The result is:

hello xmake!

And you also can add $(name) variable to files:

target("test")
    set_kind("binary")
    add_files("$(name)/*c")
    add_links("$(name)_$(arch)")
    ...

Please checkout the lastest commit 23ffe01, I fixed print("$(name)") problem and supported phony target without target kind.

Thanks!

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 9, 2017

Contributor

Oh, sounds interesting. What about $(xmake)?

Contributor

TitanSnow commented Apr 9, 2017

Oh, sounds interesting. What about $(xmake)?

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 9, 2017

Contributor

Sorry but I couldn't understand this code you wrote:

option("name")
    set_showmenu(true)
    set_default("world")

target("test")
    set_kind("binary")
    add_files("*.c")
    after_build(function (target)
        print("hello $(name)!")
    end)

Will target test do building? Why uses after_build?

Also, use xmake f --name=xmake seems to be not so direct. Why not directly pass it when building?

Another question, could I do something in phony target? For example, copying something?

Contributor

TitanSnow commented Apr 9, 2017

Sorry but I couldn't understand this code you wrote:

option("name")
    set_showmenu(true)
    set_default("world")

target("test")
    set_kind("binary")
    add_files("*.c")
    after_build(function (target)
        print("hello $(name)!")
    end)

Will target test do building? Why uses after_build?

Also, use xmake f --name=xmake seems to be not so direct. Why not directly pass it when building?

Another question, could I do something in phony target? For example, copying something?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 9, 2017

Member

Sorry, I couldn't understand what you mean.

If you want to pass variable to print("$(name)"), you can define option("name") and config it xmake f --name=xxx. I use after_build() to describe the usage of variable. It is only an example.

If you want to use make command in the xmake.lua, you can use os.run("make") or os.exec("make"), for example:

target("test")
    on_build(function (target)

        -- quietly run make
        os.run("make")
 
        -- run make and output info
        os.exec("make")
    end)

For second question, you can copying something on the custom build or other scripts.

target("testsuite")
    set_default(false)
    add_deps("testprogadd", "testprogsub", "testprogmul", "testprogdiv", "testprogmod")

    on_build(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
    after_build(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
    on_package(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
Member

waruqi commented Apr 9, 2017

Sorry, I couldn't understand what you mean.

If you want to pass variable to print("$(name)"), you can define option("name") and config it xmake f --name=xxx. I use after_build() to describe the usage of variable. It is only an example.

If you want to use make command in the xmake.lua, you can use os.run("make") or os.exec("make"), for example:

target("test")
    on_build(function (target)

        -- quietly run make
        os.run("make")
 
        -- run make and output info
        os.exec("make")
    end)

For second question, you can copying something on the custom build or other scripts.

target("testsuite")
    set_default(false)
    add_deps("testprogadd", "testprogsub", "testprogmul", "testprogdiv", "testprogmod")

    on_build(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
    after_build(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
    on_package(function (target)
        os.cp("file1", "file2", "dir/*", "to_destfile_or_dir")
    end
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 9, 2017

Contributor

I do not mean to use make in script. What I said is xmake: $(xmake). If someone has installed xmake into other dir not in PATH environment var, just use os.run("xmake") is not enough. It needs to get args[0] passed to xmake main program in script.

$ /path/to/xmake
# args[0] would be absolute path what is I wanna to get
Contributor

TitanSnow commented Apr 9, 2017

I do not mean to use make in script. What I said is xmake: $(xmake). If someone has installed xmake into other dir not in PATH environment var, just use os.run("xmake") is not enough. It needs to get args[0] passed to xmake main program in script.

$ /path/to/xmake
# args[0] would be absolute path what is I wanna to get
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 9, 2017

Member

You can get the absolute path from $(programdir)/xmake, for example:

os.run("$(programdir)/xmake")
Member

waruqi commented Apr 9, 2017

You can get the absolute path from $(programdir)/xmake, for example:

os.run("$(programdir)/xmake")
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 9, 2017

Contributor

😄

Contributor

TitanSnow commented Apr 9, 2017

😄

@TitanSnow TitanSnow closed this Apr 9, 2017

@waruqi waruqi removed the need response label Apr 9, 2017

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 16, 2017

Contributor

Are you sure it really works?

target("test")
    on_build(function (target)
        os.exec("$(programdir)/xmake --version")
    end)
    on_clean(function (target)
        os.exec("$(programdir)/xmake --version")
    end)

got:

error: invalid variable: $(programdir)

By the way, if there is not on_clean like

target("test")
    on_build(function (target)
        os.exec("$(programdir)/xmake --version")
    end)

got:

error: bad argument #1 to 'pairs' (table expected, got nil)

Why there must be on_clean?

The reason why I wanna use xmake inside is because I do not like add_subdirs. I found it getting into the way. For example, I have this path tree:

.
├── winpty
│   ├── ...
│   └── src
│       ├── ...
│       └── xmake.lua (1)
└── xmake.lua (2)

And xmake.lua (1) is below:

set_xmakever("2.1.3")
set_project("winpty")
set_languages("ansi","gnuxx11")
add_defines("_WIN32_WINNT=0x0501")
target("winpty")
    set_kind("shared")
    add_headers("include/*")
    add_includedirs("include","gen")
    add_defines("COMPILING_WINPTY_DLL")
    add_links("advapi32","user32")
    add_files(
                "libwinpty/AgentLocation.cc",
                "libwinpty/winpty.cc",
                "shared/BackgroundDesktop.cc",
                "shared/Buffer.cc",
                "shared/DebugClient.cc",
                "shared/GenRandom.cc",
                "shared/OwnedHandle.cc",
                "shared/StringUtil.cc",
                "shared/WindowsSecurity.cc",
                "shared/WindowsVersion.cc",
                "shared/WinptyAssert.cc",
                "shared/WinptyException.cc",
                "shared/WinptyVersion.cc")
    before_build(function (target)
        os.cd("shared")
        os.exec("UpdateGenVersion.bat")
        os.cd("..")
    end)

Sorry, it's little long. Can be seen at xmake.lua

Please have a mind at before_build. There I used os.cd.

I try to write xmake.lua (2) as this:

add_subdirs(path.join("winpty","src"))

But it fails with cannot change directory

So, when building subdirs, xmake does not enter it?

How to solve this? How to build submodule with xmake? Would be better if there is add_submodules?

Contributor

TitanSnow commented Apr 16, 2017

Are you sure it really works?

target("test")
    on_build(function (target)
        os.exec("$(programdir)/xmake --version")
    end)
    on_clean(function (target)
        os.exec("$(programdir)/xmake --version")
    end)

got:

error: invalid variable: $(programdir)

By the way, if there is not on_clean like

target("test")
    on_build(function (target)
        os.exec("$(programdir)/xmake --version")
    end)

got:

error: bad argument #1 to 'pairs' (table expected, got nil)

Why there must be on_clean?

The reason why I wanna use xmake inside is because I do not like add_subdirs. I found it getting into the way. For example, I have this path tree:

.
├── winpty
│   ├── ...
│   └── src
│       ├── ...
│       └── xmake.lua (1)
└── xmake.lua (2)

And xmake.lua (1) is below:

set_xmakever("2.1.3")
set_project("winpty")
set_languages("ansi","gnuxx11")
add_defines("_WIN32_WINNT=0x0501")
target("winpty")
    set_kind("shared")
    add_headers("include/*")
    add_includedirs("include","gen")
    add_defines("COMPILING_WINPTY_DLL")
    add_links("advapi32","user32")
    add_files(
                "libwinpty/AgentLocation.cc",
                "libwinpty/winpty.cc",
                "shared/BackgroundDesktop.cc",
                "shared/Buffer.cc",
                "shared/DebugClient.cc",
                "shared/GenRandom.cc",
                "shared/OwnedHandle.cc",
                "shared/StringUtil.cc",
                "shared/WindowsSecurity.cc",
                "shared/WindowsVersion.cc",
                "shared/WinptyAssert.cc",
                "shared/WinptyException.cc",
                "shared/WinptyVersion.cc")
    before_build(function (target)
        os.cd("shared")
        os.exec("UpdateGenVersion.bat")
        os.cd("..")
    end)

Sorry, it's little long. Can be seen at xmake.lua

Please have a mind at before_build. There I used os.cd.

I try to write xmake.lua (2) as this:

add_subdirs(path.join("winpty","src"))

But it fails with cannot change directory

So, when building subdirs, xmake does not enter it?

How to solve this? How to build submodule with xmake? Would be better if there is add_submodules?

@TitanSnow TitanSnow reopened this Apr 16, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 16, 2017

Member

I'm sorry, I forgot to add $(programdir) variable and I have added it and $(xmake) on commit 057493c. You can run command:

os.exec("$(xmake) --version")

About on_clean problem, I have fixed it on previous commit. You can test it again after updating xmake.

About the third problem, the default directoy of the before_build script is the project root directory ($(projectdir)). You can use $(scriptdir) variable to enter the current script(xmake.lua) directory

before_build(function (target)
        os.cd("$(scriptdir)/shared")
        os.exec("UpdateGenVersion.bat")
        os.cd("-")
    end)

Or

before_build(function (target)
        os.exec("$(scriptdir)/shared/UpdateGenVersion.bat")
end)

And it's no problem about add_subdirs, it's not directly related to change directory.

add_subdirs(path.join("winpty","src")). It works normally.

Member

waruqi commented Apr 16, 2017

I'm sorry, I forgot to add $(programdir) variable and I have added it and $(xmake) on commit 057493c. You can run command:

os.exec("$(xmake) --version")

About on_clean problem, I have fixed it on previous commit. You can test it again after updating xmake.

About the third problem, the default directoy of the before_build script is the project root directory ($(projectdir)). You can use $(scriptdir) variable to enter the current script(xmake.lua) directory

before_build(function (target)
        os.cd("$(scriptdir)/shared")
        os.exec("UpdateGenVersion.bat")
        os.cd("-")
    end)

Or

before_build(function (target)
        os.exec("$(scriptdir)/shared/UpdateGenVersion.bat")
end)

And it's no problem about add_subdirs, it's not directly related to change directory.

add_subdirs(path.join("winpty","src")). It works normally.

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 16, 2017

Contributor

Great!!!👍😄

Contributor

TitanSnow commented Apr 16, 2017

Great!!!👍😄

@TitanSnow TitanSnow closed this Apr 16, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 12, 2017

Member

I improved phony target to support the following case:

set_kind("binary")

target("test1")
    add_files("*.c")

target("test2")
    add_files("*.c")

target("alltests")
    set_kind("phony")    <---   If you do not set kind, this target kind is `binary` instead of `phony`
    add_deps("test1", "test2")
Member

waruqi commented May 12, 2017

I improved phony target to support the following case:

set_kind("binary")

target("test1")
    add_files("*.c")

target("test2")
    add_files("*.c")

target("alltests")
    set_kind("phony")    <---   If you do not set kind, this target kind is `binary` instead of `phony`
    add_deps("test1", "test2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment