sassc icon indicating copy to clipboard operation
sassc copied to clipboard

Add new flag `--write-includes` for tracking imported dependencies

Open bitc opened this issue 6 years ago • 13 comments

This adds a new flag:

-D, --write-includes PATH   Write a file containing the dependencies that were imported.

When this flag is used, after sassc finishes compiling, it will write an additional file, containing a list of all the files that were imported. This is useful for integrating into build systems / live file watching, where you need to know which ".scss" files need to be recompiled after some arbitrary file on the file system has changed.

This is similar to gcc -MMD option, but here the format of the generated file is simply a list of filenames, one per line.

Happy to make any changes/improvements based on feedback.

bitc avatar May 24 '18 13:05 bitc

I've rebased this against master and cleaned it up a bit

bitc avatar Aug 19 '18 12:08 bitc

bump. @xzyfer

bitc avatar Nov 27 '18 13:11 bitc

ping @glebm

bitc avatar Feb 27 '19 20:02 bitc

This should probably be out on hold as the upcoming module system won't be compatible.

On Thu., 28 Feb. 2019, 7:55 am Bit Connor, [email protected] wrote:

ping @glebm https://github.com/glebm

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sass/sassc/pull/228#issuecomment-468026727, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjZWNyCuX1foyxY0C9lUspBFpUUHPdYks5vRvDBgaJpZM4UMOHF .

xzyfer avatar Feb 27 '19 22:02 xzyfer

Looking at the design of the upcoming module system, it'll be pretty much the same for this purpose (am I missing something?). Looks good to me.

glebm avatar Feb 28 '19 00:02 glebm

bump. @glebm @mgreter I can rebase this on top of master, or make any other fixes/improvements if necessary

bitc avatar Nov 28 '19 00:11 bitc

I'd say this is pretty interesting. Wish libsass had a possibility to do this before running everything, i.e just by parsing the files.

saper avatar Nov 28 '19 23:11 saper

bump @aaronkelton @xzyfer @am11 @mgreter

bitc avatar Jul 21 '20 12:07 bitc

This is a feature that I think should be included one way or another. Just this week I had to convert from compass to straight sassc, and the lack of dependency support makes the Makefile less robust than I'd like.

I love how simple this patch is, but I don't think the current PR is the right way to do it. In particular, I don't like the idea of passing a single option to compile_file() and compile_stdin(). If we continue this trend when adding more options to sassc, the function signatures would quickly get out of hand.

I'm not sure what is the best way to add dependency support. There are a few options I'd consider.

Option 1: Add a struct Sassc_Options

This may be the easiest way. The struct Sassc_Options would include the deps_outfile options, and become a place to hold additional options that are not used by libsass. (verbose? lint?) It may include struct Sass_Options so we only pass around one data structure everywhere, or may be its own independent thing.

The current sassc code passes around the infile and outfile parameters. These could be added to the struct Sassc_Options to simplify the compile_file() and compile_stdin() function signatures, or use the existing fields in struct Sass_Options to avoid duplication.

Option 2: Push the functionality down into libsass.

This would mean adding the deps_outfile to struct Sass_Options and including the code to write out the dependencies. This might be as simple as the current PR (writing it out after compiling), or, as @saper mentioned, adding a dependency check as a pre-flight task and leveraging that to create the dep files.

Option 2.5: Libsass as a separate pre-flight

If it's a separate pre-flight function, then sassc can support a separate "generate dependencies only" mode.

jlfranklin avatar Sep 29 '20 19:09 jlfranklin

As a separate issue, I'd prefer the format to better mimic the output as generated bygcc -MM. That is, instead of just a list of files, make it follow Make's dependency format:

styles.css : styles.scss _init.scss _page1.scss

jlfranklin avatar Sep 29 '20 19:09 jlfranklin

+1 for using the Make-style output format. This makes for easy use with Meson's depfiles support for constructs like custom_target.

Bob131 avatar Apr 26 '22 20:04 Bob131

This is useful for integrating into build systems / live file watching, where you need to know which ".scss" files need to be recompiled after some arbitrary file on the file system has changed.

This is similar to gcc -MMD option, but here the format of the generated file is simply a list of filenames, one per line.

In order to be useful to build systems, it would in fact make sense to emit gcc's -MMD output (a valid subset of Makefile), which "build systems" support, rather than emitting a list of unformatted text lines which build systems do NOT support.

eli-schwartz avatar Apr 29 '22 22:04 eli-schwartz

It will be very easy to modify this pull request to emit Makefile-style output (if that is what is wanted)

bitc avatar Apr 30 '22 12:04 bitc