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

Basic Documentation of Plugin Limitations #3

Closed
wants to merge 8 commits into from
17 changes: 17 additions & 0 deletions limitations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Limitations

This directory contains some files displaying some known limitations of this plugin.

You can open any of the *.d files and observe errors being reported by the plugin. To compile the *.d files without errors, either use build.py, or do it manually with dmd. See the following subsections for details.

## Build (python)
You need `dmd` in your path to use the build script `build.py`. This script can be used to build all samples so you see for yourself that they're valid D programs.

* `build.py` Build all samples without running them. Default output directory is `./_build`.
* `build.py -Run` Build and run all samples in turn.
* `build.py -Clean` Remove build output instead of building.

They have been tested with dmd v2.077.1.

## Build (manually)
Each sample contains the necessary arguments to properly build them in their first line as a comment.
65 changes: 65 additions & 0 deletions limitations/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Builds and optionally runs all limitation samples.
"""

import sys, os, glob, subprocess, shutil, argparse
from glob import glob

IS_WINDOWS = os.name == 'nt'

def main(run, clean, code_dir, build_dir):
"""Main entry point to build and optionally run all samples."""
os.chdir(code_dir)
if clean:
if os.path.exists(build_dir):
print("Removing directory:", build_dir)
shutil.rmtree(build_dir)
else:
print("Nothing to clean")
else:
sources = glob('{}/*.d'.format(code_dir))
for source_path in sources:
with open(source_path) as source_file:
first_line = source_file.readline()

command = first_line.lstrip('/').strip()

if not command.startswith("dmd"):
print("Skipping:", source_path)
continue

# Add the path to the source file.
command += ' "' + source_path + '"'

# Determine the output file name so we can invoke it later.
source_name = os.path.basename(os.path.splitext(source_path)[0])
executable_path = os.path.join(build_dir, source_name)
if IS_WINDOWS:
executable_path += '.exe'

command += ' "-of={}"'.format(executable_path)

print("Compiling:", command)
subprocess.call(command, shell=True)

if run:
print("Running:", os.path.basename(source_path))
subprocess.call(executable_path)
print()

if __name__ == '__main__':
file_dir = os.path.dirname(__file__) #os.path.dirname()
code_dir = file_dir
default_build_dir = os.path.join(file_dir, '_build')

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--run', action='store_true', default=True,
help='run all built examples.')
parser.add_argument('--clean', action='store_true', default=False,
help='instead of building/running, remove the build dir')
parser.add_argument('--build-dir', default=default_build_dir,
help='output directory for build results. ' + \
'Note: working directory during build is: ' + os.path.abspath(code_dir))
args = parser.parse_args()

main(args.run, args.clean, code_dir, args.build_dir)
16 changes: 16 additions & 0 deletions limitations/conditional_import.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// dmd -version=Foo

version(Foo)
{
import std.stdio;
}

void func1() {
/// `writeln` is not defined, perhaps `std.stdio;` is needed?
writeln("func1");
}

void main()
{
func1();
}
8 changes: 8 additions & 0 deletions limitations/mixin_import.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// dmd "-J=."

mixin(import("mixin_import.txt"));

void main()
{
mixin_import_func();
}
6 changes: 6 additions & 0 deletions limitations/mixin_import.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std.stdio;

void mixin_import_func()
{
writeln("Hello from mixin_import_func in mixin_import.txt");
}