Commit Graph

240 Commits

Author SHA1 Message Date
Giacomo Vercesi 152a624f47 revng.model: drop last version autodetection
revng.model.__init__ would dynamically import the latest version of
the model when imported, however this would break IDE hints as the
classes would not be properly detected. Instead we now manually
specify the last version in the __init__.py file.
2022-07-22 15:07:14 +02:00
Giacomo Vercesi 4486167d92 revng.model: add TypedList
Add a specialized list class to be used in the model. This will do
runtime instance checking to make sure that list-like fields in the
model only contain object of the correct type.
2022-07-22 14:56:15 +02:00
Giacomo Vercesi 93e1b1a9e8 revng.model: use safe version of yaml.Loader 2022-07-22 14:56:15 +02:00
Giacomo Vercesi 116d965117 revng.model: implement kw_only
Implement a constructor override for model classes that checks that the
constructor does not have positional arguments passed to it. This can
be dropped post-3.10 since it is implemented natively by kw_only.
2022-07-22 14:56:15 +02:00
Giacomo Vercesi 2329201ba1 revng.model: import contents of MetaAddress
This allows to have all the classes needed for model manipulation to
be available with `from revng.model import *`.
2022-07-22 14:56:15 +02:00
Giacomo Vercesi 018518d783 revng.model: remove tags from dumper
Tags in the yaml have been deprecated for a while, remove them from
being outputted from YAML dumper.
2022-07-22 14:56:15 +02:00
Alessandro Di Federico f84b87e63e Minor changes 2022-07-21 19:01:37 +02:00
Davide Depau d02237ea5e python: import CIterable from collections.abc
Importing from `collection` has been deprecated for a while now.
2022-07-05 10:31:36 +02:00
Giacomo Vercesi 80afd71721 Add singleTargetFilename to pipelines
A step's artifacts now include singleTargetFilename, which gives a
suggested filename to use when a single element is extracted from the
underlying container.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi f02aecfccb Python API: produce now returns a dict
When requesting a produce for multiple targets the result will be a
dictionary mapping "<target>:<result>". This also changes the GraphQL
API where a json-serialized string is returned.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 30ef77e6fa GraphQL: introduce queries to retrieve globals
Change the schema to allow introspection of context globals.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 636299785d GraphQL: introduce artifacts introspection
Allow artifacts information (container and kind) to be retrieved from
the Step type.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 62e9baeddb GraphQL: rework schema to be camelCase
GraphQL conventions, encourage the use of camelCase for query fields
and PascalCase for types, as detailed here:

    https://graphql-rules.com/rules/naming-fields-args
2022-06-29 14:50:58 +02:00
Giacomo Vercesi df72bb68b0 GraphQL: introduce CORS headers
Add CORS headers to the graphql api. These are set via the REVNG_ORIGINS
environment variable.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 59b01a9f1b revng.daemon: asyncify all PipelineC calls
In typical scenarios most PipelineC calls block for too long, this is
debilitating to the GraphQL API since coroutines are run
cooperatively. This commit moves all PipelineC calls in a separate
thread.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 2df691535d Pipeline: Make recalculateAllPossibleTargets
`recalculateAllPossibleTarget` is now a private member of
PipelineManager This was done since all calls that can trigger a change
in the target list have been isolated and the call is done implicitly.
This removes rp_manager_recompute_all_available_targets from PipelineC,
since it was added as a stopgap until the above was implemented.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 487af0f4b0 Do not pass file paths to revng from PipelineC
Allow deserializing containers from a byte string rather than pointing
to a file, this allows revng to have an opaque workdir.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 2fc11ab055 revng daemon: introduce notifications
Add the possibility of passing a list of FIFOs to `revng daemon`. These
can be used to notify an external program when a non-reproducible change
(binary, context) has occurred.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 93f776217d Split revng.daemon.schema
Splits the module in 2:

* static_handlers: as the name suggests this is where handlers for
  static endpoints (e.g. not dependent on the pipeline) are implemented
* schema_generator: this is where the schema is generated from a
  manager's pipeline definition, together with the handler for the
  autogenerated endpoint
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 05dc27715d Improve pipeline saving capabilities
This commit introduces some changes to how the revng pipeline handles
serializing to disk. Specificaly:

* Pipeline globals (specifically model.yml) are better handled if they
  are in a subdirectory. They are now saved in the "context"
  subdirectory.
* In python:revng.api the pipeline is serialized whenever there is a
  non-reproducible change to the state (e.g. binary upload or model
  change).
  In the case of analyses this is done conservatively by checking that
  the diff produced is not empty.
* The logic for computing a step's subdirectory has been moved to the
  pipeline runner, consequently if a step is asked to serialize it
  will not create any subdirectories.
* Functionality for saving a single step/context has been exposed in
  Pipeline C.
* Finally, all path concatenations are now handled by
  llvm::sys::path::append, for extra os-agnosticism.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi a03547ae66 revng.api: drop wrong exception in get_target
If a step:container does not have any targets, return an empty list
instead of raising an exception.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 6c2d176827 python.api: introduce lock in destructors
Due to the possibly multi-threaded nature of the python C API, use
the C API lock also when invoking destructors.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi ffab18ee48 revng daemon: identify valid port
This commit resolves a non-deterministic test failure in `revng daemon`.

