def setup_clangfmt(env): cmd = "clang-format.exe" if sys.platform == "win32" else "clang-format" try: version = check_output([cmd, "--version"], env=env, universal_newlines=True).rstrip() print(version) if not version.startswith("clang-format version {}.".format(CLANGFMT_VERSION)): print("clang-format: wrong version (v{} required). Skipping CPP formatting.".format(CLANGFMT_VERSION)) return False, None, None except OSError: print("clang-format not installed. Skipping CPP formatting.") return False, None, None gitcmd = ['git', 'ls-files'] gitfiles = check_output(gitcmd + CLANGFMT_CPP_DIRS, universal_newlines=True).splitlines() filtered = [line for line in gitfiles if line.endswith(".h") or line.endswith(".cpp")] return True, cmd, filtered
def doc(self, params): env = os.environ.copy() env["RUSTUP_TOOLCHAIN"] = self.toolchain() rustc_path = check_output(["rustup" + BIN_SUFFIX, "which", "rustc"], env=env) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") self.ensure_bootstrapped() docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) return self.call_rustup_run( ["cargo", "doc", "--manifest-path", self.servo_manifest()] + params, env=self.build_env())
def test_tidy(self, all_files, no_progress, self_test, stylo, force_cpp=False, no_wpt=False): if self_test: return test_tidy.do_tests() else: if no_wpt: manifest_dirty = False else: manifest_dirty = run_update(self.context.topdir, check_clean=True) tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo, no_wpt=no_wpt) self.install_rustfmt() rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"]) env = self.build_env() clangfmt_failed = False available, cmd, files = setup_clangfmt(env) if available: for file in files: stdout = check_output([cmd, "-output-replacements-xml", file], env=env) if len(XML(stdout)) > 0: print("%s is not formatted correctly." % file) clangfmt_failed = True elif force_cpp: print("Error: can't find suitable clang-format version. Required with --force-cpp.") return True if rustfmt_failed or clangfmt_failed: print("Run `./mach fmt` to fix the formatting") return tidy_failed or manifest_dirty or rustfmt_failed or clangfmt_failed
def doc(self, params): env = os.environ.copy() env["RUSTUP_TOOLCHAIN"] = self.toolchain() rustc_path = check_output(["rustup" + BIN_SUFFIX, "which", "rustc"], env=env) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") self.ensure_bootstrapped() docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) return self.call_rustup_run( ["cargo", "doc", "--manifest-path", self.ports_servo_manifest()] + params, env=self.build_env() )
def doc(self, params, features, target=None, android=False, magicleap=False, media_stack=None, **kwargs): self.ensure_bootstrapped(rustup_components=["rust-docs"]) rustc_path = check_output([ "rustup" + BIN_SUFFIX, "which", "--toolchain", self.rust_toolchain(), "rustc" ]) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) features = features or [] target, android = self.pick_target_triple(target, android, magicleap) features += self.pick_media_stack(media_stack, target) env = self.build_env(target=target, is_build=True, features=features) returncode = self.run_cargo_build_like_command("doc", params, features=features, env=env, **kwargs) if returncode: return returncode static = path.join(self.context.topdir, "etc", "doc.servo.org") for name in os.listdir(static): copy2(path.join(static, name), path.join(docs, name))
def doc(self, params): env = os.environ.copy() env["RUSTUP_TOOLCHAIN"] = self.toolchain() rustc_path = check_output(["rustup" + BIN_SUFFIX, "which", "rustc"], env=env) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") self.ensure_bootstrapped() docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) params += ["--features", "azure_backend"] returncode = self.call_rustup_run( ["cargo", "doc", "--manifest-path", self.ports_glutin_manifest()] + params, env=self.build_env()) if returncode: return returncode static = path.join(self.context.topdir, "etc", "doc.servo.org") for name in os.listdir(static): copy2(path.join(static, name), path.join(docs, name)) build = path.join(self.context.topdir, "components", "style", "properties", "build.py") subprocess.check_call([sys.executable, build, "servo", "html"]) script = path.join(self.context.topdir, "components", "script") subprocess.check_call(["cmake", "."], cwd=script) subprocess.check_call( ["cmake", "--build", ".", "--target", "supported-apis"], cwd=script) copy2(path.join(script, "apis.html"), path.join(docs, "servo", "apis.html"))
def doc(self, params): env = os.environ.copy() env["RUSTUP_TOOLCHAIN"] = self.toolchain() rustc_path = check_output(["rustup" + BIN_SUFFIX, "which", "rustc"], env=env) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") self.ensure_bootstrapped() docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) returncode = self.call_rustup_run( ["cargo", "doc", "--manifest-path", self.ports_servo_manifest()] + params, env=self.build_env()) if returncode: return returncode static = path.join(self.context.topdir, "etc", "doc.servo.org") for name in os.listdir(static): copy2(path.join(static, name), path.join(docs, name)) build = path.join(self.context.topdir, "components", "style", "properties", "build.py") subprocess.check_call([sys.executable, build, "servo", "html"]) script = path.join(self.context.topdir, "components", "script") subprocess.check_call(["cmake", "."], cwd=script) subprocess.check_call(["cmake", "--build", ".", "--target", "supported-apis"], cwd=script) copy2(path.join(script, "apis.html"), path.join(docs, "servo", "apis.html"))
def doc(self, params, features, **kwargs): env = os.environ.copy() env["RUSTUP_TOOLCHAIN"] = self.toolchain() rustc_path = check_output(["rustup" + BIN_SUFFIX, "which", "rustc"], env=env) assert path.basename(path.dirname(rustc_path)) == "bin" toolchain_path = path.dirname(path.dirname(rustc_path)) rust_docs = path.join(toolchain_path, "share", "doc", "rust", "html") self.ensure_bootstrapped() docs = path.join(self.get_target_dir(), "doc") if not path.exists(docs): os.makedirs(docs) if read_file(path.join(docs, "version_info.html"), if_exists=True) != \ read_file(path.join(rust_docs, "version_info.html")): print("Copying Rust documentation.") # copytree doesn't like the destination already existing. for name in os.listdir(rust_docs): if not name.startswith('.'): full_name = path.join(rust_docs, name) destination = path.join(docs, name) if path.isdir(full_name): if path.exists(destination): rmtree(destination) copytree(full_name, destination) else: copy2(full_name, destination) features = features or [] returncode = self.run_cargo_build_like_command("doc", params, features=features, **kwargs) if returncode: return returncode static = path.join(self.context.topdir, "etc", "doc.servo.org") for name in os.listdir(static): copy2(path.join(static, name), path.join(docs, name))