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

Add new flag --write-includes for tracking imported dependencies #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bitc
Copy link
Contributor

@bitc bitc commented May 24, 2018

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 bitc force-pushed the write-includes branch 2 times, most recently from b81a349 to 10e97fe Compare August 19, 2018 12:24
@bitc
Copy link
Contributor Author

bitc commented Aug 19, 2018

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

@bitc
Copy link
Contributor Author

bitc commented Nov 27, 2018

bump. @xzyfer

@bitc
Copy link
Contributor Author

bitc commented Feb 27, 2019

ping @glebm

@xzyfer
Copy link
Contributor

xzyfer commented Feb 27, 2019 via email

@glebm
Copy link
Contributor

glebm commented Feb 28, 2019

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.

@bitc
Copy link
Contributor Author

bitc commented Nov 28, 2019

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

@saper
Copy link
Member

saper commented Nov 28, 2019

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.

@bitc
Copy link
Contributor Author

bitc commented Jul 21, 2020

bump @aaronkelton @xzyfer @am11 @mgreter

@jlfranklin
Copy link

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
Copy link

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

@Bob131
Copy link

Bob131 commented Apr 26, 2022

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

@eli-schwartz
Copy link

eli-schwartz commented Apr 29, 2022

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.

@bitc
Copy link
Contributor Author

bitc commented Apr 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants