servo/components/script/makefile.cargo
Alex Crichton e8eebc1111 Fix spurious rebuilds of the script crate
The script crate currently has a build script, and Cargo will consider all files
in the script crate as inputs to the build script as it otherwise doesn't know
[what the input files are][cargo-1162]. This means that if any file in the
source tree of the script crate changes (or is created) then Cargo will think it
needs to re-run the build script and rebuild the crate.

[cargo-1162]: https://github.com/rust-lang/cargo/issues/1162

The build script of the script crate is invoking python, and consequently Python
is generating some bytecode files in the source tree. On the second build of
Servo, Cargo will see these new files, think that something has changed, and
will re-run the build script of the script crate.

This change passes the `-B` flag to python to avoid generating these bytecode
files, which should avoid tampering with the source tree and appease Cargo by
ensuring that it doesn't get rebuilt.

---

As a helpful tip to if this comes up again, this was discovered by using the
changes in rust-lang/cargo@c447e9d plus the change in rust-lang/cargo#2044. Once
`RUST_LOG` was set to `cargo::ops::cargo_rustc::fingerprint=info`, the second
run of `./mach build` printed out:

```
precalculated components have changed:
  1444364448.000000000s (/build/servo/components/script/dom/bindings/codegen/parser/WebIDL.pyc) !=
  1444364235.000000000s (/build/servo/components/script/document_loader.rs)
```

Which should help easily diagnose these kinds of problems in the future!
2015-10-08 21:37:56 -07:00

49 lines
1.7 KiB
Text

# Recursive wildcard function
# http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
$(filter $(subst *,%,$2),$d))
PYTHON = $(shell which python2.7 2>/dev/null || echo python) -B
BINDINGS_SRC = $(shell pwd)/dom/bindings/codegen
WEBIDLS_SRC = $(shell pwd)/dom/webidls
WEBIDLS = $(call rwildcard,$(WEBIDLS_SRC),*.webidl)
BINDINGS = $(patsubst %.webidl,%Binding.rs,$(WEBIDLS))
AUTOGEN_SRC = $(foreach var,$(BINDINGS),$(subst $(WEBIDLS_SRC),$(OUT_DIR)/Bindings,$(var)))
export PYTHONPATH := $(BINDINGS_SRC)/parser:$(BINDINGS_SRC)/ply:$(PYTHONPATH)
CACHE_DIR = $(OUT_DIR)/_cache
bindinggen_dependencies := $(addprefix $(BINDINGS_SRC)/,BindingGen.py Bindings.conf Configuration.py CodegenRust.py parser/WebIDL.py) $(OUT_DIR)/ParserResults.pkl $(OUT_DIR)/Bindings/.done
globalgen_dependencies := $(addprefix $(BINDINGS_SRC)/,GlobalGen.py Bindings.conf Configuration.py CodegenRust.py parser/WebIDL.py) $(CACHE_DIR)/.done $(OUT_DIR)/Bindings/.done
.PHONY: all
all: $(AUTOGEN_SRC)
$(OUT_DIR)/Bindings/.done:
mkdir -p $(OUT_DIR)/Bindings
touch $@
$(CACHE_DIR)/.done:
mkdir -p $(CACHE_DIR)
touch $@
$(OUT_DIR)/ParserResults.pkl: $(globalgen_dependencies) $(WEBIDLS)
$(PYTHON) \
$(BINDINGS_SRC)/GlobalGen.py \
--cachedir=$(CACHE_DIR) \
$(BINDINGS_SRC)/Bindings.conf \
$(OUT_DIR) \
. \
$(WEBIDLS)
$(AUTOGEN_SRC): $(OUT_DIR)/Bindings/%Binding.rs: $(bindinggen_dependencies) \
$(addprefix $(WEBIDLS_SRC)/,%.webidl)
$(PYTHON) \
$(BINDINGS_SRC)/BindingGen.py \
$(BINDINGS_SRC)/Bindings.conf \
$(OUT_DIR) \
$(OUT_DIR)/Bindings/$*Binding \
$(addprefix $(WEBIDLS_SRC)/,$*.webidl)
touch $@