parent
a7ebe54eb1
commit
9abff2b95f
3 changed files with 381 additions and 0 deletions
@ -0,0 +1,193 @@ |
||||
|
||||
package( |
||||
default_visibility = ["//visibility:public"], |
||||
) |
||||
|
||||
cc_binary( |
||||
name = "ragel", |
||||
srcs = [ |
||||
"ragel/rubycodegen.cpp", |
||||
"ragel/goipgoto.h", |
||||
"ragel/cdtable.h", |
||||
"ragel/rubycodegen.h", |
||||
"ragel/gotable.h", |
||||
"ragel/gocodegen.cpp", |
||||
"ragel/rubyfflat.cpp", |
||||
"ragel/common.cpp", |
||||
"ragel/gofflat.cpp", |
||||
"ragel/cdtable.cpp", |
||||
"ragel/cdsplit.cpp", |
||||
"ragel/rlparse.cpp", |
||||
"ragel/csfgoto.cpp", |
||||
"ragel/javacodegen.cpp", |
||||
"ragel/gocodegen.h", |
||||
"ragel/mlgoto.cpp", |
||||
"ragel/fsmgraph.cpp", |
||||
"ragel/version.h", |
||||
"ragel/mlfflat.h", |
||||
"ragel/fsmgraph.h", |
||||
"ragel/fsmbase.cpp", |
||||
"ragel/fsmstate.cpp", |
||||
"ragel/gotablish.cpp", |
||||
"ragel/rubyflat.cpp", |
||||
"ragel/cdfgoto.h", |
||||
"ragel/cscodegen.h", |
||||
"ragel/mlflat.cpp", |
||||
"ragel/rubyflat.h", |
||||
"ragel/goftable.h", |
||||
"ragel/rbxgoto.cpp", |
||||
"ragel/csfflat.cpp", |
||||
"ragel/gofgoto.cpp", |
||||
"ragel/gofgoto.h", |
||||
"ragel/ragel.h", |
||||
"ragel/goftable.cpp", |
||||
"ragel/cdcodegen.cpp", |
||||
"ragel/rlparse.h", |
||||
"ragel/cdsplit.h", |
||||
"ragel/xmlcodegen.cpp", |
||||
"ragel/goipgoto.cpp", |
||||
"ragel/dotcodegen.h", |
||||
"ragel/gogoto.cpp", |
||||
"ragel/csflat.h", |
||||
"ragel/csfflat.h", |
||||
#"ragel/config.h.in", |
||||
"ragel/csipgoto.cpp", |
||||
"ragel/mltable.cpp", |
||||
"ragel/mlflat.h", |
||||
"ragel/csftable.cpp", |
||||
"ragel/cdgoto.h", |
||||
"ragel/goflat.cpp", |
||||
"ragel/rubyfflat.h", |
||||
"ragel/mlftable.h", |
||||
"ragel/rubyftable.h", |
||||
"ragel/fsmap.cpp", |
||||
"ragel/redfsm.cpp", |
||||
"ragel/goflat.h", |
||||
"ragel/parsetree.cpp", |
||||
"ragel/fsmmin.cpp", |
||||
"ragel/dotcodegen.cpp", |
||||
"ragel/redfsm.h", |
||||
"ragel/mlcodegen.cpp", |
||||
"ragel/cdfgoto.cpp", |
||||
"ragel/cssplit.cpp", |
||||
"ragel/cstable.cpp", |
||||
"ragel/javacodegen.h", |
||||
"ragel/parsedata.cpp", |
||||
"ragel/buffer.h", |
||||
"ragel/gogoto.h", |
||||
"ragel/csgoto.h", |
||||
"ragel/pcheck.h", |
||||
"ragel/rubyftable.cpp", |
||||
"ragel/csfgoto.h", |
||||
"ragel/common.h", |
||||
"ragel/cdftable.h", |
||||
"ragel/mlgoto.h", |
||||
"ragel/csgoto.cpp", |
||||
"ragel/cdflat.h", |
||||
"ragel/cdipgoto.h", |
||||
"ragel/cstable.h", |
||||
"ragel/gendata.h", |
||||
"ragel/cdfflat.cpp", |
||||
"ragel/gotable.cpp", |
||||
"ragel/cdcodegen.h", |
||||
"ragel/gendata.cpp", |
||||
"ragel/rubytable.h", |
||||
"ragel/csflat.cpp", |
||||
"ragel/inputdata.h", |
||||
"ragel/inputdata.cpp", |
||||
"ragel/rubytable.cpp", |
||||
"ragel/fsmattach.cpp", |
||||
"ragel/csipgoto.h", |
||||
"ragel/cscodegen.cpp", |
||||
"ragel/cdfflat.h", |
||||
"ragel/rbxgoto.h", |
||||
"ragel/xmlcodegen.h", |
||||
"ragel/gofflat.h", |
||||
"ragel/parsedata.h", |
||||
"ragel/mlfgoto.h", |
||||
"ragel/cdflat.cpp", |
||||
"ragel/config.h", |
||||
"ragel/rlscan.cpp", |
||||
"ragel/mlcodegen.h", |
||||
"ragel/mlfflat.cpp", |
||||
"ragel/mlftable.cpp", |
||||
"ragel/mltable.h", |
||||
"ragel/cdipgoto.cpp", |
||||
"ragel/cdftable.cpp", |
||||
"ragel/parsetree.h", |
||||
"ragel/rlscan.h", |
||||
"ragel/main.cpp", |
||||
"ragel/cssplit.h", |
||||
"ragel/mlfgoto.cpp", |
||||
"ragel/csftable.h", |
||||
"ragel/gotablish.h", |
||||
"ragel/cdgoto.cpp", |
||||
"aapl/avlmelkey.h", |
||||
"aapl/dlistmel.h", |
||||
"aapl/avliset.h", |
||||
"aapl/avlkeyless.h", |
||||
"aapl/sbstset.h", |
||||
"aapl/sbsttable.h", |
||||
"aapl/quicksort.h", |
||||
"aapl/avlitree.h", |
||||
"aapl/avlcommon.h", |
||||
"aapl/bstset.h", |
||||
"aapl/avlmel.h", |
||||
"aapl/insertsort.h", |
||||
"aapl/dlist.h", |
||||
"aapl/avlmap.h", |
||||
"aapl/mergesort.h", |
||||
"aapl/resize.h", |
||||
"aapl/bstcommon.h", |
||||
"aapl/bstmap.h", |
||||
"aapl/compare.h", |
||||
"aapl/svector.h", |
||||
"aapl/avlset.h", |
||||
"aapl/bsttable.h", |
||||
"aapl/avlikeyless.h", |
||||
"aapl/bubblesort.h", |
||||
"aapl/table.h", |
||||
"aapl/avlbasic.h", |
||||
"aapl/vector.h", |
||||
"aapl/avlimap.h", |
||||
"aapl/dlistval.h", |
||||
"aapl/dlcommon.h", |
||||
"aapl/avlibasic.h", |
||||
"aapl/sbstmap.h", |
||||
"aapl/avlimel.h", |
||||
"aapl/avlimelkey.h", |
||||
"aapl/avltree.h", |
||||
], |
||||
includes = ["ragel", "aapl"], |
||||
) |
||||
|
||||
config_h_contents = """ |
||||
#define PACKAGE "ragel" |
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */ |
||||
#define PACKAGE_BUGREPORT "" |
||||
|
||||
/* Define to the full name of this package. */ |
||||
#define PACKAGE_NAME "ragel" |
||||
|
||||
/* Define to the full name and version of this package. */ |
||||
#define PACKAGE_STRING "ragel 6.10" |
||||
|
||||
/* Define to the one symbol short name of this package. */ |
||||
#define PACKAGE_TARNAME "ragel" |
||||
|
||||
/* Define to the home page for this package. */ |
||||
#define PACKAGE_URL "" |
||||
|
||||
/* Define to the version of this package. */ |
||||
#define PACKAGE_VERSION "6.10" |
||||
|
||||
/* Version number of package */ |
||||
#define VERSION "6.10" |
||||
""" |
||||
|
||||
genrule( |
||||
name = "gen_config_h", |
||||
outs = ["ragel/config.h"], |
||||
cmd = "(cat <<'HEREDOC'\n%s\nHEREDOC\n) > $@" % config_h_contents, |
||||
) |
@ -0,0 +1,30 @@ |
||||
"""The py_test() script for generated_file_staleness_test() rules. |
||||
|
||||
Note that this file is preprocessed! The INSERT_<...> text below is replaced |
||||
with the actual list of files before we actually run the script. |
||||
""" |
||||
|
||||
from __future__ import absolute_import |
||||
|
||||
import staleness_test_lib |
||||
import unittest |
||||
import sys |
||||
|
||||
file_list = """ |
||||
INSERT_FILE_LIST_HERE |
||||
""".split() |
||||
|
||||
config = staleness_test_lib.Config(file_list) |
||||
|
||||
|
||||
class TestFilesMatch(unittest.TestCase): |
||||
|
||||
def testFilesMatch(self): |
||||
errors = staleness_test_lib.CheckFilesMatch(config) |
||||
self.assertFalse(errors, errors) |
||||
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--fix": |
||||
staleness_test_lib.FixFiles(config) |
||||
else: |
||||
unittest.main() |
@ -0,0 +1,158 @@ |
||||
"""Shared code for validating generated_file_staleness_test() rules. |
||||
|
||||
This code is used by test scripts generated from |
||||
generated_file_staleness_test() rules. |
||||
""" |
||||
|
||||
from __future__ import absolute_import |
||||
from __future__ import print_function |
||||
|
||||
import os |
||||
from shutil import copyfile |
||||
|
||||
|
||||
class _FilePair(object): |
||||
"""Represents a single (target, generated) file pair.""" |
||||
|
||||
def __init__(self, target, generated): |
||||
self.target = target |
||||
self.generated = generated |
||||
|
||||
|
||||
class Config(object): |
||||
"""Represents the configuration for a single staleness test target.""" |
||||
|
||||
def __init__(self, file_list): |
||||
# Duplicate to avoid modifying our arguments. |
||||
file_list = list(file_list) |
||||
|
||||
# The file list contains a few other bits of information at the end. |
||||
# This is packed by the code in build_defs.bzl. |
||||
self.target_name = file_list.pop() |
||||
self.package_name = file_list.pop() |
||||
self.pattern = file_list.pop() |
||||
|
||||
self.file_list = file_list |
||||
|
||||
|
||||
def _GetFilePairs(config): |
||||
"""Generates the list of file pairs. |
||||
|
||||
Args: |
||||
config: a Config object representing this target's config. |
||||
|
||||
Returns: |
||||
A list of _FilePair objects. |
||||
""" |
||||
|
||||
ret = [] |
||||
|
||||
has_bazel_genfiles = os.path.exists("bazel-genfiles") |
||||
|
||||
for filename in config.file_list: |
||||
target = os.path.join(config.package_name, filename) |
||||
generated = os.path.join(config.package_name, config.pattern % filename) |
||||
if has_bazel_genfiles: |
||||
generated = os.path.join("bazel-genfiles", generated) |
||||
|
||||
# Generated files should always exist. Blaze should guarantee this before |
||||
# we are run. |
||||
if not os.path.isfile(generated): |
||||
print("Generated file '%s' does not exist." % generated) |
||||
print("Please run this command to generate it:") |
||||
print(" bazel build %s:%s" % (config.package_name, config.target_name)) |
||||
ret.append(_FilePair(target, generated)) |
||||
|
||||
return ret |
||||
|
||||
|
||||
def _GetMissingAndStaleFiles(file_pairs): |
||||
"""Generates lists of missing and stale files. |
||||
|
||||
Args: |
||||
file_pairs: a list of _FilePair objects. |
||||
|
||||
Returns: |
||||
missing_files: a list of _FilePair objects representing missing files. |
||||
These target files do not exist at all. |
||||
stale_files: a list of _FilePair objects representing stale files. |
||||
These target files exist but have stale contents. |
||||
""" |
||||
|
||||
missing_files = [] |
||||
stale_files = [] |
||||
|
||||
for pair in file_pairs: |
||||
if not os.path.isfile(pair.target): |
||||
missing_files.append(pair) |
||||
continue |
||||
|
||||
generated = open(pair.generated).read() |
||||
target = open(pair.target).read() |
||||
if generated != target: |
||||
stale_files.append(pair) |
||||
|
||||
return missing_files, stale_files |
||||
|
||||
|
||||
def _CopyFiles(file_pairs): |
||||
"""Copies all generated files to the corresponding target file. |
||||
|
||||
The target files must be writable already. |
||||
|
||||
Args: |
||||
file_pairs: a list of _FilePair objects that we want to copy. |
||||
""" |
||||
|
||||
for pair in file_pairs: |
||||
target_dir = os.path.dirname(pair.target) |
||||
if not os.path.isdir(target_dir): |
||||
os.makedirs(target_dir) |
||||
copyfile(pair.generated, pair.target) |
||||
|
||||
|
||||
def FixFiles(config): |
||||
"""Implements the --fix option: overwrites missing or out-of-date files. |
||||
|
||||
Args: |
||||
config: the Config object for this test. |
||||
""" |
||||
|
||||
file_pairs = _GetFilePairs(config) |
||||
missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs) |
||||
|
||||
_CopyFiles(stale_files + missing_files) |
||||
|
||||
|
||||
def CheckFilesMatch(config): |
||||
"""Checks whether each target file matches the corresponding generated file. |
||||
|
||||
Args: |
||||
config: the Config object for this test. |
||||
|
||||
Returns: |
||||
None if everything matches, otherwise a string error message. |
||||
""" |
||||
|
||||
diff_errors = [] |
||||
|
||||
file_pairs = _GetFilePairs(config) |
||||
missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs) |
||||
|
||||
for pair in missing_files: |
||||
diff_errors.append("File %s does not exist" % pair.target) |
||||
continue |
||||
|
||||
for pair in stale_files: |
||||
diff_errors.append("File %s is out of date" % pair.target) |
||||
|
||||
if diff_errors: |
||||
error_msg = "Files out of date!\n\n" |
||||
error_msg += "To fix run THIS command:\n" |
||||
error_msg += " bazel-bin/%s/%s --fix\n\n" % (config.package_name, |
||||
config.target_name) |
||||
error_msg += "Errors:\n" |
||||
error_msg += " " + "\n ".join(diff_errors) |
||||
return error_msg |
||||
else: |
||||
return None |
Loading…
Reference in new issue