Skip to content

Migrate examples to snippets #1069

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions Examples/Package.swift

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ text editor, or IDE.
- [SwiftParser](Sources/SwiftParser/SwiftParser.docc)
- [SwiftOperators](Sources/SwiftOperators/SwiftOperators.docc)

Examples of how to use SwiftSyntax can be found in [Snippets](Snippets).

## Contributing

Start contributing to SwiftSyntax see [this guide](CONTRIBUTING.md) for more information.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Examples/README.md → Snippets/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Examples
# Snippets (Examples)

Each example can be executed by navigating into this folder and running `swift run <example> <arguments>`. There is the following set of examples available:

Expand Down
21 changes: 8 additions & 13 deletions build-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

PACKAGE_DIR = os.path.dirname(os.path.realpath(__file__))
WORKSPACE_DIR = os.path.dirname(PACKAGE_DIR)
EXAMPLES_DIR = os.path.join(PACKAGE_DIR, "Examples")
SOURCES_DIR = os.path.join(PACKAGE_DIR, "Sources")
IDEUTILS_DIR = os.path.join(SOURCES_DIR, "IDEUtils")
SWIFTSYNTAX_DIR = os.path.join(SOURCES_DIR, "SwiftSyntax")
Expand Down Expand Up @@ -460,14 +459,10 @@ def __get_swiftpm_invocation(self, package_dir: str) -> List[str]:
invocation.append("--verbose")
return invocation

def buildProduct(self, product_name: str) -> None:
def build_product(self, product_name: str) -> None:
print("** Building product " + product_name + " **")
self.__build(PACKAGE_DIR, product_name)

def buildExample(self, example_name: str) -> None:
print("** Building example " + example_name + " **")
self.__build(EXAMPLES_DIR, example_name)

def __build(self, package_dir: str, product_name: str) -> None:
command = list(self.__get_swiftpm_invocation(package_dir))
command.extend(["--product", product_name])
Expand Down Expand Up @@ -759,13 +754,13 @@ def build_command(args: argparse.Namespace) -> None:
)
# Until rdar://53881101 is implemented, we cannot request a build of multiple
# targets simultaneously. For now, just build one product after the other.
builder.buildProduct("SwiftSyntax")
builder.buildProduct("SwiftSyntaxParser")
builder.buildProduct("SwiftSyntaxBuilder")
builder.build_product("SwiftSyntax")
builder.build_product("SwiftSyntaxParser")
builder.build_product("SwiftSyntaxBuilder")

# Build examples
builder.buildExample("AddOneToIntegerLiterals")
builder.buildExample("CodeGenerationUsingSwiftSyntaxBuilder")
builder.build_product("AddOneToIntegerLiterals")
builder.build_product("CodeGenerationUsingSwiftSyntaxBuilder")
except subprocess.CalledProcessError as e:
fail_for_called_process_error("Building SwiftSyntax failed", e)

Expand All @@ -781,7 +776,7 @@ def test_command(args: argparse.Namespace) -> None:
disable_sandbox=args.disable_sandbox,
)

builder.buildProduct("lit-test-helper")
builder.build_product("lit-test-helper")

run_tests(
toolchain=args.toolchain,
Expand Down Expand Up @@ -892,7 +887,7 @@ def add_generate_source_code_args(parser: argparse.ArgumentParser) -> None:
# -------------------------------------------------------------------------
# Shared arguments

sub_parsers = parser.add_subparsers()
sub_parsers = parser.add_subparsers(required=True)

# -------------------------------------------------------------------------
generate_xcodeproj_parser = sub_parsers.add_parser(
Expand Down