When running daemon tests, `randint` was used for selecting the listen
port, this caused test failures when the same port number was used for
reused. This has been replaced with the use of port 0 that guarantees
the use of an unused port and psutil to find the port number once it has
been bound by the daemon process.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi dd08f2bf96 revng daemon --help: add description
Add an extended description to the command `revng daemon` which
details the the environment variables at play when running it.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 79c6086d0d revng.api: autodetect files
`revng.api` now autodetects files (libraries, pipeline yamls) for
initialization via the same mechanism used by `revng.cli`. This removes
the need to pass them via environment variables from `revng daemon`
and allows easy interaction with python's C API.
2022-06-29 14:49:29 +02:00
Giacomo Vercesi a741e39f76 revng-check-conventions: introduce prettier
Adds the formatting tool prettier to allow formatting JS, TS, JSON,
YAML and HTML files.
2022-06-28 15:29:09 +02:00
Alessandro Di Federico f4684e244d Switch to new testsuite 2022-06-20 19:04:18 +02:00
Giacomo Vercesi 1cc8c2c20c Fix pyYAML type error
Remove code in revng.cli.model_dump and override_by_name that was used
when the model had tags. The code subclassed the default pyYAML loader
to ignore unknown tags to allow reading the model data easily. Since the
model no longer has tags this code is dead and can be removed.
2022-06-13 18:35:37 +02:00
Alessandro Di Federico d37c3d3dd8 Fix revng --prefix
When running subcommands from a `revng` script the build directory and
the root directory were being swapped.
2022-05-31 11:30:10 +02:00
Giacomo Vercesi 2f0519c3c5 GraphQL: Introduce run_all_analyses 2022-05-24 10:56:04 +02:00
Giacomo Vercesi e5704ede11 Make Python API thread-safe and non-blocking
Since PipelineC is not thread-safe, add a lock to all function calls to
it to avoid any thread safety-related issues.

At the same time, use a thread pool to run "expensive" PipelineC
functions in GraphQL (specifically `produce_target` and `run_analysis`)
to avoid problems due to the cooperative nature of Python coroutines.
2022-05-24 10:56:04 +02:00
Giacomo Vercesi 7052f2a8a0 Support analyses and globals in Python
This commit adds the newly implemented functionality in PipelineC both
in revng.api and the graphql api, allowing:

* retrieval of global variable names
* unwrapping of a single target
* execution of analyses
2022-05-24 10:56:02 +02:00
Giacomo Vercesi 7c3d9a3fcd Python API: automatically call destructors
Use the owning annotation in PipelineC/Prototypes.h to automatically
destroy resources when they go out of scope on the python side.
2022-05-24 08:59:08 +02:00
Massimo Fioravanti f0a5ffe3b3 revng-pipeline: globals, extractOne and analyses 2022-05-24 08:58:48 +02:00
Giacomo Vercesi 07c23dda8d revng-deamon: fix GraphQL URL
The page was using the wrong attribute to make the GraphQL calls
relative to the debug page's url.
2022-05-24 08:49:16 +02:00
Alessandro Di Federico 5b39595b77 Minor changes 2022-05-13 15:14:51 +02:00
Alessandro Di Federico 41c21ddb07 revng-daemon: use ASan 2022-05-12 21:55:18 +02:00
Alessandro Di Federico ccba62b13d revng opt: do not add --help 2022-05-12 21:54:42 +02:00
Alessandro Di Federico 450b0b4013 Minor changes 2022-05-11 09:29:45 +02:00
Ivan Krysak 8a07e67767 Add revng yield assembly tool 2022-05-06 18:51:47 +02:00
Giacomo Vercesi 09d9950aac daemon: fix debug page in subpaths 2022-05-06 15:04:19 +02:00
Giacomo Vercesi d13e802c4f daemon: Disable debug page in production mode 2022-05-06 15:04:19 +02:00
Giacomo Vercesi 3bdf8468b1 Add extra command line options to 'revng daemon'
--production runs the server on all interfaces and with debug options
disabled
--hypercorn-args allows to pass extra options to hypercorn when running
revng daemon
2022-05-06 15:04:19 +02:00
Giacomo Vercesi 70f7337f28 Substitute Flask with Starlette
In the future we will need to use GraphQL subscriptions. This is done
via websockets and is supported in Ariadne. However this support is
limited to ASGI frameworks, which Flask isn't a part of.
Startlette is a direct depencency of Ariadne, and all of Ariadne's
features are fully integrated with Starlette, so the switch allows to
drop some Flask integration cruft and streamline the revng.daemon
package.
Starlette does not have a built-in development server, instead
Hypercorn, which is an ASGI-compliant HTTP server, is used in place of
Flask's Werkzeug/Gunicorn for both the development and production
server roles.
2022-05-06 15:04:19 +02:00
Giacomo Vercesi 2a89da8d53 revng daemon: properly shut down after tests
Fix termination of the daemon process during test, previously it was the
daemon instances were not cleaned up properly and remained running after
the tests
2022-05-06 15:03:51 +02:00
Giacomo Vercesi f02976faee revng --help: do not display absolute paths 2022-05-06 15:03:35 +02:00
Alessandro Di Federico 1370763bc4 llvm pipeline: handle - as input 2022-04-29 17:57:49 +02:00
Alessandro Di Federico cafdd7c6f9 Introduce revng model override-by-name 2022-04-29 17:57:49 +02:00
Alessandro Di Federico 9ca3447b5d revng.cli: introduce try_run 2022-04-29 17:57:49 +02:00
Giacomo Vercesi b9794b84bb revng.daemon: introduce tests
Add end-to-end tests checking that every GraphQL endpoint is properly
working and returning the expected result
2022-04-26 15:59:35 +02:00