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 finding common makefiles at top of the workspace #1175

Closed
jayvdb opened this issue Oct 13, 2024 · 10 comments
Closed

Allow finding common makefiles at top of the workspace #1175

jayvdb opened this issue Oct 13, 2024 · 10 comments
Assignees

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Oct 13, 2024

Feature Description

Context is #1163

A workspace member Makefile.toml should be able to easily include (extend) common tasks/rules/etc from a cargo-make compliant toml file that can be located from the top of the workspace.

Currently one needs to do

extend = [{ path = "../../../makefiles/tools.toml" }]

And the number of "../" depends on the level of the workspace member. This isnt bad, as it is accurate, but it could be improved upon.

Describe The Solution You'd Like

I suspect that some very basic and rarely modified (and probably should be immutable) cargo-make defined envvars can be set early enough in the process so that this works:

extend = [{ path = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/makefiles/tools.toml" }]

Code Sample

sagiegurari added a commit that referenced this issue Oct 17, 2024
@sagiegurari
Copy link
Owner

@jayvdb pushed a solution in dev branch 0.37.23 and would love if you can check it.
you now have an additional keyword apart of path, relative. it gets 2 optional values: crate, workspace.
to specify that the path provided is relative either to the current crate root or workspace root.
would love your feedback.

you can look at the extends_list.toml example of how to use it

@jayvdb
Copy link
Contributor Author

jayvdb commented Oct 17, 2024

Note using relative = "something-else" doesnt emit any warning that it is invalid.

In all the cases I have, relative = "workspace" on that branch isn't working.

I have a "services/" directory under the workspace root. It has no files in that directory - only sub-directories for each workspace member.

I have other cases where the workspace member is under x/y/z/workspace_member_crate_here. None of x, y or z have a Cargo.toml or Makefile.toml - they are only structural.

Also I have Makefile.toml in subdirs that are not a crate - i.e. there is no Cargo.toml there.

@jayvdb
Copy link
Contributor Author

jayvdb commented Oct 17, 2024

services/serviceA/Makefile.toml:

extend = [{ path = "makefiles/tools.toml", relative = "workspace" }]

results in

> cargo make -l debug
[cargo-make] INFO - cargo make 0.37.22
[cargo-make] ERROR - Descriptor file: "/path/to/workspace_root/services/serviceA/makefiles/tools.toml" not found.

The version made me think maybe I had the wrong binary, but seems like this is correct per 8e7ca82

@sagiegurari
Copy link
Owner

ya i only bump the version before releasing....

can you share more details like how the workspace looks like, the makefiles, etc so i can reproduce?

@sagiegurari
Copy link
Owner

also if you run with "-v" i'll see some debug logs of if it finds and where it finds the crate/workspace roots. so that might be helpful as well for me

@sagiegurari
Copy link
Owner

just added a 'workspace' example which seems to work well so need that debug info and project structure and makefiles to understand better.

@sagiegurari
Copy link
Owner

is t possible you don't have a Cargo.toml at the workspace root?
did you check the workspace example i pushed? which works

sagiegurari added a commit that referenced this issue Oct 19, 2024
@sagiegurari
Copy link
Owner

@jayvdb adding 2 more things in latest diff

  1. "git" as an option. it will search for first top .git folder
  2. warning in case an invalid value is defined but still will default to makefile as relative to

@jayvdb
Copy link
Contributor Author

jayvdb commented Oct 19, 2024

sorry - been very busy

is t possible you don't have a Cargo.toml at the workspace root?

no.

did you check the workspace example i pushed?

no. sorry. I reinstalled using the latest and it still doesnt work in my monorepo.

I am 99% sure it is because we have the structure explained above that has multiple subdirectories. Your example only has one level.

/home/jayvdb/work/project_root/services/serviceA> cargo make -v
...
[cargo-make] VERBOSE - No load script defined.
[cargo-make] VERBOSE - External config parent path: .
[cargo-make] VERBOSE - Loading tasks from file: makefiles/tools.toml base directory: ., relative to: WorkspaceRoot
[cargo-make] VERBOSE - Looking for project root from directory: "/home/jayvdb/work/project_root/services/serviceA"
[cargo-make] VERBOSE - project root: Some(
    "/home/jayvdb/work/project_root/services/serviceA",
)
[cargo-make] VERBOSE - Looking for project root from directory: "/home/jayvdb/work/project_root/services/serviceA/.."
[cargo-make] VERBOSE - Looking for project root from directory: "/home/jayvdb/work/project_root/services/serviceA"
[cargo-make] VERBOSE - workspace root: Some(
    "/home/jayvdb/work/project_root/services/serviceA",
)
[cargo-make] ERROR - Descriptor file: "/home/jayvdb/work/project_root/services/serviceA/makefiles/tools.toml" not found.
[cargo-make] WARN - Build Failed.

"git" as an option. it will search for first top .git folder

this works

warning in case an invalid value is defined but still will default to makefile as relative to

roger that.

@sagiegurari
Copy link
Owner

@jayvdb released

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