Skip to content

add global interface "set_default_target"#65

Closed
ghost wants to merge 5 commits intodevfrom
unknown repository
Closed

add global interface "set_default_target"#65
ghost wants to merge 5 commits intodevfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 31, 2017

This pull is a feature adding.

Sometimes I don't want end-users to build all targets by default. Just like my libBG project, the "bg" target for building library is main, and other targets for building test program is meaningless to end-users. So I think it would be better to add a interface to let people like me choose default target manually.

This "set_default_target" is applied to task "build", "package", "install" and "run". I do not apply it to other task like "uninstall" because it might trouble end-user. (They always like to uninstall everything)

Design is that just do such work to xmake.lua just like set_project is OK:

set_default_target("bg")

Then the default target will be "bg" instead of "all".

TitanSnow added 5 commits March 31, 2017 19:46
add global interface "set_default_target"
to let it be able to override target "all"
when target isn't specified

partly supported by task "build"
@waruqi
Copy link
Copy Markdown
Member

waruqi commented Mar 31, 2017

You can pass the given target name to build or install it.

For example:

# only build target: bg
$ xmake build bg

# only install target: bg
$ xmake install bg 

# only uninstall target: bg
$ xmake uninstall bg 

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Mar 31, 2017

I have added set_default api to each target and you can use this interface to set multiple default targets.

Please try it from the lastest commit from dev branch.

For example:

target("test1")
    set_default(false)

target("test2")
    set_default(true)

target("test3")
    ...

If you run commands: xmake, xmake install, xmake package, xmake run, the behavior is

target behavior
test1 will be not built and installed .. by default
test2 will be built and installed .. by default
test3 will be built and installed .. by default

And you can also force to build and install all targets:

$ xmake [-a|--all]
$ xmake install [-a|--all]
$ xmake run [-a|--all]

I do not apply it to other task like "xmake uninstall", "xmake clean".

: )

@ghost
Copy link
Copy Markdown
Author

ghost commented Mar 31, 2017

Good but I think specifying for each target is a bit cumbersome. Why not a global setting interface? If multiple default has meanings, I think it would be simpler to be set_default_targets instead of specifying in each target. Some projects might have tons of targets, But the main targets are always not too many. 🤔

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 1, 2017

I don't want to add too much apis to global scope and this interface name is a little long. set_default only affects the target scope. : )

You don't need to set default for each target. All targets will be built by default if don't call set_default to set default property.This behavior will be compatible with older versions.

You can only call set_default to disable the given target. For example:

-- it will be built and install by default
target("test1")
    ...

-- it will be built and install by default
target("test2")
    ...

-- only `test3` target will be not built and install by default
target("test3")
    set_default(false)

You need only to set one target.

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 1, 2017

I know your meaning, but I'm afraid that you don't get my point. My meaning is that to disable target is used more usual than to enable a target, so api to enable could only set once but to disable need to set many times. Also, if one project don't do anything special about this, the behavior will be compatible with older versions as well.

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 1, 2017

I know, but I think that to enable target is used more usual than to disable a target.

And I rarely see the need to manually disable a target. : )

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 1, 2017

All right, maybe you're right 😺 I keep my opinion.

@ghost ghost closed this Apr 1, 2017
@ghost ghost deleted the TitanSnow branch April 1, 2017 03:21
@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 1, 2017

I think xmake build all should be kept. It's simpler and I'm used to building all with this.

$ xmake build all
error: assertion failed!

@waruqi

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 1, 2017

You can try run xmake -a or xmake --all.

May be conflict with target("all") if uses build all.

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 1, 2017

I see

@waruqi
Copy link
Copy Markdown
Member

waruqi commented Apr 17, 2017

And then I thought about it. You can also disable all targets in the root scope and only enable target you need. for example:

-- disable all targets by default
set_default(false)

-- only `test1` target will be built and install by default
target("test1")
    set_default(true)

-- other targets will be not built and install by default
for _, name in ipairs({"test2", "test3", "test4" ... }) do
    target(name)
        ...
end

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 17, 2017

😸

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant