pnkfelix / tango

Markdown-based Literate programming in Rust, integrated with Cargo.
Apache License 2.0
171 stars 12 forks source link

[WIP] Add alternative entry point to emit rerun-if-changed directive #18

Closed nsreeen closed 6 years ago

nsreeen commented 7 years ago

This introduces a second entry point as described in issue #12.

The new function (process_root_and_emit_rerun) writes a cargo:rerun-if-changed=PATH directive for each file tango manages or interacts with in a calling crate. These lines are written to the build script output file of the calling crate, where cargo will read them.

This makes sure that if any of the files tango is interested in change, the calling crate will be rebuilt.

pnkfelix commented 7 years ago

Hmm.

This assumes that everything in the src/ directory should cause a rebuild. And that is not true; e.g., if there are non-.md/.rs files stored under src/ (e.g. a notes.txt file), then this will emit rerun-if-changed for those files as well.

Now, you could fix that by revising the directory walk to only process file ended with .rs/.md. But I have a different suggestion.

Instead, I would add a flag to the Context struct that tracks whether we need to emit the rerun-if-changed directive, and then change Context::gather_inputs to emit the rerun-if-changed for each input it detects. (Either right before the calls to Context::check_transform, or within the body of Context::check_transform.)

nsreeen commented 7 years ago

thanks @pnkfelix! I started implementing this - rerun-if is now written from gather_inputs, at the point where .rs files are gathered.
I'm still working on emitting rerun-if for build.rs and tango.stamp, and the config struct

pnkfelix commented 7 years ago

@Nasreen123 hmm.

Interesting questions arise about whether it should be tango's job to emit rerun-if for the build.rs and for the tango.stamp...

nsreeen commented 7 years ago

Hi @pnkfelix Now rerun-if is being written only for md and rs files in the src folder. You're right that build.rs doesn't need one - changing it always triggers a rebuild. Manually testing things things are working as expected, I'm still working on tests

pnkfelix commented 6 years ago

Thanks Nasreen!