119 Commits

Author SHA1 Message Date
Dan Chao
edf704b469 Run spotless apply 2025-01-22 09:04:02 -08:00
Dan Chao
d9cfb68048 Prepare 0.27.2 release 2025-01-22 08:57:27 -08:00
Daniel Chao
1e75001382 Add release notes for 0.27.2 (#894) 2025-01-21 11:56:33 -08:00
Dan Chao
376eb2bdbf Run spotless apply 2025-01-17 10:32:24 -08:00
Daniel Chao
56a3b0a193 Update license year (#871)
* Update license header file spec to use placeholder year
* Update spotless to use ratchet formatting (only format files that have changed)
2025-01-17 10:32:24 -08:00
Josh B
6c8e45b19a Fix NPE when handling ExternalReader specs with null arguments (#882) 2025-01-17 10:32:24 -08:00
Josh B
0bc1b7156e Fix page size for Linux AArch64 native executables (#875)
Graal Native Image is assuming 4k page size here, which is a naughty assumption to make in the modern Linux-on-ARM landscape.
Two very common hardware configurations require 16k minumum page size: the Raspberry Pi 5 and Asahi Linux (running on Apple Silicon hardware).

This change forces 64k pages for Linux/AArch64 native executables to guarantee compatibility with these platforms.
DEVELOPMENT.adoc is also updated to cover the additional dependencies required for building native executables on Linux.
2025-01-17 10:32:24 -08:00
Stefan M.
f0b961de81 Make Test Report locale independent (#868)
Format numbers with `.` decimals
2025-01-17 10:32:24 -08:00
Daniel Chao
3ece353e0c Download JDK for windows build (#851)
Don't use the system Java on Windows builds, instead download them from Adoptium.

Also:

* Fail job if curl returns a 4xx status code
* Add java version to `GradleJob`
2025-01-17 09:58:03 -08:00
Josh B
639cc2430e Fix CreateEvaluatorRequest decoding (#853)
Handle case when request specifies external reader with null arguments
2024-12-19 10:00:46 -08:00
Philip K.F. Hölzenspies
48a710f439 Prepare 0.27.1 release (#839) 2024-12-06 14:23:25 +00:00
Philip K.F. Hölzenspies
15d85b0660 Add release notes for 0.27.1 2024-12-06 13:25:39 +00:00
odenix
aeace8bb3c Improve lazy type checking of listings and mappings (#789)
Motivation:
- simplify implementation of lazy type checking
- fix correctness issues of lazy type checking (#785)

Changes:
- implement listing/mapping type cast via amendment (`parent`) instead of delegation (`delegate`)
- handle type checking of *computed* elements/entries in the same way as type checking of computed properties
  - ElementOrEntryNode is the equivalent of TypeCheckedPropertyNode
- remove fields VmListingOrMapping.delegate/typeNodeFrame/cachedMembers/checkedMembers
- fix #785 by executing all type casts between a member's owner and receiver
- fix #823 by storing owner and receiver directly
  instead of storing the mutable frame containing them (typeNodeFrame)
- remove overrides of VmObject methods that are no longer required
  - good for Truffle partial evaluation and JVM inlining
- revert a85a173faa except for added tests
- move `VmUtils.setOwner` and `VmUtils.setReceiver` and make them private
  - these methods aren't generally safe to use

Result:
- simpler code with greater optimization potential
  - VmListingOrMapping can now have both a type node and new members
- fewer changes to surrounding code
- smaller memory footprint
- better performance in some cases
- fixes https://github.com/apple/pkl/issues/785
- fixes https://github.com/apple/pkl/issues/823

Potential future optimizations:
- avoid lazy type checking overhead for untyped listings/mappings
- improve efficiency of forcing a typed listing/mapping
  - currently, lazy type checking will traverse the parent chain once per member,
    reducing the performance benefit of shallow-forcing
	  a listing/mapping over evaluating each member individually
- avoid creating an intermediate untyped listing/mapping in the following cases:
  - `new Listing<X> {...}`
  - amendment of `property: Listing<X>`
2024-12-06 14:00:23 +01:00
Islon Scherer
7b850dd6d9 Fix possible stack overflow in Listing/Mapping type checking (#826) 2024-12-06 13:58:29 +01:00
Daniel Chao
c2096f633b Exclude non file-based modules from synthesized *GatherImports task (#821)
This fixes an issue where certain modules tasks fail due to the plugin
attempting to analyze their imports, but the arguments may not actually be
Pkl modules.

For example, the pkldoc task accepts entire packages in its "sourceMoules" property.

This changes the gather imports logic to only analyze file-based modules.
This is also a performance improvement; non file-based modules are unlikely to import
files due to insufficient trust levels.

Also: fix a bug when generating pkldoc on Windows
2024-12-06 13:58:06 +01:00
translatenix
d6ba021e12 Fix length of listings with computed index (#797)
Motivation:
The following expression evaluates to 2 instead of 1:
new Listing { "value" } { [0 + 0] = "override" }.length

Changes:
- fix length computation in EntriesLiteralNode
- improve `api/listing` tests
- make snippet test failures diffable in IntelliJ

Result:
- fixes https://github.com/apple/pkl/issues/780
- improved dev experience in IntelliJ
2024-12-06 13:57:19 +01:00
Josh B
077497d9b8 Fix a possible deadlock during external reader process close (#786) (#787)
* Fix a possible deadlock during external reader process close

* Apply spotless

---------

Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-11-08 13:18:13 -08:00
Nick Muerdter
552b301451 Fix broken link to documentation site in release notes (#784) 2024-11-05 12:58:43 -08:00
Dan Chao
d3ac4b288c Prepare 0.27.0 release 2024-11-05 09:51:48 -08:00
Daniel Chao
7eedcf1e50 Prepare 0.27.0 release notes (#756)
Co-authored-by: translatenix <119817707+translatenix@users.noreply.github.com>
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
Co-authored-by: Islon Scherer <islonscherer@gmail.com>
2024-11-05 09:49:50 -08:00
Daniel Chao
a85a173faa Fix equals/hashCode/hasCachedValue in delegating listings/mappings (#781)
This fixes issues when a mapping/listing delegates to another mapping/listing.

The core issue is that `cachedValues` is not guaranteed to be the complete set
of the object's members; they may be stored on the delegate instead.

Therefore, it's not correct compute hash code and equality based on `cachedValues`.
Instead, it's better to use the `getCachedValue()` method, which has the correct
logic for looking up the existing cached value.
2024-11-05 09:05:36 -08:00
Daniel Chao
b402463f3c Eagerly check function arguments when called from inside iterable (#778)
This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to https://github.com/apple/pkl/pull/752.
2024-11-05 09:05:09 -08:00
translatenix
6d161ce1d4 Polish ANSI formatting and underlying code (#779)
- change line numbers from blue to faint to improve legibility on dark backgrounds
- use EnumSet throughout
- move all ANSI classes into package core.util (no need to split them over util and runtime)
- rename AnsiCodingStringBuilder to AnsiStringBuilder
2024-11-05 08:54:35 -08:00
Daniel Chao
40a08affa6 Use ANSI colors for test results; more polish (#771)
Any thrown Pkl Errors are colored in the simple test report!

Also:
* Refactor `TextFormatter` to be more generic; rename to `TextFormattingStringBuilder`
* Adjust test report slightly (no emojis, add more spacing).
* Introduce `ColorTheme` class.
* Make stack frame descriptors colored as "faint"

Also: this changes the summary so it summarizes _all_ modules, rather than a summary per module.

---------

Co-authored-by: Islon Scherer <islonscherer@gmail.com>
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-11-04 14:14:19 -08:00
Daniel Chao
4b4d81ba93 Fix semver comparison logic (#773)
Fix `isLessThan` logic between semvers
2024-11-03 20:31:04 -08:00
Josh B
9692504b5f Remove pkl.core.messaging from core APIs (#770) 2024-11-01 14:53:16 -07:00
Josh B
fa25fb46fd More external reader refinements (#766)
* org.pkl.core.Readers -> org.pkl.core.Closeables
* Remove coupling between pkl.core.module/resource and pkl.core.messaging
2024-11-01 14:05:45 -07:00
translatenix
3f38173ed5 Update commonmark and test dependencies (#767) 2024-11-01 12:48:01 -07:00
translatenix
d50179827d Update to GraalVM 23.0.6 and GraalVM for JDK 17.0.12 (#765)
GraalVM for JDK 17.0.12 is the final Critical Patch Update
made available under the GraalVM Free Terms and Conditions license.
Subsequent Critical Patch Updates require a commercial license.
2024-11-01 12:42:08 -07:00
Philip K.F. Hölzenspies
03462fefae Add color to error formatting (#746)
* Add color to error formatting

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Address reviewer comments

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Define style choices as operations on formatter (abandon semantic API)

* Adjust margin styling

* Review feedback

* Documentation nits

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-11-01 10:02:19 +00:00
Josh B
e217cfcd6f Refine external reader API (#762)
* Encapsulate message transport by removing `ExternalReaderProcess.getTransport` and adding `getModuleResolver` and `getResourceResolver` methods
* Reuse `Random` instances within `ExternalReaderProcessImpl` and module/resource resolvers
* Externalize all `ExternalReaderProcessException` messages
* Add some missing doc comments to `ModuleKeyFactories` and `ResourceReaders` methods for external readers
* Move org.pkl.core.util.Readers to org.pkl.core.Readers
2024-10-31 16:51:25 -07:00
Daniel Chao
66d751f093 Eagerly check listing/mapping in iterables (#752)
There is currently a bug around resolving variables within the iterable of a for
generator or spread syntax (https://github.com/apple/pkl/issues/741)

Normally, mappings/listings are type-checked lazily. However, this results in the said
bug getting widened, for any object members declared in the iterable.

As a workaround for now, prevent the bug from being any worse by ensuring that these
object members are eagerly typechecked.
2024-10-31 14:22:24 -07:00
translatenix
1be1fe4863 Use VmObjectBuilder in Listing.distinct(By) implementations (#760) 2024-10-31 13:28:04 -07:00
translatenix
cc72f9d160 Polish external reader API/implementation (#759)
- keep implementation classes internal to their packages
- make classes final if possible
- make namespace classes non-instantiable
- throw IllegalStateException instead of ExternalReaderProcessException for use after close
  - common convention already used by HttpClient etc.
  - programming errors should be signaled with unchecked exceptions
- use private instead of public lock object
- polish Javadoc
- delete commented out code
- don't use star import for a single class
2024-10-31 13:12:19 -07:00
Philip K.F. Hölzenspies
a03827951c Add methods from List/Map to Listing/Mapping (#683)
* Add `values` to `Mapping`

* Add `entries` to `Mapping`

* Add `containsValue` to `Mapping`

* Add `every` to `Mapping`

* Add `any` to `Mapping`

* Add `toDynamic` to `Mapping`

* Add `lastIndex` to `Listing`

* Add `getOrNull` to `Listing`

* Add `first` to `Listing`

* Add `firstOrNull` to `Listing`

* Add `last` to `Listing`

* Add `lastOrNull` to `Listing`

* Add `single` to `Listing`

* Add `singleOrNull` to `Listing`

* Add `contains` to `Listing`

* Add `any` to `Listing`

* Add `every` to `Listing`

* Fixup `any` to `Listing`

* Revert "Add `toDynamic` to `Mapping`"

This reverts commit 5551974ecd8110aa2eb8f546e992c32d3181df9b.

* Revert "Add `values` to `Mapping`"

This reverts commit 6fc78796

* Revert "Add `entries` to `Mapping`"

This reverts commit a7e8dfc4

* Annotate new members with `Since` 0.27

* Fix documentation in `base.pkl`

* Add location information to empty/single checks in `Listing` operations

* Remove additional variable for laziness preservation

* Apply spotless

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-10-31 14:54:27 +00:00
Stefan M.
71db4d0fae Replace code with italic (#753) 2024-10-30 17:15:04 +00:00
Josh B
dd16f7469e pkl-executor: fix loading projects and fix incorrectly thrown PklException
* Load `PklProject` using the same security settings and env vars passed provided via ExecutorSPIOptions
* Handle thrown `PklException` from loading `PklProject` and throw `ExecutorSPIException`
* Handle thrown `PklException` of older Pkl distributions, converting them into `ExecutorSpiException`
2024-10-29 23:29:19 -07:00
Daniel Chao
acd2222534 Polish test result running and reporting (#738)
Changes:
* Move class `TestResults` to package `org.pkl.core`, because it is a public class (it's the result of `Evaluator#evaluateTest`)
* Change examples to treat individual examples as assertions in the same test. Previously, they were considered different tests with an incrementing number. This better aligns with how facts are treated.
* Change `TestResults` to be a record, and introduce builders.
* Remove "module" test result section (it is not really a section).
* Add javadoc to `TestResults`
* Formatting fix: prefix ✍️ emoji just like we do the  and  emojis 
* Consider writing examples as failures, not successes. `pkl test` will exit with code 10 if the only failing tests are due to writing examples.
2024-10-28 21:05:13 -07:00
Josh B
666f8c3939 Implement SPICE-0009 External Readers (#660)
This adds a new feature, which allows Pkl to read resources and modules from external processes.

Follows the design laid out in SPICE-0009.

Also, this moves most of the messaging API into pkl-core
2024-10-28 18:22:14 -07:00
Daniel Chao
466ae6fd4c Exclude non-ascii files from windows native snippet tests (#739)
There is an existing bug that is preventing the CLI from loading
these files.
2024-10-26 07:56:00 -07:00
translatenix
08be6be059 codegen-java/kotlin: Support Spring Boot 3.x instead of 2.x (#729)
Motivation:
In Spring Boot 3.0, the annotation type `org.springframework.boot.context.properties.ConstructorBinding`
was deprecated in favor of `org.springframework.boot.context.properties.bind.ConstructorBinding`.
In 3.2, the old annotation type was removed.
As of 3.0, a `@ConstructorBinding` annotation is no longer required/recommended for configuration classes with a single public constructor.

Changes:
Remove generation of `@ConstructorBinding` annotations in codegen-java and codegen-kotlin.

Result:
- Generated code is compatible with Spring Boot 3.x.
  (Verified with locally updated pkl-spring.)
- Generated code is no longer compatible with Spring Boot 2.x.
  To use Pkl 0.27 and later with Spring Boot 2.x, use Pkl 0.26's code generator.
- Fixes #139.
2024-10-25 14:08:20 -07:00
translatenix
8fa3acf32f codegen-kotlin: Support Java serialization of module classes (#721)
Motivation:
- Java serialization makes as much sense for module classes as it does for regular classes.
- Offer same Java serialization support as codegen-java.

Changes:
- Move generation of `appendProperty` method and serialization code
  into new method `generateCompanionRelatedCode`.
- Improve/fix generation of serialization code.

Result:
Java serialization is also supported for module classes.
2024-10-24 22:11:35 -07:00
Islon Scherer
8b0118fec5 Store PklProject annotations in the project metadata (#708)
Write annotations to project metadata, and provide them to pkl-doc\

The following annotations have meaning for pkl-doc:
* `@Unlisted`: hide package from documentation site
* `@Deprecated`: add deprecated information
2024-10-24 17:21:58 -07:00
Islon Scherer
93cc3253eb Report error on circular local dependencies (#731)
If a stack overflow is found during project evaluation, present any
circular imports found in the dependency graph.
2024-10-24 16:45:18 -07:00
translatenix
1ceb489d78 Fix lazy type checking of UInt types (#740)
For example, Listing<UInt16> is equivalent to Listing<UInt16>, but not to Listing<UInt32>.
2024-10-24 16:19:26 -07:00
Josh B
4b6bc7bb7c Produce more helpful output when module output is overwritten (#716)
Fix a bug where overwriting `output` causes a PklBugException.

This now produces a more helpful message pointing to the actual problem.

Co-authored-by: translatenix <119817707+translatenix@users.noreply.github.com>
2024-10-24 09:41:59 -07:00
translatenix
cbbcca0d84 codegen-java: Make stateless classes instantiable (#734)
Motivation:
Currently, the condition for making a generated Java class instantiable is "class is neither abstract nor stateless".
(An instantiable class receives a public constructor and equals/hashCode/toString/with methods.)
This is inconsistent with Pkl and codegen-kotlin, both of which support instantiation of stateless classes.

Changes:
Widen condition for making a class instantiable to "class is neither abstract nor a stateless final module class".
This is consistent with codegen-kotlin, which generates object declarations (only) for stateless final module classes.

Result:
Stateless classes are instantiable in Pkl, codegen-java, and codegen-kotlin.
2024-10-24 09:29:08 -07:00
Daniel Chao
22c9a6c9f4 Exclude thrown ascii filename error from native tests (#737)
The URI encoding is not predictable here.
2024-10-24 08:20:56 -07:00
Josh B
069a5d1adc Fix test failures on main (#735) 2024-10-24 11:53:39 +01:00
Javier Maestro
86d870ba09 Improve testing with stats and errors per test section (#498)
* Emojis are moves to the left to be aligned
* A summary line is added with test counts
* Facts and Examples are grouped under their own section
2024-10-23 23:00:35 -07:00
translatenix
2040f14b07 codegen-java: Change condition for generating equals/hashCode/toString/with/Serializable (#710)
Motivation:
- Currently, the condition for generating equals/hashCode/toString methods is "generated class declares properties".
  As a result, classes that don't declare properties inherit these methods from their generated superclasses.
  However, generated `equals` and `toString` methods aren't designed to be inherited
  and will either fail or produce wrong results when called for a subclass.
- Currently, the condition for generating `with` methods is "class is not abstract".
  However, it isn't useful to generate `with` methods for non-instantiable non-abstract classes.
- Currently, the condition for making classes serializable is "class is not a module class".
  However, it isn't useful to make non-instantiable non-module classes serializable,
  and it is useful to make instantiable module classes serializable.

Changes:
- Change condition for generating equals/hashCode/toString/with/Serializable to "class is instantiable".
  This is a breaking change.
  (A generated class is instantiable, i.e., declares a public constructor,
  if it is neither abstract nor stateless. This behavior remains unchanged for now.)
- Overhaul JavaCodeGeneratorTest
  - introduce classes JavaSourceCode and JavaSourceCodeAssert
  - change assertions to use JavaSourceCodeAssert via `assertThat(javaCode)`
  - use parameterized test instead of loop
  - use explicit trimIndent() and trimMargin() for multiline string literals
    - IntelliJ editor desperately wants to insert trimIndent()
    - can potentially be exploited by kotlinc and ktfmt

Result:
- Fixes all motivating issues.
- Fixes #706.
2024-10-23 21:59:15 -07:00
translatenix
730257861f codegen-kotlin: Don't generate equals/hashCode/toString/copy/:Serializable for abstract classes (#714)
* codegen-kotlin: Don't generate equals/hashCode/toString/copy/:Serializable for abstract classes

* Polish KotlinCodeGeneratorTest

- use `assertContains()` instead of `assertThat().contains()`
- remove redundant `trimIndent()` and `trimMargin()` calls
- rename `javaCode` to `kotlinCode`

* Overhaul KotlinCodeGeneratorTest

- introduce classes KotlinSourceCode and KotlinSourceCodeAssert
- change assertions to use KotlinSourceCodeAssert via `assertThat(kotlinCode)`
- use explicit trimIndent() and trimMargin() for multiline string literals
  - IntelliJ editor desperately wants to insert trimIndent()
  - can be used by kotlinc and ktfmt
- format code in the exact way it falls out of the IntelliJ editor
  (successfully destroyed by ktfmt)
2024-10-23 21:31:08 -07:00
Josh B
f9fe226eba Fix handling of file: module URIs with non-ASCII characters (#696)
Addresses an issue where Pkl cannot evaluate files with non-ASCII characters.
2024-10-23 20:52:40 -07:00
Daniel Chao
5a654e453c Fix formatting issues (#733) 2024-10-23 20:49:16 -07:00
Daniel Chao
9d10832ffc Fix typecheck error on Listing/Mapping (#725)
The addresses the following case:

    local l1: Listing<String> = new { 1 }
    l2: Listing<Int> = (l1) { 2 }

The member in `l1` should be checked against its owner; to check against `Listing<String>`.
2024-10-23 14:38:30 -07:00
Daniel Chao
ce25cb8ef0 Add analyze imports libs (SPICE-0001) (#695)
This adds a new feature to build a dependency graph of Pkl programs, following the SPICE outlined in https://github.com/apple/pkl-evolution/pull/2.

It adds:
* CLI command `pkl analyze imports`
* Java API `org.pkl.core.Analyzer`
* Pkl stdlib module `pkl:analyze`
* pkl-gradle extension `analyze`

In addition, it also changes the Gradle plugin such that `transitiveModules` is by default computed from the import graph.
2024-10-23 14:36:57 -07:00
Philip K.F. Hölzenspies
eb3891b21f Change license header from doc- to block-comment (#730)
* Change license header from doc to block comment

* Apply fixed license header throughout
2024-10-23 16:02:42 +01:00
Philip K.F. Hölzenspies
0aa4819cea Add version of resolved Pkl distribution to ExecutorException (#719)
* Add version of resolved Pkl distribution to `ExecutorException`

* Review comments

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-10-23 10:51:53 +01:00
Kushal Pisavadia
a7cc098925 Remove isMappingDefault on VmNull (#724)
This method is unused.
2024-10-22 10:41:31 -07:00
Daniel Chao
0ee3d37524 Add support for const object members (#678)
This adds support for adding the `const` modifier to object members.

Such object members are also required to have the `local` modifier applied.

This follows SPICE-0011.
2024-10-21 22:00:12 -07:00
translatenix
5057bb5b17 Fix build performance issues of spotless tasks (#722)
Using more efficient glob expressions and removing `targetExclude()` greatly speeds up performance on some OSes.
2024-10-21 17:23:40 -07:00
translatenix
9abf1de7de List Pkl GitHub repositories in README (#715) 2024-10-21 17:22:29 -07:00
translatenix
84f4ec863c codegen-kotlin: Fix generation of copy() methods (#705)
- don't generate copy methods for abstract classes
- precisely determine if copy method needs override modifier (tricky)

Fixes #569
2024-10-19 20:32:21 -07:00
translatenix
d271b62543 Update dependencies (#689)
- Update dependencies by deleting lock files and regenerating them with `gw updateDependencyLocks`.
  Deleting lock files avoids strange `some.library:some.older.version=default` entries.
  Most updated dependencies are test dependencies.
- Handle breaking changes in library commonmark.
- Fix test to close PackageServer exactly once.
  This problem surfaced because JUnit 5.11 changed override rules for lifecycle methods,
  resulting in too many instead of too few close() calls.
- Bump msgpack version
- Bump clikt version
- Bump Gradle plugin versions
2024-10-17 09:12:07 -07:00
Josh B
62c796a257 Fix double unary minus (#697)
Fix an issue where doubly unary minus (e.g. `--1`) on int/float literals are incorrectly
parsed as single unary minus.
2024-10-17 07:30:00 -07:00
Jens Teglhus Møller
9b5c5a5c98 Fix error in spread documentation (#704) 2024-10-17 07:16:53 -07:00
Daniel Chao
2add291375 Fix formatting of let expressions (#702) 2024-10-17 07:02:24 -07:00
Daniel Chao
7ac51f1f88 Fix invalid syntax in doc comments of pkl:reflect members (#703) 2024-10-17 07:02:10 -07:00
translatenix
1022cf3ff3 Replace some usages of java.lang.String.replaceAll with String.replace (#701)
Both methods replace all occurrences.
The difference is that String.replaceAll interprets its first argument as a regex.
2024-10-16 15:00:45 -07:00
Philip K.F. Hölzenspies
421711be10 Improve let-expression examples (#680) (#699)
Because I did not understand what a `Let Expression` should be and the example code was more confusing as explanatory, I changed the format of the examples a little bit and changed the result.

- It should be clear that the example is just one code-line
- I tried out the example (`pkl eval...`) and get a little bit different result

Co-authored-by: ManuW <ManuW@users.noreply.github.com>
2024-10-16 13:10:48 +01:00
translatenix
475f29c896 Set lower limit for glob pattern resolution in test mode (#693)
Motivation:
Speed up the test that verifies enforcement of the limit for glob pattern resolution (invalidGlobImport6.pkl).

Changes:
- Set a lower limit if test mode is enabled.
- Change static field to static method to prevent compile-time evaluation by native-image.
2024-10-15 22:20:25 -07:00
translatenix
d00c466843 Fix dangling Javadoc reference (#687) 2024-10-15 08:26:35 -07:00
translatenix
7f26592360 Use case-insensitive comparison for module URI schemes (#688)
Previously, some factories used case-sensitive comparison, for no apparent reason.
2024-10-15 08:26:23 -07:00
translatenix
4854027a1a Update Gradle to 8.10.2 (#684)
Verify wrapper JAR according to:
https://docs.gradle.org/current/userguide/gradle_wrapper.html#wrapper_checksum_verification
2024-10-14 22:53:26 -07:00
translatenix
2961cdad19 Update Windows and Mac development instructions (#685) 2024-10-14 22:52:59 -07:00
translatenix
b76ff0f858 Don't run native Windows tests during pkl-core:test (#686) 2024-10-14 22:51:28 -07:00
translatenix
bc9d526b7a Update DEVELOPMENT.adoc (#682) 2024-10-14 11:00:16 +02:00
Daniel Chao
3600582908 Add .vscode and .pkl-lsp to gitignore (#677) 2024-10-11 07:59:35 -07:00
Josh B
1e63c48ce4 Add String.splitLimit API (#666)
* Add String.splitLimit API

* Update stdlib/base.pkl

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-10-07 15:28:19 +01:00
Max Rydahl Andersen
9e7e42eb53 add jbang catalog (#655) 2024-10-07 13:13:38 +02:00
Josh B
b072794d0d Handle null contents gracefully in message passing API (#657)
In messages "Read Resource Response" and "Read Module Response", if `contents` and `error` are both null, default to an empty byte array/string.

This resolves one of the issues reported in #656
2024-10-01 12:54:06 -07:00
Philip K.F. Hölzenspies
cc1e432a30 Add PklProject.deps.json file with newline for POSIX compliance (#664)
* Add Project.deps.json file with newline for POSIX compliance

* Fix test cases
2024-10-01 20:00:46 +01:00
Daniel Chao
47f2143e0d Fix PklBugException when reading local package assets (#642) 2024-09-10 05:51:34 -07:00
Daniel Chao
7868d9d9c8 Typecheck Mapping/Listing members lazily (#628)
This changes how the language performs typechecks for mappings and
listings.

Currently, Pkl will shallow-force any Mapping and Listing to check it
the type parameter (e.g. Listing<Person> means each element is checked
to be an instance of Person).

This changes the language to check each member's type when the member
is accessed.

This also adjust test runner to handle thrown errors from within tests.

With the change to make mapping/listing typechecks lazy, we can now
correctly handle thrown errors from within a single test case.

This adjusts the test runner to consider any thrown errors as a failure
for that specific test case.
2024-09-06 15:05:23 -07:00
Josh B
7001a42149 [docs] Add documentation for new keyword (#624) 2024-08-29 15:25:14 -07:00
Philip K.F. Hölzenspies
a8f24c9f13 Fix parsing of external property values containing = (#631) 2024-08-20 13:28:13 +01:00
Josh B
e5b7e046d9 [docs] Improve searchability of "Methods" section (#625) 2024-08-19 15:54:46 -07:00
LamTrinh.Dev
ef0433a9ba Correct the link for ANTLR 4 Documentation (#623) 2024-08-15 20:15:26 -07:00
Josh B
a9c4963a4a [docs] Document the class-as-a-function pattern (#614) 2024-08-15 17:06:56 -07:00
Philip K.F. Hölzenspies
e21db76efe Remove const from reserved keywords (remnant) (#626) 2024-08-14 14:48:49 +01:00
Josh B
bbdc45656c [docs] Document hidden equality/hashing behavior (#618)
* [docs] Document `hidden` equality/hashing behavior

* Update docs/modules/language-reference/pages/index.adoc

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-08-13 09:56:15 +02:00
Josh B
c445770261 [docs] Add mention of "optional" to nullably types section (#613) 2024-08-07 12:18:50 -07:00
Daniel Chao
b1c2015321 Cherry pick 0.26.3 release notes (#615) 2024-08-06 12:08:44 -07:00
Daniel Chao
7c4904429f Fix: make Gradle tests compatible with Gradle 8.1 (#610)
The tests were using assignment expressions, a Kotlin compiler feature
only available in Gradle 8.2 and onwards.
2024-08-06 07:55:13 -07:00
Daniel Chao
d5e86ed077 Fix: globbing--read extra storage from owner instead of receiver (#607)
This fixes an issue where a PklBugException is thrown when a globbed
read/import is amended.
2024-08-05 10:27:50 -07:00
Daniel Chao
604b042d1b Make EvalTask track resolved output paths and fix file() notation on Gradle on Windows (#403)
* Add `getEffectiveOutputFiles` and `getEffectiveOutputDirs` to `EvalTask`, and mark them as output files/dirs so they are tracked by Gradle. This enables implicit dependency tracking between two tasks.
* Fix usage of `file()` notation in Gradle scripts when on Windows.
2024-07-25 17:41:03 -07:00
Islon Scherer
e3133f604b Fix property parsing bug in the cli (#596) 2024-07-25 09:27:38 +02:00
XIAO YU
bfc2d7abbf refactor: Simplify regex pattern for code block matching (#592) 2024-07-24 15:13:49 +01:00
XIAO YU
0704b8cd83 Remove redundant suppression (#594) 2024-07-22 17:14:54 -07:00
Daniel Chao
e81a47a038 Import release notes for 0.26.2 (#587) 2024-07-18 09:39:13 -07:00
Daniel Chao
176ede0002 Fix race condition when concurrently downloading packages (#584)
This fixes a possible race condition where multiple processes download
the same package into the same temp dir.
2024-07-18 09:11:25 -07:00
Islon Scherer
24cc95abcc Support _ in String[toInt|toIntOrNull|toFloat|toFloatOrNull] (#580)
The logic is the same as the Pkl parser
2024-07-16 19:24:59 +02:00
Taichi Ishitani
b5e011dae1 Allow to toInt() to parse a string including "__" (#578)
Fix the issue where String#toInt() cannot parse a Int string
including sequence of "_" like "1_2__3___".
2024-07-15 10:39:17 +02:00
Thomas Purchas
cdf548cad0 Add CSS to make top doc box have a fade, rather than hard cutoff (#570)
The current hard cutoff in the docs often results in people not
realising that the doc box can be expanded, and often resulting in
confusion because the most helpful examples are often in the module doc
box.

This change uses some simple CSS tweaks to replace the hard cut-off with
a visualfade, so it's obvious that there's content hidden out of view.
Doing this required removing the CSS transition, as it hard to correctly
transition the height property of CSS element of unknown target height.
But the improved discoverablility of the doc content seems like a
worthwhile tradeoff.
2024-07-08 15:12:24 +01:00
Philip K.F. Hölzenspies
5cc2ea2d00 Revert error coloring (for development on dedicated branch) (#565) 2024-07-03 17:25:06 +01:00
Dan Chao
527d236ba4 Add Git ignore-revs file 2024-07-01 09:24:04 -07:00
Dan Chao
8c1c10528f Run spotless apply 2024-07-01 09:24:04 -07:00
Dan Chao
7a9b571f6e Use spotless to format remaining Kotlin files
Also: fix issue where some commented out Kotlin files are invalid.
2024-07-01 09:24:04 -07:00
Thomas Purchas
3659ad8b7a Add test for colour outputs
Test two error conditions that cover all current colour outputs.
2024-07-01 10:13:16 +01:00
Thomas Purchas
0d7b95d3ff Add colours to Pkl errors in Cli output
To make error messages from Pkl eval easier to read, this change uses
the Jansi library to colour the output, making it quicker and easier to
scan error messages and understand what's happened.

The Jansi library also detects if the CLI output is a terminal capable
of handling colours, and will automatically strip out escape codes if
the output won't support them (e.g. piping the output somewhere else).
2024-07-01 10:13:16 +01:00
Daniel Chao
49aaf288cc Cherry-pick release notes for 0.26.1 (#557) 2024-06-28 10:23:24 -07:00
Daniel Chao
51d7265ec6 Do not enable TLS certificate revocation checks by default (#553)
This addresses an issue where network requests may fail if cert revocation checks
error, which may occur due to availability issues, or due to lack of internet access.

Revocation checking can still be enabled by setting JVM property com.sun.net.ssl.checkRevocation if on the JVM.

Also:
* Load built-in certs from resources, and move them to pkl-commons-cli
* Fix an issue where HttpInitException is not caught when loading a module
2024-06-28 08:57:46 -07:00
Daniel Chao
420336dc78 Only run Gradle compatibility tests against releases in CI (#554)
This fixes our CI tests on main. It mitigates an issue where the current RC is borked right now.
2024-06-28 07:57:27 -07:00
Daniel Chao
70e77347f3 Use compatible architecture in native executables (#551)
Use the most compatible architecture; for example, x86-64 instead of
x86-64-v3.
2024-06-27 07:39:17 -07:00
Philip K.F. Hölzenspies
3b786878fd Pass HOMEBREW_* environment variables on through native_image 2024-06-26 16:31:31 +01:00
Philip K.F. Hölzenspies
64bfcfdc4f Resolve project dirs from working dir by default 2024-06-25 13:13:48 +01:00
Daniel Chao
5c950d2e73 docs: add contributor for 0.26 release (#546)
Add a contributor name who was missing from acknowledgements.
2024-06-24 07:47:26 -07:00
Philip K.F. Hölzenspies
0ef22a73fb Start next dev iteration 2024-06-17 19:53:30 +01:00
Philip K.F. Hölzenspies
4a27ac5bda Prepare 0.26.0 release 2024-06-17 19:53:30 +01:00
1115 changed files with 26048 additions and 9673 deletions

View File

@@ -108,10 +108,12 @@ local gradleCheckJobs: Mapping<String, GradleCheckJob> = new {
["gradle-check-jdk17"] {
javaVersion = "17.0"
isRelease = false
os = "linux"
}
["gradle-check-jdk21"] {
javaVersion = "21.0"
isRelease = false
os = "linux"
}
["gradle-check-jdk17-windows"] {
javaVersion = "17.0"
@@ -132,8 +134,7 @@ jobs {
name = "gradle compatibility"
command = #"""
:pkl-gradle:build \
:pkl-gradle:compatibilityTestReleases \
:pkl-gradle:compatibilityTestCandidate
:pkl-gradle:compatibilityTestReleases
"""#
}.job
["deploy-snapshot"] = new DeployJob { command = "publishToSonatype" }.job

View File

@@ -39,7 +39,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -52,7 +52,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -65,7 +65,7 @@ jobs:
# install musl
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
curl -L https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
mkdir -p /tmp/dep_musl-1.2.2 \
&& cd /tmp/dep_musl-1.2.2 \
@@ -135,7 +135,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -148,7 +148,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -196,7 +196,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -209,7 +209,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -222,7 +222,7 @@ jobs:
# install musl
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
curl -L https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
mkdir -p /tmp/dep_musl-1.2.2 \
&& cd /tmp/dep_musl-1.2.2 \
@@ -262,6 +262,18 @@ jobs:
pkl-cli-windows-amd64-release:
steps:
- checkout
- run:
command: |-
# install jdk
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9.1/OpenJDK17U-jdk_x64_windows_hotspot_17.0.9_9.zip -o /tmp/jdk.zip
unzip /tmp/jdk.zip -d /tmp/jdk \
&& cd /tmp/jdk/jdk-* \
&& mkdir /jdk \
&& cp -r . /jdk
name: Set up environment
shell: bash.exe
- run:
command: |-
export PATH=~/staticdeps/bin:$PATH
@@ -276,6 +288,7 @@ jobs:
path: ~/test-results
environment:
LANG: en_US.UTF-8
JAVA_HOME: /jdk
resource_class: windows.large
machine:
image: windows-server-2022-gui:current
@@ -315,7 +328,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -328,7 +341,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -341,7 +354,7 @@ jobs:
# install musl
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
curl -L https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
mkdir -p /tmp/dep_musl-1.2.2 \
&& cd /tmp/dep_musl-1.2.2 \
@@ -411,7 +424,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -424,7 +437,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -472,7 +485,7 @@ jobs:
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
@@ -485,7 +498,7 @@ jobs:
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-1.2.13 \
&& cd /tmp/dep_zlib-1.2.13 \
@@ -498,7 +511,7 @@ jobs:
# install musl
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
curl -L https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz
mkdir -p /tmp/dep_musl-1.2.2 \
&& cd /tmp/dep_musl-1.2.2 \
@@ -538,6 +551,18 @@ jobs:
pkl-cli-windows-amd64-snapshot:
steps:
- checkout
- run:
command: |-
# install jdk
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9.1/OpenJDK17U-jdk_x64_windows_hotspot_17.0.9_9.zip -o /tmp/jdk.zip
unzip /tmp/jdk.zip -d /tmp/jdk \
&& cd /tmp/jdk/jdk-* \
&& mkdir /jdk \
&& cp -r . /jdk
name: Set up environment
shell: bash.exe
- run:
command: |-
export PATH=~/staticdeps/bin:$PATH
@@ -552,6 +577,7 @@ jobs:
path: ~/test-results
environment:
LANG: en_US.UTF-8
JAVA_HOME: /jdk
resource_class: windows.large
machine:
image: windows-server-2022-gui:current
@@ -582,6 +608,18 @@ jobs:
gradle-check-jdk17-windows:
steps:
- checkout
- run:
command: |-
# install jdk
curl -Lf \
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9.1/OpenJDK17U-jdk_x64_windows_hotspot_17.0.9_9.zip -o /tmp/jdk.zip
unzip /tmp/jdk.zip -d /tmp/jdk \
&& cd /tmp/jdk/jdk-* \
&& mkdir /jdk \
&& cp -r . /jdk
name: Set up environment
shell: bash.exe
- run:
command: ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results check
name: gradle check
@@ -589,6 +627,7 @@ jobs:
path: ~/test-results
environment:
LANG: en_US.UTF-8
JAVA_HOME: /jdk
resource_class: windows.large
machine:
image: windows-server-2022-gui:current
@@ -610,8 +649,7 @@ jobs:
- run:
command: |-
./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results :pkl-gradle:build \
:pkl-gradle:compatibilityTestReleases \
:pkl-gradle:compatibilityTestCandidate
:pkl-gradle:compatibilityTestReleases
name: gradle compatibility
- store_test_results:
path: ~/test-results

View File

@@ -17,7 +17,6 @@
extends "GradleJob.pkl"
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.2#/Config.pkl"
import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1.0.0#/URI.pkl"
/// The architecture to use
arch: "amd64"|"aarch64"
@@ -25,13 +24,11 @@ arch: "amd64"|"aarch64"
/// Whether to link to musl. Otherwise, links to glibc.
musl: Boolean = false
javaVersion = "17.0"
local setupLinuxEnvironment: Config.RunStep =
let (jdkVersion = "17.0.9+9")
let (muslVersion = "1.2.2")
let (zlibVersion = "1.2.13")
let (jdkVersionEncoded = URI.encodeComponent(jdkVersion))
let (jdkVersionAlt = jdkVersion.replaceLast("+", "_"))
let (majorJdkVersion = jdkVersion.split(".").first)
new {
name = "Set up environment"
shell = "#!/bin/bash -exo pipefail"
@@ -43,8 +40,8 @@ local setupLinuxEnvironment: Config.RunStep =
&& rm -rf /var/cache/dnf
# install jdk
curl -L \
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/jdk-\#(jdkVersionEncoded)/OpenJDK\#(majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_linux_hotspot_\#(jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
curl -Lf \
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
mkdir /jdk \
&& cd /jdk \
@@ -56,7 +53,7 @@ local setupLinuxEnvironment: Config.RunStep =
# install zlib
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
curl -L https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
curl -Lf https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
mkdir -p /tmp/dep_zlib-\#(zlibVersion) \
&& cd /tmp/dep_zlib-\#(zlibVersion) \
@@ -72,7 +69,7 @@ local setupLinuxEnvironment: Config.RunStep =
#"""
# install musl
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
curl -L https://musl.libc.org/releases/musl-\#(muslVersion).tar.gz -o /tmp/musl.tar.gz
curl -Lf https://musl.libc.org/releases/musl-\#(muslVersion).tar.gz -o /tmp/musl.tar.gz
mkdir -p /tmp/dep_musl-\#(muslVersion) \
&& cd /tmp/dep_musl-\#(muslVersion) \
@@ -145,7 +142,7 @@ job {
resource_class = "macos.m1.large.gen1"
}
when (os == "linux") {
docker {
docker = new Listing<Config.DockerImage> {
new {
image = if (arch == "aarch64") "arm64v8/oraclelinux:8-slim" else "oraclelinux:8-slim"
}
@@ -160,5 +157,8 @@ job {
image = "windows-server-2022-gui:current"
}
resource_class = "windows.large"
environment {
["JAVA_HOME"] = "/jdk"
}
}
}

View File

@@ -19,13 +19,9 @@ import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.2#/Config.pkl"
local self = this
command: String
javaVersion = "17.0"
job {
docker {
new { image = "cimg/openjdk:17.0" }
}
}
command: String
os = "linux"

View File

@@ -17,29 +17,9 @@ extends "GradleJob.pkl"
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.2#/Config.pkl"
javaVersion: "17.0"|"21.0"
os = "linux"
steps {
new Config.RunStep {
name = "gradle check"
command = "./gradlew \(module.gradleArgs) check"
}
}
job {
when (os == "linux") {
docker {
new {
image = "cimg/openjdk:\(javaVersion)"
}
}
}
when (os == "windows") {
machine {
image = "windows-server-2022-gui:current"
}
resource_class = "windows.large"
}
}

View File

@@ -16,6 +16,7 @@
abstract module GradleJob
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.2#/Config.pkl"
import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1.0.3#/URI.pkl"
/// Whether this is a release build or not.
isRelease: Boolean = false
@@ -23,6 +24,25 @@ isRelease: Boolean = false
/// The OS to run on
os: "macOS"|"linux"|"windows"
/// The version of Java to use.
javaVersion: "17.0"|"21.0"
fixed javaVersionFull =
if (javaVersion == "17.0") "17.0.9+9"
else "21.0.5+11"
fixed jdkVersionAlt = javaVersionFull.replaceLast("+", "_")
fixed majorJdkVersion = javaVersionFull.split(".").first
fixed jdkGitHubReleaseName =
let (ver =
// 17.0.9+9 is missing some binaries (see https://github.com/adoptium/adoptium-support/issues/994)
if (javaVersionFull == "17.0.9+9" && os == "windows") "jdk-17.0.9+9.1"
else "jdk-\(javaVersionFull)"
)
URI.encodeComponent(ver)
fixed gradleArgs = new Listing {
"--info"
"--stacktrace"
@@ -37,9 +57,41 @@ steps: Listing<Config.Step>
job: Config.Job = new {
environment {
["LANG"] = "en_US.UTF-8"
when (os == "windows") {
["JAVA_HOME"] = "/jdk"
}
}
when (os == "linux") {
docker {
new {
image = "cimg/openjdk:\(javaVersion)"
}
}
}
when (os == "windows") {
machine {
image = "windows-server-2022-gui:current"
}
resource_class = "windows.large"
}
steps {
"checkout"
when (os == "windows") {
new Config.RunStep {
name = "Set up environment"
shell = "bash.exe"
command = #"""
# install jdk
curl -Lf \
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/\#(jdkGitHubReleaseName)/OpenJDK\#(majorJdkVersion)U-jdk_x64_windows_hotspot_\#(jdkVersionAlt).zip -o /tmp/jdk.zip
unzip /tmp/jdk.zip -d /tmp/jdk \
&& cd /tmp/jdk/jdk-* \
&& mkdir /jdk \
&& cp -r . /jdk
"""#
}
}
...module.steps
new Config.StoreTestResults {
path = "~/test-results"

View File

@@ -23,6 +23,8 @@ command: String
os = "linux"
javaVersion = "17.0"
steps {
new Config.RunStep {
name = module.name
@@ -31,9 +33,3 @@ steps {
"""
}
}
job {
docker {
new { image = "cimg/openjdk:17.0" }
}
}

2
.git-blame-ignore-revs Normal file
View File

@@ -0,0 +1,2 @@
# Auto-format Kotlin code
816cd483c8adf4c04e14236c173a1dc6bd2579ea

4
.gitignore vendored
View File

@@ -15,6 +15,10 @@ generated/
!.idea/scopes/
!.idea/vcs.xml
.vscode/
.pkl-lsp/
# :pkl-core:makeIntelliJAntlrPluginHappy
gen/
PklLexer.tokens

View File

@@ -3,16 +3,20 @@
:uri-jenv: https://www.jenv.be
:uri-intellij: https://www.jetbrains.com/idea/download/
:uri-jdk: https://adoptopenjdk.net/releases.html?variant=openjdk17
:uri-native-prerequisites-linux: https://www.graalvm.org/latest/getting-started/linux/#prerequisites-for-native-image-on-linux
:uri-native-prerequisites-windows: https://www.graalvm.org/latest/getting-started/windows/#prerequisites-for-native-image-on-windows
== Setup
. (mandatory) Install {uri-jdk}[OpenJDK 17] or higher
. (recommended) Install {uri-intellij}[IntelliJ IDEA 2023.x] +
. (recommended) Install {uri-intellij}[IntelliJ IDEA] +
To import the project into IntelliJ, go to File->Open and select the project's root directory.
If the project is opened but not imported, look for a popup in the lower right corner
and click its "Import Gradle Project" link.
. (recommended) Install {uri-gng}[gng] +
_gng_ enables to run Gradle commands with `gw` (instead of `./gradlew`) from any subdirectory.
. (recommended) Set up Git ignore-revs +
`git config blame.ignoreRevsFile .git-blame-ignore-revs`
. (recommended) Install {uri-jenv}[jenv] and plugins +
_jenv_ use specific JDK versions in certain subdirectories. _Pkl_ comes with a `.java-version` file specifying JDK 17. +
Enable _jenv_ plugins for better handling by `gradle`:
@@ -22,6 +26,20 @@ Enable _jenv_ plugins for better handling by `gradle`:
jenv enable-plugin gradle
jenv enable-plugin export
----
. (optional) If you've named the original apple/pkl git repository something other than `origin`, set env var `PKL_ORIGINAL_REMOTE_NAME` to that name in your `.bashrc`, `.zshrc`, `config.fish` or however you manage your local environment.
+
This will allow spotless to pick the correct starting branch when formatting source code files.
Otherwise, you might see that _every_ file has its copyright year updated.
=== Additional Linux Setup
. (optional) To build the native executable (`./gradlew buildNative`),
install {uri-native-prerequisites-linux}[Prerequisites For Native Image on Linux].
=== Additional Windows Setup
. (optional) Go to `System->For developers` and enable `Developer Mode`.
Otherwise, some tests may fail due to insufficient file system privileges.
. (optional) To build the native executable (`./gradlew buildNative`),
install {uri-native-prerequisites-windows}[Prerequisites For Native Image on Windows].
== Common Build Commands
@@ -32,12 +50,12 @@ gw test # run all tests except native executable tests
gw testNative # run native executable tests
gw spotlessApply # fix code formatting
gw build # build everything except native executables
gw buildNative # build macOS executable on macOS,
# Linux and Alpine executables on Linux
gw buildNative # build native executable(s) for current platform
# (Alpine executable is only built if ~/staticdeps/bin/musl-gcc exists)
pkl-cli/build/executable/jpkl # run Java executable
pkl-cli/build/executable/pkl-macos-amd64 # run Mac executable
pkl-cli/build/executable/pkl-macos-aarch64 # run Mac executable
pkl-cli/build/executable/pkl-macos-amd64 # run Intel Mac executable
pkl-cli/build/executable/pkl-linux-amd64 # run Linux executable
pkl-cli/build/executable/pkl-alpine-linux-amd64 # run Alpine Linux executable
pkl-cli/build/executable/pkl-windows-amd64.exe # run Windows executable
@@ -81,7 +99,7 @@ For automated build setup examples see our https://github.com/apple/pkl/blob/mai
=== ANTLR
* https://github.com/antlr/antlr4/blob/main/doc/index.md[Documentation]
* https://github.com/antlr/antlr4/blob/master/doc/index.md[Documentation]
* https://groups.google.com/forum/#!forum/antlr-discussion[Forums]
* https://github.com/mobileink/lab.clj.antlr/tree/main/doc[Some third-party docs]

View File

@@ -1,4 +1,4 @@
Copyright © 2024 Apple Inc. and the Pkl project authors
Copyright © 2024-2025 Apple Inc. and the Pkl project authors
Portions of this software were originally based on 'SnakeYAML' developed by Andrey Somov.

View File

@@ -41,3 +41,73 @@ We'd love to hear from you!
* link:CONTRIBUTING.adoc[] for tips on pull requests and filing issues
* link:DEVELOPMENT.adoc[] for build instructions
* {uri-ci-artifacts}[Sonatype Repository] for the artifacts/binaries built by our {uri-ci-pipeline}[CI pipelines] (and those of our other tools and packages repositories).
== Pkl GitHub Repositories
[%autowidth]
|===
|Name |Description
|`apple/pkl`
|A configuration as code language with rich validation and tooling.
|https://github.com/apple/pkl-evolution[`apple/pkl-evolution`]
|Suggested Pkl Improvements, Changes, or Enhancements (SPICEs)
|https://github.com/apple/pkl-go[`apple/pkl-go`]
|Pkl bindings for the Go programming language
|https://github.com/apple/pkl-go-examples[`apple/pkl-go-examples`]
|Examples for using Pkl within Go applications
|https://github.com/apple/pkl-intellij[`apple/pkl-intellij`]
|JetBrains editor plugins providing Pkl language support
|https://github.com/apple/pkl-jvm-examples[`apple/pkl-jvm-examples`]
|Examples for using Pkl within JVM applications
|https://github.com/apple/pkl-k8s[`apple/pkl-k8s`]
|Templates for using Pkl with Kubernetes
|https://github.com/apple/pkl-k8s-examples[`apple/pkl-k8s-examples`]
|Examples for using Pkl with Kubernetes
|https://github.com/apple/pkl-lang.org[`apple/pkl-lang.org`]
|The pkl-lang.org website
|https://github.com/apple/pkl-lsp[`apple/pkl-lsp`]
| Language server for Pkl, implementing the server-side of the Language Server Protocol
|https://github.com/apple/pkl-neovim[`apple/pkl-neovim`]
|Pkl language support for Neovim
|https://github.com/apple/pkl-package-docs[`apple/pkl-package-docs`]
|Documentation for Pkl packages
|https://github.com/apple/pkl-pantry[`apple/pkl-pantry`]
|Shared Pkl packages
|https://github.com/apple/pkl-project-commons[`apple/pkl-project-commons`]
|Utility libraries for Pkl
|https://github.com/apple/pkl-spring[`apple/pkl-spring`]
|Spring Boot extension for configuring Boot apps with Pkl
|https://github.com/apple/pkl-swift[`apple/pkl-swift`]
|Pkl bindings for the Swift programming language
|https://github.com/apple/pkl-swift-examples[`apple/pkl-swift-examples`]
|Examples for using Pkl within Swift applications
|https://github.com/apple/pkl-vscode[`apple/pkl-vscode`]
|Pkl language support for VS Code
|https://github.com/apple/pkl.tmbundle[`apple/pkl.tmbundle`]
|TextMate bundle for Pkl
|https://github.com/apple/rules_pkl[`apple/rules_pkl`]
| Bazel build rules for Pkl
|https://github.com/apple/tree-sitter-pkl[`apple/tree-sitter-pkl`]
|Tree-sitter parser for Pkl
|===

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
pklAllProjects
pklJavaLibrary
@@ -18,14 +33,15 @@ dependencies {
}
jmh {
//include = ["fib_class_java"]
//include = ["fib_class_constrained1", "fib_class_constrained2"]
// include = ["fib_class_java"]
// include = ["fib_class_constrained1", "fib_class_constrained2"]
jmhVersion.set(libs.versions.jmh)
// jvmArgsAppend = "-Dgraal.TruffleCompilationExceptionsAreFatal=true " +
// "-Dgraal.Dump=Truffle,TruffleTree -Dgraal.TraceTruffleCompilation=true " +
// "-Dgraal.TruffleFunctionInlining=false"
jvm.set("${buildInfo.graalVmAmd64.baseDir}/bin/java")
// see: https://docs.oracle.com/en/graalvm/enterprise/20/docs/graalvm-as-a-platform/implement-language/#disable-class-path-separation
// see:
// https://docs.oracle.com/en/graalvm/enterprise/20/docs/graalvm-as-a-platform/implement-language/#disable-class-path-separation
jvmArgs.set(
listOf(
// one JVM arg per list element doesn't work, but the following does
@@ -33,16 +49,13 @@ jmh {
)
)
includeTests.set(false)
//threads = Runtime.runtime.availableProcessors() / 2 + 1
//synchronizeIterations = false
// threads = Runtime.runtime.availableProcessors() / 2 + 1
// synchronizeIterations = false
}
tasks.named("jmh") {
dependsOn(":installGraalVmAmd64")
}
tasks.named("jmh") { dependsOn(":installGraalVmAmd64") }
// Prevent this error which occurs when building in IntelliJ:
// "Entry org/pkl/core/fib_class_typed.pkl is a duplicate but no duplicate handling strategy has been set."
tasks.processJmhResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// "Entry org/pkl/core/fib_class_typed.pkl is a duplicate but no duplicate handling strategy has
// been set."
tasks.processJmhResources { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }

View File

@@ -2,15 +2,15 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.tunnelvisionlabs:antlr4-runtime:4.9.0=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.18=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
net.sf.jopt-simple:jopt-simple:5.0.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.apache.commons:commons-math3:3.6.1=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.compiler:compiler:23.0.2=graal
org.graalvm.sdk:graal-sdk:23.0.2=graal,jmh,jmhRuntimeClasspath,truffle
org.graalvm.truffle:truffle-api:23.0.2=graal,jmh,jmhRuntimeClasspath,truffle
org.assertj:assertj-core:3.26.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.compiler:compiler:23.0.6=graal
org.graalvm.sdk:graal-sdk:23.0.6=graal,jmh,jmhRuntimeClasspath,truffle
org.graalvm.truffle:truffle-api:23.0.6=graal,jmh,jmhRuntimeClasspath,truffle
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
@@ -26,12 +26,13 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=testCompileClasspath,testImplemen
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=kotlinCompilerClasspath,kotlinCompilerPluginClasspathJmh,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains:annotations:13.0=kotlinCompilerClasspath,kotlinCompilerPluginClasspathJmh,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.10.2=testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.10.2=testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.11.3=testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.11.3=testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.msgpack:msgpack-core:0.9.8=jmh,jmhRuntimeClasspath
org.openjdk.jmh:jmh-core:1.37=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.openjdk.jmh:jmh-generator-asm:1.37=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.openjdk.jmh:jmh-generator-bytecode:1.37=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
@@ -40,4 +41,4 @@ org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenc
org.organicdesign:Paguro:3.10.3=jmh,jmhRuntimeClasspath
org.ow2.asm:asm:9.0=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.snakeyaml:snakeyaml-engine:2.5=jmh,jmhRuntimeClasspath
empty=annotationProcessor,apiDependenciesMetadata,archives,compile,compileClasspath,compileOnly,compileOnlyDependenciesMetadata,default,implementationDependenciesMetadata,intransitiveDependenciesMetadata,jmhAnnotationProcessor,jmhApiDependenciesMetadata,jmhCompile,jmhCompileOnly,jmhCompileOnlyDependenciesMetadata,jmhIntransitiveDependenciesMetadata,jmhKotlinScriptDef,jmhKotlinScriptDefExtensions,jmhRuntime,jmhRuntimeOnlyDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeClasspath,runtimeOnlyDependenciesMetadata,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
empty=annotationProcessor,apiDependenciesMetadata,compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,intransitiveDependenciesMetadata,jmhAnnotationProcessor,jmhApiDependenciesMetadata,jmhCompileOnlyDependenciesMetadata,jmhIntransitiveDependenciesMetadata,jmhKotlinScriptDef,jmhKotlinScriptDefExtensions,jmhRuntimeOnlyDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtimeClasspath,runtimeOnlyDependenciesMetadata,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -50,7 +50,8 @@ public class ListSort {
null,
null,
IoUtils.getCurrentWorkingDir(),
StackFrameTransformers.defaultTransformer);
StackFrameTransformers.defaultTransformer,
false);
private static final List<Object> list = new ArrayList<>(100000);
static {

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,5 +1,20 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// https://youtrack.jetbrains.com/issue/KTIJ-19369
@file:Suppress("DSL_SCOPE_VIOLATION")
@file:Suppress("DSL_SCOPE_VIOLATION")
import org.jetbrains.gradle.ext.ActionDelegationConfig
import org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
@@ -40,15 +55,12 @@ idea {
}
}
val clean by tasks.registering(Delete::class) {
delete(layout.buildDirectory)
}
val clean by tasks.existing { delete(layout.buildDirectory) }
val printVersion by tasks.registering {
doFirst { println(buildInfo.pklVersion) }
}
val printVersion by tasks.registering { doFirst { println(buildInfo.pklVersion) } }
val message = """
val message =
"""
====
Gradle version : ${gradle.gradleVersion}
Java version : ${System.getProperty("java.version")}
@@ -63,5 +75,7 @@ Git Commit ID : ${buildInfo.commitId}
====
"""
val formattedMessage = message.replace("\n====", "\n" + "=".repeat(message.lines().maxByOrNull { it.length }!!.length))
val formattedMessage =
message.replace("\n====", "\n" + "=".repeat(message.lines().maxByOrNull { it.length }!!.length))
logger.info(formattedMessage)

View File

@@ -1,15 +1,24 @@
import org.jetbrains.kotlin.config.JvmTarget
plugins {
`kotlin-dsl`
}
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins { `kotlin-dsl` }
dependencies {
implementation(libs.downloadTaskPlugin)
implementation(libs.spotlessPlugin)
implementation(libs.kotlinPlugin) {
exclude(module = "kotlin-android-extensions")
}
implementation(libs.kotlinPlugin) { exclude(module = "kotlin-android-extensions") }
implementation(libs.shadowPlugin)
// fix from the Gradle team: makes version catalog symbols available in build scripts
@@ -22,12 +31,4 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
target {
compilations.configureEach {
kotlinOptions {
jvmTarget = "17"
}
}
}
}
kotlin { target { compilations.configureEach { kotlinOptions { jvmTarget = "17" } } } }

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("UnstableApiUsage")
rootProject.name = "buildSrc"
@@ -12,11 +27,7 @@ pluginManagement {
// makes ~/.gradle/init.gradle unnecessary and ~/.gradle/gradle.properties optional
dependencyResolutionManagement {
// use same version catalog as main build
versionCatalogs {
register("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
versionCatalogs { register("libs") { from(files("../gradle/libs.versions.toml")) } }
repositories {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("MemberVisibilityCanBePrivate")
import java.io.File
@@ -14,13 +29,9 @@ open class BuildInfo(project: Project) {
System.getenv("GRAALVM_HOME") ?: "${System.getProperty("user.home")}/.graalvm"
}
val version: String by lazy {
libs.findVersion("graalVm").get().toString()
}
val version: String by lazy { libs.findVersion("graalVm").get().toString() }
val graalVmJdkVersion: String by lazy {
libs.findVersion("graalVmJdkVersion").get().toString()
}
val graalVmJdkVersion: String by lazy { libs.findVersion("graalVmJdkVersion").get().toString() }
val osName: String by lazy {
when {
@@ -31,9 +42,7 @@ open class BuildInfo(project: Project) {
}
}
val baseName: String by lazy {
"graalvm-jdk-${graalVmJdkVersion}_${osName}-${arch}_bin"
}
val baseName: String by lazy { "graalvm-jdk-${graalVmJdkVersion}_${osName}-${arch}_bin" }
val downloadUrl: String by lazy {
val jdkMajor = graalVmJdkVersion.takeWhile { it != '.' }
@@ -41,18 +50,14 @@ open class BuildInfo(project: Project) {
"https://download.oracle.com/graalvm/$jdkMajor/archive/$baseName.$extension"
}
val installDir: File by lazy {
File(homeDir, baseName)
}
val installDir: File by lazy { File(homeDir, baseName) }
val baseDir: String by lazy {
if (os.isMacOsX) "$installDir/Contents/Home" else installDir.toString()
}
}
/**
* Same logic as [org.gradle.internal.os.OperatingSystem#arch], which is protected.
*/
/** Same logic as [org.gradle.internal.os.OperatingSystem#arch], which is protected. */
val arch: String by lazy {
when (val arch = System.getProperty("os.arch")) {
"x86" -> "i386"
@@ -66,13 +71,9 @@ open class BuildInfo(project: Project) {
val graalVmAmd64: GraalVm = GraalVm("x64")
val isCiBuild: Boolean by lazy {
System.getenv("CI") != null
}
val isCiBuild: Boolean by lazy { System.getenv("CI") != null }
val isReleaseBuild: Boolean by lazy {
java.lang.Boolean.getBoolean("releaseBuild")
}
val isReleaseBuild: Boolean by lazy { java.lang.Boolean.getBoolean("releaseBuild") }
val hasMuslToolchain: Boolean by lazy {
// see "install musl" in .circleci/jobs/BuildNativeJob.pkl
@@ -87,10 +88,11 @@ open class BuildInfo(project: Project) {
val commitId: String by lazy {
// only run command once per build invocation
if (project === project.rootProject) {
val process = ProcessBuilder()
.command("git", "rev-parse", "--short", "HEAD")
.directory(project.rootDir)
.start()
val process =
ProcessBuilder()
.command("git", "rev-parse", "--short", "HEAD")
.directory(project.rootDir)
.start()
process.waitFor().also { exitCode ->
if (exitCode == -1) throw RuntimeException(process.errorStream.reader().readText())
}
@@ -100,9 +102,7 @@ open class BuildInfo(project: Project) {
}
}
val commitish: String by lazy {
if (isReleaseBuild) project.version.toString() else commitId
}
val commitish: String by lazy { if (isReleaseBuild) project.version.toString() else commitId }
val pklVersion: String by lazy {
if (isReleaseBuild) {

View File

@@ -1,39 +1,52 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
/**
* Builds a self-contained Pkl CLI Jar that is directly executable on *nix
* and executable with `java -jar` on Windows.
* Builds a self-contained Pkl CLI Jar that is directly executable on *nix and executable with `java
* -jar` on Windows.
*
* For direct execution, the `java` command must be on the PATH.
*
* https://skife.org/java/unix/2011/06/20/really_executable_jars.html
*/
abstract class ExecutableJar : DefaultTask() {
@get:InputFile
abstract val inJar: RegularFileProperty
@get:InputFile abstract val inJar: RegularFileProperty
@get:OutputFile
abstract val outJar: RegularFileProperty
@get:OutputFile abstract val outJar: RegularFileProperty
@get:Input
abstract val jvmArgs: ListProperty<String>
@get:Input abstract val jvmArgs: ListProperty<String>
@TaskAction
fun buildJar() {
val inFile = inJar.get().asFile
val outFile = outJar.get().asFile
val escapedJvmArgs = jvmArgs.get().joinToString(separator = " ") { "\"$it\"" }
val startScript = """
val startScript =
"""
#!/bin/sh
exec java $escapedJvmArgs -jar $0 "$@"
""".trimIndent() + "\n\n\n"
"""
.trimIndent() + "\n\n\n"
outFile.outputStream().use { outStream ->
startScript.byteInputStream().use { it.copyTo(outStream) }
inFile.inputStream().use { it.copyTo(outStream) }

View File

@@ -1,7 +1,22 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.util.GradleVersion
open class GradlePluginTests {
lateinit var minGradleVersion: GradleVersion
lateinit var maxGradleVersion: GradleVersion
var skippedGradleVersions: List<GradleVersion> = listOf()
}
}

View File

@@ -1,6 +1,21 @@
import org.gradle.util.GradleVersion
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import groovy.json.JsonSlurper
import java.net.URI
import org.gradle.util.GradleVersion
@Suppress("unused")
class GradleVersionInfo(json: Map<String, Any>) {
@@ -38,15 +53,19 @@ class GradleVersionInfo(json: Map<String, Any>) {
val wrapperChecksumUrl: String by json
companion object {
private fun fetchAll(): List<GradleVersionInfo> = fetchMultiple("https://services.gradle.org/versions/all")
private fun fetchAll(): List<GradleVersionInfo> =
fetchMultiple("https://services.gradle.org/versions/all")
fun fetchReleases(): List<GradleVersionInfo> = fetchAll().filter { it.isReleaseVersion }
fun fetchCurrent(): GradleVersionInfo = fetchSingle("https://services.gradle.org/versions/current")
fun fetchCurrent(): GradleVersionInfo =
fetchSingle("https://services.gradle.org/versions/current")
fun fetchRc(): GradleVersionInfo? = fetchSingleOrNull("https://services.gradle.org/versions/release-candidate")
fun fetchRc(): GradleVersionInfo? =
fetchSingleOrNull("https://services.gradle.org/versions/release-candidate")
fun fetchNightly(): GradleVersionInfo = fetchSingle("https://services.gradle.org/versions/nightly")
fun fetchNightly(): GradleVersionInfo =
fetchSingle("https://services.gradle.org/versions/nightly")
private fun fetchSingle(url: String): GradleVersionInfo {
@Suppress("UNCHECKED_CAST")
@@ -61,8 +80,9 @@ class GradleVersionInfo(json: Map<String, Any>) {
private fun fetchMultiple(url: String): List<GradleVersionInfo> {
@Suppress("UNCHECKED_CAST")
return (JsonSlurper().parse(URI(url).toURL()) as List<Map<String, Any>>)
.map { GradleVersionInfo(it) }
return (JsonSlurper().parse(URI(url).toURL()) as List<Map<String, Any>>).map {
GradleVersionInfo(it)
}
}
}
}

View File

@@ -1,6 +1,21 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
open class HtmlValidator(project: Project) {
var sources: FileCollection = project.files()
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -15,21 +30,18 @@ import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.mapProperty
open class MergeSourcesJars : DefaultTask() {
@get:InputFiles
val inputJars: ConfigurableFileCollection = project.objects.fileCollection()
@get:InputFiles val inputJars: ConfigurableFileCollection = project.objects.fileCollection()
@get:InputFiles
val mergedBinaryJars: ConfigurableFileCollection = project.objects.fileCollection()
@get:Input
val relocatedPackages: MapProperty<String, String> = project.objects.mapProperty()
@get:Input val relocatedPackages: MapProperty<String, String> = project.objects.mapProperty()
@get:Input
var sourceFileExtensions: ListProperty<String> = project.objects.listProperty<String>()
.convention(listOf(".java", ".kt"))
var sourceFileExtensions: ListProperty<String> =
project.objects.listProperty<String>().convention(listOf(".java", ".kt"))
@get:OutputFile
val outputJar: RegularFileProperty = project.objects.fileProperty()
@get:OutputFile val outputJar: RegularFileProperty = project.objects.fileProperty()
@TaskAction
@Suppress("unused")
@@ -38,12 +50,15 @@ open class MergeSourcesJars : DefaultTask() {
val relocatedPkgs = relocatedPackages.get()
val relocatedPaths = relocatedPkgs.entries.associate { (key, value) -> toPath(key) to toPath(value) }
val relocatedPaths =
relocatedPkgs.entries.associate { (key, value) -> toPath(key) to toPath(value) }
// use negative lookbehind to match any that don't precede with
// a word or a period character. should catch most cases.
val importPattern = Pattern.compile("(?<!(\\w|\\.))(" +
relocatedPkgs.keys.joinToString("|") { it.replace(".", "\\.") } + ")")
val importPattern =
Pattern.compile(
"(?<!(\\w|\\.))(" + relocatedPkgs.keys.joinToString("|") { it.replace(".", "\\.") } + ")"
)
val sourceFileExts = sourceFileExtensions.get()

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.result.ResolvedArtifactResult
@@ -12,27 +27,29 @@ import org.gradle.kotlin.dsl.property
import org.gradle.language.base.artifact.SourcesArtifact
open class ResolveSourcesJars : DefaultTask() {
@get:InputFiles
val configuration: Property<Configuration> = project.objects.property()
@get:InputFiles val configuration: Property<Configuration> = project.objects.property()
@get:OutputDirectory
val outputDir: DirectoryProperty = project.objects.directoryProperty()
@get:OutputDirectory val outputDir: DirectoryProperty = project.objects.directoryProperty()
@TaskAction
@Suppress("UnstableApiUsage", "unused")
fun resolve() {
val componentIds = configuration.get().incoming.resolutionResult.allDependencies.map {
(it as ResolvedDependencyResult).selected.id
}
val componentIds =
configuration.get().incoming.resolutionResult.allDependencies.map {
(it as ResolvedDependencyResult).selected.id
}
val resolutionResult = project.dependencies.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(JvmLibrary::class.java, SourcesArtifact::class.java)
.execute()
val resolutionResult =
project.dependencies
.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(JvmLibrary::class.java, SourcesArtifact::class.java)
.execute()
val resolvedJars = resolutionResult.resolvedComponents
.flatMap { it.getArtifacts(SourcesArtifact::class.java) }
.map { (it as ResolvedArtifactResult).file }
val resolvedJars =
resolutionResult.resolvedComponents
.flatMap { it.getArtifacts(SourcesArtifact::class.java) }
.map { (it as ResolvedArtifactResult).file }
// copying to an output dir because I don't know how else to describe task outputs
project.sync {

View File

@@ -1,10 +1,27 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.diffplug.gradle.spotless.KotlinGradleExtension
import org.gradle.accessors.dm.LibrariesForLibs
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { id("com.diffplug.spotless") }
val buildInfo = extensions.create<BuildInfo>("buildInfo", project)
dependencyLocking {
lockAllConfigurations()
}
dependencyLocking { lockAllConfigurations() }
configurations {
val rejectedVersionSuffix = Regex("-alpha|-beta|-eap|-m|-rc|-snapshot", RegexOption.IGNORE_CASE)
@@ -13,8 +30,10 @@ configurations {
componentSelection {
all {
if (rejectedVersionSuffix.containsMatchIn(candidate.version)) {
reject("Rejected dependency $candidate " +
"because it has a prelease version suffix matching `$rejectedVersionSuffix`.")
reject(
"Rejected dependency $candidate " +
"because it has a prelease version suffix matching `$rejectedVersionSuffix`."
)
}
}
}
@@ -36,24 +55,13 @@ tasks.withType<KotlinCompile>().configureEach {
}
plugins.withType(IdeaPlugin::class).configureEach {
val errorMessage = "Use IntelliJ Gradle import instead of running the `idea` task. See README for more information."
val errorMessage =
"Use IntelliJ Gradle import instead of running the `idea` task. See README for more information."
tasks.named("idea") {
doFirst {
throw GradleException(errorMessage)
}
}
tasks.named("ideaModule") {
doFirst {
throw GradleException(errorMessage)
}
}
tasks.named("idea") { doFirst { throw GradleException(errorMessage) } }
tasks.named("ideaModule") { doFirst { throw GradleException(errorMessage) } }
if (project == rootProject) {
tasks.named("ideaProject") {
doFirst {
throw GradleException(errorMessage)
}
}
tasks.named("ideaProject") { doFirst { throw GradleException(errorMessage) } }
}
}
@@ -72,11 +80,7 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
// dependency versions in generated POMs
publications {
withType(MavenPublication::class.java) {
versionMapping {
allVariants {
fromResolutionResult()
}
}
versionMapping { allVariants { fromResolutionResult() } }
}
}
}
@@ -84,13 +88,10 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
// settings.gradle.kts sets `--write-locks`
// if Gradle command line contains this task name
val updateDependencyLocks by tasks.registering {
doLast {
configurations
.filter { it.isCanBeResolved }
.forEach { it.resolve() }
val updateDependencyLocks by
tasks.registering {
doLast { configurations.filter { it.isCanBeResolved }.forEach { it.resolve() } }
}
}
val allDependencies by tasks.registering(DependencyReportTask::class)
@@ -118,3 +119,41 @@ tasks.withType(JavaExec::class).configureEach {
server = true
}
}
// Version Catalog library symbols.
private val libs = the<LibrariesForLibs>()
private val licenseHeaderFile by lazy {
rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt")
}
private fun KotlinGradleExtension.configureFormatter() {
ktfmt(libs.versions.ktfmt.get()).googleStyle()
licenseHeaderFile(licenseHeaderFile, "([a-zA-Z]|@file|//)")
}
val originalRemoteName = System.getenv("PKL_ORIGINAL_REMOTE_NAME") ?: "origin"
spotless {
ratchetFrom = "$originalRemoteName/main"
// When building root project, format buildSrc files too.
// We need this because buildSrc is not a subproject of the root project, so a top-level
// `spotlessApply` will not trigger `buildSrc:spotlessApply`.
if (project === rootProject) {
kotlinGradle {
configureFormatter()
target("*.kts", "buildSrc/*.kts", "buildSrc/src/*/kotlin/**/*.kts")
}
kotlin {
ktfmt(libs.versions.ktfmt.get()).googleStyle()
target("buildSrc/src/*/kotlin/**/*.kt")
licenseHeaderFile(licenseHeaderFile)
}
} else {
kotlinGradle {
configureFormatter()
target("*.kts")
}
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.api.GradleException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.component.AdhocComponentWithVariants
@@ -18,41 +33,43 @@ val fatJarConfiguration: Configuration = configurations.create("fatJar")
val fatJarPublication: MavenPublication = publishing.publications.create<MavenPublication>("fatJar")
// ideally we'd configure this automatically based on project dependencies
val firstPartySourcesJarsConfiguration: Configuration = configurations.create("firstPartySourcesJars")
val firstPartySourcesJarsConfiguration: Configuration =
configurations.create("firstPartySourcesJars")
val relocations = mapOf(
// pkl-core dependencies
"org.antlr.v4." to "org.pkl.thirdparty.antlr.v4.",
"com.oracle.truffle" to "org.pkl.thirdparty.truffle",
"org.graalvm." to "org.pkl.thirdparty.graalvm.",
"org.organicdesign.fp." to "org.pkl.thirdparty.paguro.",
"org.snakeyaml.engine." to "org.pkl.thirdparty.snakeyaml.engine.",
"org.msgpack." to "org.pkl.thirdparty.msgpack.",
"org.w3c.dom." to "org.pkl.thirdparty.w3c.dom",
"com.oracle.svm.core." to "org.pkl.thirdparty.svm.",
val relocations =
mapOf(
// pkl-core dependencies
"org.antlr.v4." to "org.pkl.thirdparty.antlr.v4.",
"com.oracle.truffle" to "org.pkl.thirdparty.truffle",
"org.graalvm." to "org.pkl.thirdparty.graalvm.",
"org.organicdesign.fp." to "org.pkl.thirdparty.paguro.",
"org.snakeyaml.engine." to "org.pkl.thirdparty.snakeyaml.engine.",
"org.msgpack." to "org.pkl.thirdparty.msgpack.",
"org.w3c.dom." to "org.pkl.thirdparty.w3c.dom",
"com.oracle.svm.core." to "org.pkl.thirdparty.svm.",
// pkl-cli dependencies
"org.jline." to "org.pkl.thirdparty.jline.",
"com.github.ajalt.clikt." to "org.pkl.thirdparty.clikt.",
"kotlin." to "org.pkl.thirdparty.kotlin.",
"kotlinx." to "org.pkl.thirdparty.kotlinx.",
"org.intellij." to "org.pkl.thirdparty.intellij.",
"org.fusesource.jansi." to "org.pkl.thirdparty.jansi",
"org.fusesource.hawtjni." to "org.pkl.thirdparty.hawtjni",
// pkl-cli dependencies
"org.jline." to "org.pkl.thirdparty.jline.",
"com.github.ajalt.clikt." to "org.pkl.thirdparty.clikt.",
"kotlin." to "org.pkl.thirdparty.kotlin.",
"kotlinx." to "org.pkl.thirdparty.kotlinx.",
"org.intellij." to "org.pkl.thirdparty.intellij.",
"org.fusesource.jansi." to "org.pkl.thirdparty.jansi",
"org.fusesource.hawtjni." to "org.pkl.thirdparty.hawtjni",
// pkl-doc dependencies
"org.commonmark." to "org.pkl.thirdparty.commonmark.",
"org.jetbrains." to "org.pkl.thirdparty.jetbrains.",
// pkl-config-java dependencies
"io.leangen.geantyref." to "org.pkl.thirdparty.geantyref.",
// pkl-doc dependencies
"org.commonmark." to "org.pkl.thirdparty.commonmark.",
"org.jetbrains." to "org.pkl.thirdparty.jetbrains.",
// pkl-codegen-java dependencies
"com.squareup.javapoet." to "org.pkl.thirdparty.javapoet.",
// pkl-config-java dependencies
"io.leangen.geantyref." to "org.pkl.thirdparty.geantyref.",
// pkl-codegen-kotlin dependencies
"com.squareup.kotlinpoet." to "org.pkl.thirdparty.kotlinpoet.",
)
// pkl-codegen-java dependencies
"com.squareup.javapoet." to "org.pkl.thirdparty.javapoet.",
// pkl-codegen-kotlin dependencies
"com.squareup.kotlinpoet." to "org.pkl.thirdparty.kotlinpoet.",
)
val nonRelocations = listOf("com/oracle/truffle/")
@@ -82,82 +99,81 @@ tasks.shadowJar {
// workaround for https://github.com/johnrengelman/shadow/issues/651
components.withType(AdhocComponentWithVariants::class.java).forEach { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) {
skip()
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) { skip() }
}
val testFatJar by
tasks.registering(Test::class) {
testClassesDirs = files(tasks.test.get().testClassesDirs)
classpath =
// compiled test classes
sourceSets.test.get().output +
// fat Jar
tasks.shadowJar.get().outputs.files +
// test-only dependencies
// (test dependencies that are also main dependencies must already be contained in fat Jar;
// to verify that, we don't want to include them here)
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
}
}
val testFatJar by tasks.registering(Test::class) {
testClassesDirs = files(tasks.test.get().testClassesDirs)
classpath =
// compiled test classes
sourceSets.test.get().output +
// fat Jar
tasks.shadowJar.get().outputs.files +
// test-only dependencies
// (test dependencies that are also main dependencies must already be contained in fat Jar;
// to verify that, we don't want to include them here)
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
}
tasks.check { dependsOn(testFatJar) }
tasks.check {
dependsOn(testFatJar)
}
val validateFatJar by
tasks.registering {
val outputFile = layout.buildDirectory.file("validateFatJar/result.txt")
inputs.files(tasks.shadowJar)
inputs.property("nonRelocations", nonRelocations)
outputs.file(outputFile)
val validateFatJar by tasks.registering {
val outputFile = layout.buildDirectory.file("validateFatJar/result.txt")
inputs.files(tasks.shadowJar)
inputs.property("nonRelocations", nonRelocations)
outputs.file(outputFile)
doLast {
val unshadowedFiles = mutableListOf<String>()
zipTree(tasks.shadowJar.get().outputs.files.singleFile).visit {
val fileDetails = this
val path = fileDetails.relativePath.pathString
if (!(fileDetails.isDirectory ||
path.startsWith("org/pkl/") ||
path.startsWith("META-INF/") ||
nonRelocations.any { path.startsWith(it) })) {
// don't throw exception inside `visit`
// as this gives a misleading "Could not expand ZIP" error message
unshadowedFiles.add(path)
doLast {
val unshadowedFiles = mutableListOf<String>()
zipTree(tasks.shadowJar.get().outputs.files.singleFile).visit {
val fileDetails = this
val path = fileDetails.relativePath.pathString
if (
!(fileDetails.isDirectory ||
path.startsWith("org/pkl/") ||
path.startsWith("META-INF/") ||
nonRelocations.any { path.startsWith(it) })
) {
// don't throw exception inside `visit`
// as this gives a misleading "Could not expand ZIP" error message
unshadowedFiles.add(path)
}
}
if (unshadowedFiles.isEmpty()) {
outputFile.get().asFile.writeText("SUCCESS")
} else {
outputFile.get().asFile.writeText("FAILURE")
throw GradleException("Found unshadowed files:\n" + unshadowedFiles.joinToString("\n"))
}
}
if (unshadowedFiles.isEmpty()) {
outputFile.get().asFile.writeText("SUCCESS")
} else {
outputFile.get().asFile.writeText("FAILURE")
throw GradleException("Found unshadowed files:\n" + unshadowedFiles.joinToString("\n"))
}
}
}
tasks.check {
dependsOn(validateFatJar)
}
val resolveSourcesJars by tasks.registering(ResolveSourcesJars::class) {
configuration.set(configurations.runtimeClasspath)
outputDir.set(layout.buildDirectory.dir("resolveSourcesJars"))
}
tasks.check { dependsOn(validateFatJar) }
val fatSourcesJar by tasks.registering(MergeSourcesJars::class) {
plugins.withId("pklJavaLibrary") {
inputJars.from(tasks.named("sourcesJar"))
val resolveSourcesJars by
tasks.registering(ResolveSourcesJars::class) {
configuration.set(configurations.runtimeClasspath)
outputDir.set(layout.buildDirectory.dir("resolveSourcesJars"))
}
inputJars.from(firstPartySourcesJarsConfiguration)
inputJars.from(resolveSourcesJars.map { fileTree(it.outputDir) })
mergedBinaryJars.from(tasks.shadowJar)
relocatedPackages.set(relocations)
outputJar.fileProvider(provider {
file(tasks.shadowJar.get().archiveFile.get().asFile.path.replace(".jar", "-sources.jar"))
})
}
val fatSourcesJar by
tasks.registering(MergeSourcesJars::class) {
plugins.withId("pklJavaLibrary") { inputJars.from(tasks.named("sourcesJar")) }
inputJars.from(firstPartySourcesJarsConfiguration)
inputJars.from(resolveSourcesJars.map { fileTree(it.outputDir) })
artifacts {
add("fatJar", tasks.shadowJar)
}
mergedBinaryJars.from(tasks.shadowJar)
relocatedPackages.set(relocations)
outputJar.fileProvider(
provider {
file(tasks.shadowJar.get().archiveFile.get().asFile.path.replace(".jar", "-sources.jar"))
}
)
}
artifacts { add("fatJar", tasks.shadowJar) }
publishing {
publications {
@@ -165,16 +181,12 @@ publishing {
project.shadow.component(this)
// sources Jar is fat
artifact(fatSourcesJar.flatMap { it.outputJar.asFile }) {
classifier = "sources"
}
artifact(fatSourcesJar.flatMap { it.outputJar.asFile }) { classifier = "sources" }
plugins.withId("pklJavaLibrary") {
val javadocJar by tasks.existing(Jar::class)
// Javadoc Jar is not fat (didn't invest effort)
artifact(javadocJar.flatMap { it.archiveFile }) {
classifier = "javadoc"
}
artifact(javadocJar.flatMap { it.archiveFile }) { classifier = "javadoc" }
}
}
}

View File

@@ -1,36 +1,44 @@
import java.nio.file.*
import java.util.UUID
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
import java.nio.file.*
import java.util.UUID
import kotlin.io.path.createDirectories
plugins {
id("de.undercouch.download")
}
plugins { id("de.undercouch.download") }
val buildInfo = project.extensions.getByType<BuildInfo>()
val BuildInfo.GraalVm.downloadFile get(): File {
val extension = if (buildInfo.os.isWindows) "zip" else "tar.gz"
return file(homeDir).resolve("${baseName}.$extension")
}
val BuildInfo.GraalVm.downloadFile
get(): File {
val extension = if (buildInfo.os.isWindows) "zip" else "tar.gz"
return file(homeDir).resolve("${baseName}.$extension")
}
// tries to minimize chance of corruption by download-to-temp-file-and-move
val downloadGraalVmAarch64 by tasks.registering(Download::class) {
configureDownloadGraalVm(buildInfo.graalVmAarch64)
}
val downloadGraalVmAarch64 by
tasks.registering(Download::class) { configureDownloadGraalVm(buildInfo.graalVmAarch64) }
val downloadGraalVmAmd64 by tasks.registering(Download::class) {
configureDownloadGraalVm(buildInfo.graalVmAmd64)
}
val downloadGraalVmAmd64 by
tasks.registering(Download::class) { configureDownloadGraalVm(buildInfo.graalVmAmd64) }
fun Download.configureDownloadGraalVm(graalvm: BuildInfo.GraalVm) {
onlyIf {
!graalvm.installDir.exists()
}
doLast {
println("Downloaded GraalVm to ${graalvm.downloadFile}")
}
onlyIf { !graalvm.installDir.exists() }
doLast { println("Downloaded GraalVm to ${graalvm.downloadFile}") }
src(graalvm.downloadUrl)
dest(graalvm.downloadFile)
@@ -38,42 +46,44 @@ fun Download.configureDownloadGraalVm(graalvm: BuildInfo.GraalVm) {
tempAndMove(true)
}
val verifyGraalVmAarch64 by tasks.registering(Verify::class) {
configureVerifyGraalVm(buildInfo.graalVmAarch64)
dependsOn(downloadGraalVmAarch64)
}
val verifyGraalVmAmd64 by tasks.registering(Verify::class) {
configureVerifyGraalVm(buildInfo.graalVmAmd64)
dependsOn(downloadGraalVmAmd64)
}
fun Verify.configureVerifyGraalVm(graalvm: BuildInfo.GraalVm) {
onlyIf {
!graalvm.installDir.exists()
val verifyGraalVmAarch64 by
tasks.registering(Verify::class) {
configureVerifyGraalVm(buildInfo.graalVmAarch64)
dependsOn(downloadGraalVmAarch64)
}
val verifyGraalVmAmd64 by
tasks.registering(Verify::class) {
configureVerifyGraalVm(buildInfo.graalVmAmd64)
dependsOn(downloadGraalVmAmd64)
}
fun Verify.configureVerifyGraalVm(graalvm: BuildInfo.GraalVm) {
onlyIf { !graalvm.installDir.exists() }
src(graalvm.downloadFile)
checksum(buildInfo.libs.findVersion("graalVmSha256-${graalvm.osName}-${graalvm.arch}").get().toString())
checksum(
buildInfo.libs.findVersion("graalVmSha256-${graalvm.osName}-${graalvm.arch}").get().toString()
)
algorithm("SHA-256")
}
// minimize chance of corruption by extract-to-random-dir-and-flip-symlink
val installGraalVmAarch64 by tasks.registering {
dependsOn(verifyGraalVmAarch64)
configureInstallGraalVm(buildInfo.graalVmAarch64)
}
val installGraalVmAarch64 by
tasks.registering {
dependsOn(verifyGraalVmAarch64)
configureInstallGraalVm(buildInfo.graalVmAarch64)
}
// minimize chance of corruption by extract-to-random-dir-and-flip-symlink
val installGraalVmAmd64 by tasks.registering {
dependsOn(verifyGraalVmAmd64)
configureInstallGraalVm(buildInfo.graalVmAmd64)
}
val installGraalVmAmd64 by
tasks.registering {
dependsOn(verifyGraalVmAmd64)
configureInstallGraalVm(buildInfo.graalVmAmd64)
}
fun Task.configureInstallGraalVm(graalVm: BuildInfo.GraalVm) {
onlyIf {
!graalVm.installDir.exists()
}
onlyIf { !graalVm.installDir.exists() }
doLast {
val distroDir = Paths.get(graalVm.homeDir, UUID.randomUUID().toString())
@@ -88,7 +98,9 @@ fun Task.configureInstallGraalVm(graalVm: BuildInfo.GraalVm) {
args("--strip-components=1", "-xzf", graalVm.downloadFile)
}
val distroBinDir = if (buildInfo.os.isMacOsX) distroDir.resolve("Contents/Home/bin") else distroDir.resolve("bin")
val distroBinDir =
if (buildInfo.os.isMacOsX) distroDir.resolve("Contents/Home/bin")
else distroDir.resolve("bin")
println("Installing native-image into $distroDir")
exec {
@@ -103,11 +115,15 @@ fun Task.configureInstallGraalVm(graalVm: BuildInfo.GraalVm) {
try {
Files.move(tempLink, graalVm.installDir.toPath(), StandardCopyOption.ATOMIC_MOVE)
} catch (e: Exception) {
try { delete(tempLink.toFile()) } catch (ignored: Exception) {}
try {
delete(tempLink.toFile())
} catch (ignored: Exception) {}
throw e
}
} catch (e: Exception) {
try { delete(distroDir) } catch (ignored: Exception) {}
try {
delete(distroDir)
} catch (ignored: Exception) {}
throw e
}
}

View File

@@ -1,19 +1,19 @@
/**
* Allows to run Gradle plugin tests against different Gradle versions.
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Adds a `compatibilityTestX` task for every Gradle version X
* between `ext.minSupportedGradleVersion` and `ext.maxSupportedGradleVersion`
* that is not in `ext.gradleVersionsExcludedFromTesting`.
* The list of available Gradle versions is obtained from services.gradle.org.
* Adds lifecycle tasks to test against multiple Gradle versions at once, for example all Gradle release versions.
* Compatibility test tasks run the same tests and use the same task configuration as the project's `test` task.
* They set system properties for the Gradle version and distribution URL to be used.
* These properties are consumed by the `AbstractTest` class.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
java
}
plugins { java }
val gradlePluginTests = extensions.create<GradlePluginTests>("gradlePluginTests")
@@ -24,18 +24,23 @@ tasks.addRule("Pattern: compatibilityTest[All|Releases|Latest|Candidate|Nightly|
when (val taskNameSuffix = matchResult.groupValues[1]) {
"All" ->
task("compatibilityTestAll") {
dependsOn("compatibilityTestReleases", "compatibilityTestCandidate", "compatibilityTestNightly")
dependsOn(
"compatibilityTestReleases",
"compatibilityTestCandidate",
"compatibilityTestNightly"
)
}
// releases in configured range
"Releases" ->
task("compatibilityTestReleases") {
val versionInfos = GradleVersionInfo.fetchReleases()
val versionsToTestAgainst = versionInfos.filter { versionInfo ->
val v = versionInfo.gradleVersion
!versionInfo.broken &&
val versionsToTestAgainst =
versionInfos.filter { versionInfo ->
val v = versionInfo.gradleVersion
!versionInfo.broken &&
v in gradlePluginTests.minGradleVersion..gradlePluginTests.maxGradleVersion &&
v !in gradlePluginTests.skippedGradleVersions
}
}
dependsOn(versionsToTestAgainst.map { createCompatibilityTestTask(it) })
}
@@ -45,8 +50,10 @@ tasks.addRule("Pattern: compatibilityTest[All|Releases|Latest|Candidate|Nightly|
val versionInfo = GradleVersionInfo.fetchCurrent()
if (versionInfo.version == gradle.gradleVersion) {
doLast {
println("No new Gradle release available. " +
"(Run `gradlew test` to test against ${versionInfo.version}.)")
println(
"No new Gradle release available. " +
"(Run `gradlew test` to test against ${versionInfo.version}.)"
)
}
} else {
dependsOn(createCompatibilityTestTask(versionInfo))
@@ -59,9 +66,7 @@ tasks.addRule("Pattern: compatibilityTest[All|Releases|Latest|Candidate|Nightly|
if (versionInfo?.activeRc == true) {
dependsOn(createCompatibilityTestTask(versionInfo))
} else {
doLast {
println("No active Gradle release candidate available.")
}
doLast { println("No active Gradle release candidate available.") }
}
}
// latest nightly
@@ -73,14 +78,14 @@ tasks.addRule("Pattern: compatibilityTest[All|Releases|Latest|Candidate|Nightly|
// explicit version
else ->
createCompatibilityTestTask(
taskNameSuffix,
"https://services.gradle.org/distributions-snapshots/gradle-$taskNameSuffix-bin.zip"
taskNameSuffix,
"https://services.gradle.org/distributions-snapshots/gradle-$taskNameSuffix-bin.zip"
)
}
}
fun createCompatibilityTestTask(versionInfo: GradleVersionInfo): Task =
createCompatibilityTestTask(versionInfo.version, versionInfo.downloadUrl)
createCompatibilityTestTask(versionInfo.version, versionInfo.downloadUrl)
fun createCompatibilityTestTask(version: String, downloadUrl: String): Task {
return tasks.create("compatibilityTest$version", Test::class.java) {

View File

@@ -1,20 +1,33 @@
plugins {
base
}
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins { base }
val htmlValidator = extensions.create<HtmlValidator>("htmlValidator", project)
val buildInfo = project.extensions.getByType<BuildInfo>()
val validatorConfiguration: Configuration = configurations.create("validator") {
resolutionStrategy.eachDependency {
if (requested.group == "log4j" && requested.name == "log4j") {
@Suppress("UnstableApiUsage")
useTarget(buildInfo.libs.findLibrary("log4j12Api").get())
because("mitigate critical security vulnerabilities")
val validatorConfiguration: Configuration =
configurations.create("validator") {
resolutionStrategy.eachDependency {
if (requested.group == "log4j" && requested.name == "log4j") {
@Suppress("UnstableApiUsage") useTarget(buildInfo.libs.findLibrary("log4j12Api").get())
because("mitigate critical security vulnerabilities")
}
}
}
}
dependencies {
@Suppress("UnstableApiUsage")
@@ -32,27 +45,29 @@ dependencies {
}
}
val validateHtml by tasks.registering(JavaExec::class) {
val resultFile = layout.buildDirectory.file("validateHtml/result.txt")
inputs.files(htmlValidator.sources)
outputs.file(resultFile)
val validateHtml by
tasks.registering(JavaExec::class) {
val resultFile = layout.buildDirectory.file("validateHtml/result.txt")
inputs.files(htmlValidator.sources)
outputs.file(resultFile)
classpath = validatorConfiguration
mainClass.set("nu.validator.client.SimpleCommandLineValidator")
args("--skip-non-html") // --also-check-css doesn't work (still checks css as html), so limit to html files
args("--filterpattern", "(.*)Consider adding “lang=(.*)")
args("--filterpattern", "(.*)Consider adding a “lang” attribute(.*)")
args("--filterpattern", "(.*)unrecognized media “amzn-kf8”(.*)") // kindle
// for debugging
// args "--verbose"
args(htmlValidator.sources)
classpath = validatorConfiguration
mainClass.set("nu.validator.client.SimpleCommandLineValidator")
args(
"--skip-non-html"
) // --also-check-css doesn't work (still checks css as html), so limit to html files
args("--filterpattern", "(.*)Consider adding “lang=(.*)")
args("--filterpattern", "(.*)Consider adding a “lang” attribute(.*)")
args("--filterpattern", "(.*)unrecognized media “amzn-kf8”(.*)") // kindle
// for debugging
// args "--verbose"
args(htmlValidator.sources)
// write a basic result file s.t. gradle can consider task up-to-date
// writing a result file in case validation fails is not easily possible with JavaExec, but also not strictly necessary
doFirst { project.delete(resultFile) }
doLast { resultFile.get().asFile.writeText("Success.") }
}
// write a basic result file s.t. gradle can consider task up-to-date
// writing a result file in case validation fails is not easily possible with JavaExec, but also
// not strictly necessary
doFirst { project.delete(resultFile) }
doLast { resultFile.get().asFile.writeText("Success.") }
}
tasks.check {
dependsOn(validateHtml)
}
tasks.check { dependsOn(validateHtml) }

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("HttpUrlsUsage")
import org.gradle.accessors.dm.LibrariesForLibs
@@ -27,14 +42,17 @@ artifacts {
spotless {
java {
googleJavaFormat(libs.versions.googleJavaFormat.get())
targetExclude("**/generated/**", "**/build/**")
target("src/*/java/**/*.java")
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
}
kotlin {
ktfmt(libs.versions.ktfmt.get()).googleStyle()
target("src/*/kotlin/**/*.kt")
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
}
}
tasks.compileKotlin {
enabled = false
}
tasks.compileKotlin { enabled = false }
tasks.jar {
manifest {
@@ -49,15 +67,18 @@ tasks.javadoc {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
val workAroundKotlinGradlePluginBug by tasks.registering {
doLast {
// Works around this problem, which sporadically appears and disappears in different subprojects:
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type 'JavaCompile').
// > Directory '[...]/pkl/pkl-executor/build/classes/kotlin/main'
// specified for property 'compileKotlinOutputClasses' does not exist.
layout.buildDirectory.dir("classes/kotlin/main").get().asFile.mkdirs()
val workAroundKotlinGradlePluginBug by
tasks.registering {
doLast {
// Works around this problem, which sporadically appears and disappears in different
// subprojects:
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type
// 'JavaCompile').
// > Directory '[...]/pkl/pkl-executor/build/classes/kotlin/main'
// specified for property 'compileKotlinOutputClasses' does not exist.
layout.buildDirectory.dir("classes/kotlin/main").get().asFile.mkdirs()
}
}
}
tasks.compileJava {
dependsOn(workAroundKotlinGradlePluginBug)

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.accessors.dm.LibrariesForLibs
plugins {
@@ -23,11 +38,3 @@ dependencies {
tasks.compileKotlin {
enabled = true // disabled by pklJavaLibrary
}
spotless {
kotlin {
ktfmt(libs.versions.ktfmt.get()).googleStyle()
targetExclude("**/generated/**", "**/build/**")
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
}
}

View File

@@ -1,9 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.URI
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
kotlin("jvm")
}
plugins { kotlin("jvm") }
val buildInfo = project.extensions.getByType<BuildInfo>()
@@ -24,34 +37,36 @@ tasks.withType<Test>().configureEach {
// enable checking of stdlib return types
systemProperty("org.pkl.testMode", "true")
reports.named("html") {
enabled = true
}
reports.named("html") { enabled = true }
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
testLogging { exceptionFormat = TestExceptionFormat.FULL }
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {}
addTestListener(
object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
// print report link at end of task, not just at end of build
override fun afterSuite(descriptor: TestDescriptor, result: TestResult) {
if (descriptor.parent != null) return // only interested in overall result
override fun beforeTest(testDescriptor: TestDescriptor) {}
if (result.resultType == TestResult.ResultType.FAILURE) {
println("\nThere were failing tests. See the report at: ${fixFileUri(testTask.reports.html.entryPoint.toURI())}")
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {}
// print report link at end of task, not just at end of build
override fun afterSuite(descriptor: TestDescriptor, result: TestResult) {
if (descriptor.parent != null) return // only interested in overall result
if (result.resultType == TestResult.ResultType.FAILURE) {
println(
"\nThere were failing tests. See the report at: ${fixFileUri(testTask.reports.html.entryPoint.toURI())}"
)
}
}
// makes links clickable on macOS
private fun fixFileUri(uri: URI): URI {
if ("file" == uri.scheme && !uri.schemeSpecificPart.startsWith("//")) {
return URI.create("file://" + uri.schemeSpecificPart)
}
return uri
}
}
// makes links clickable on macOS
private fun fixFileUri(uri: URI): URI {
if ("file" == uri.scheme && !uri.schemeSpecificPart.startsWith("//")) {
return URI.create("file://" + uri.schemeSpecificPart)
}
return uri
}
})
)
}

View File

@@ -1,11 +1,22 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
val assembleNative by tasks.registering {}
val testNative by tasks.registering {}
val checkNative by tasks.registering {
dependsOn(testNative)
}
val checkNative by tasks.registering { dependsOn(testNative) }
val buildNative by tasks.registering {
dependsOn(assembleNative, checkNative)
}
val buildNative by tasks.registering { dependsOn(assembleNative, checkNative) }

View File

@@ -1,6 +1,21 @@
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.nio.charset.StandardCharsets
import java.util.Base64
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
plugins {
`maven-publish`
@@ -10,9 +25,7 @@ plugins {
publishing {
publications {
components.findByName("java")?.let { javaComponent ->
create<MavenPublication>("library") {
from(javaComponent)
}
create<MavenPublication>("library") { from(javaComponent) }
}
withType<MavenPublication>().configureEach {
pom {
@@ -49,63 +62,66 @@ publishing {
}
}
val validatePom by tasks.registering {
if (tasks.findByName("generatePomFileForLibraryPublication") == null) {
return@registering
}
val generatePomFileForLibraryPublication by tasks.existing(GenerateMavenPom::class)
val outputFile = layout.buildDirectory.file("validatePom") // dummy output to satisfy up-to-date check
val validatePom by
tasks.registering {
if (tasks.findByName("generatePomFileForLibraryPublication") == null) {
return@registering
}
val generatePomFileForLibraryPublication by tasks.existing(GenerateMavenPom::class)
val outputFile =
layout.buildDirectory.file("validatePom") // dummy output to satisfy up-to-date check
dependsOn(generatePomFileForLibraryPublication)
inputs.file(generatePomFileForLibraryPublication.get().destination)
outputs.file(outputFile)
dependsOn(generatePomFileForLibraryPublication)
inputs.file(generatePomFileForLibraryPublication.get().destination)
outputs.file(outputFile)
doLast {
outputFile.get().asFile.delete()
doLast {
outputFile.get().asFile.delete()
val pomFile = generatePomFileForLibraryPublication.get().destination
assert(pomFile.exists())
val pomFile = generatePomFileForLibraryPublication.get().destination
assert(pomFile.exists())
val text = pomFile.readText()
val text = pomFile.readText()
run {
val unresolvedVersion = Regex("<version>.*[+,()\\[\\]].*</version>")
val matches = unresolvedVersion.findAll(text).toList()
if (matches.isNotEmpty()) {
throw GradleException(
"""
run {
val unresolvedVersion = Regex("<version>.*[+,()\\[\\]].*</version>")
val matches = unresolvedVersion.findAll(text).toList()
if (matches.isNotEmpty()) {
throw GradleException(
"""
Found unresolved version selector(s) in generated POM:
${matches.joinToString("\n") { it.groupValues[0] }}
""".trimIndent()
)
"""
.trimIndent()
)
}
}
}
val buildInfo = project.extensions.getByType<BuildInfo>()
if (buildInfo.isReleaseBuild) {
val snapshotVersion = Regex("<version>.*-SNAPSHOT</version>")
val matches = snapshotVersion.findAll(text).toList()
if (matches.isNotEmpty()) {
throw GradleException(
"""
val buildInfo = project.extensions.getByType<BuildInfo>()
if (buildInfo.isReleaseBuild) {
val snapshotVersion = Regex("<version>.*-SNAPSHOT</version>")
val matches = snapshotVersion.findAll(text).toList()
if (matches.isNotEmpty()) {
throw GradleException(
"""
Found snapshot version(s) in generated POM of Pkl release version:
${matches.joinToString("\n") { it.groupValues[0] }}
""".trimIndent()
)
"""
.trimIndent()
)
}
}
outputFile.get().asFile.writeText("OK")
}
outputFile.get().asFile.writeText("OK")
}
}
tasks.publish {
dependsOn(validatePom)
}
tasks.publish { dependsOn(validatePom) }
// Workaround for maven publish plugin not setting up dependencies correctly.
// Taken from https://github.com/gradle/gradle/issues/26091#issuecomment-1798137734
val dependsOnTasks = mutableListOf<String>()
tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOnTasks.add(name.replace("publish", "sign").replaceAfter("Publication", ""))
dependsOn(dependsOnTasks)
@@ -114,8 +130,10 @@ tasks.withType<AbstractPublishToMaven>().configureEach {
signing {
// provided as env vars `ORG_GRADLE_PROJECT_signingKey` and `ORG_GRADLE_PROJECT_signingPassword`
// in CI.
val signingKey = (findProperty("signingKey") as String?)
?.let { Base64.getDecoder().decode(it).toString(StandardCharsets.US_ASCII) }
val signingKey =
(findProperty("signingKey") as String?)?.let {
Base64.getDecoder().decode(it).toString(StandardCharsets.US_ASCII)
}
val signingPassword = findProperty("signingPassword") as String?
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)

View File

@@ -1,5 +1,5 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
// Copyright © $YEAR Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/**
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
/*
* Copyright © $YEAR Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,6 +1,6 @@
name: main
title: Main Project
version: 0.26.0-dev
prerelease: true
version: 0.27.2
prerelease: false
nav:
- nav.adoc

View File

@@ -1,3 +1,18 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
plugins {
@@ -12,10 +27,7 @@ sourceSets {
srcDir(file("modules/pkl-config-java/examples"))
srcDir(file("modules/java-binding/examples"))
}
val kotlin = project.extensions
.getByType<KotlinJvmProjectExtension>()
.sourceSets[name]
.kotlin
val kotlin = project.extensions.getByType<KotlinJvmProjectExtension>().sourceSets[name].kotlin
kotlin.srcDir(file("modules/kotlin-binding/examples"))
}
}
@@ -30,7 +42,8 @@ dependencies {
}
tasks.test {
inputs.files(fileTree("modules").matching {
include("**/pages/*.adoc")
}).withPropertyName("asciiDocFiles").withPathSensitivity(PathSensitivity.RELATIVE)
inputs
.files(fileTree("modules").matching { include("**/pages/*.adoc") })
.withPropertyName("asciiDocFiles")
.withPathSensitivity(PathSensitivity.RELATIVE)
}

View File

@@ -2,13 +2,13 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.tunnelvisionlabs:antlr4-runtime:4.9.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.leangen.geantyref:geantyref:1.3.15=testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.18=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:23.0.2=testRuntimeClasspath
org.graalvm.truffle:truffle-api:23.0.2=testRuntimeClasspath
org.assertj:assertj-core:3.26.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:23.0.6=testRuntimeClasspath
org.graalvm.truffle:truffle-api:23.0.6=testRuntimeClasspath
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
@@ -24,13 +24,14 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=testCompileClasspath,testImplemen
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains:annotations:13.0=kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.msgpack:msgpack-core:0.9.8=testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.organicdesign:Paguro:3.10.3=testRuntimeClasspath
org.snakeyaml:snakeyaml-engine:2.5=testRuntimeClasspath
empty=annotationProcessor,apiDependenciesMetadata,archives,compile,compileClasspath,compileOnly,compileOnlyDependenciesMetadata,default,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeClasspath,runtimeOnlyDependenciesMetadata,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
empty=annotationProcessor,apiDependenciesMetadata,compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtimeClasspath,runtimeOnlyDependenciesMetadata,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions

View File

@@ -3,10 +3,10 @@
// the following attributes must be updated immediately before a release
// pkl version corresponding to current git commit without -dev suffix or git hash
:pkl-version-no-suffix: 0.26.0
:pkl-version-no-suffix: 0.27.2
// tells whether pkl version corresponding to current git commit
// is a release version (:is-release-version: '') or dev version (:!is-release-version:)
:!is-release-version:
:is-release-version: ''
// the remaining attributes do not need to be updated regularly
@@ -68,15 +68,18 @@ endif::[]
:uri-pkldoc-example: {uri-pkl-examples-tree}/pkldoc
:uri-stdlib-baseModule: {uri-pkl-stdlib-docs}/base
:uri-stdlib-analyzeModule: {uri-pkl-stdlib-docs}/analyze
:uri-stdlib-jsonnetModule: {uri-pkl-stdlib-docs}/jsonnet
:uri-stdlib-reflectModule: {uri-pkl-stdlib-docs}/reflect
:uri-stdlib-xmlModule: {uri-pkl-stdlib-docs}/xml
:uri-stdlib-protobufModule: {uri-pkl-stdlib-docs}/protobuf
:uri-stdlib-evaluatorSettingsModule: {uri-pkl-stdlib-docs}/EvaluatorSettings
:uri-stdlib-Boolean: {uri-stdlib-baseModule}/Boolean
:uri-stdlib-xor: {uri-stdlib-baseModule}/Boolean#xor()
:uri-stdlib-implies: {uri-stdlib-baseModule}/Boolean#implies()
:uri-stdlib-Any: {uri-stdlib-baseModule}/Any
:uri-stdlib-String: {uri-stdlib-baseModule}/String
:uri-stdlib-StringToInt: {uri-stdlib-baseModule}/String#toInt()
:uri-stdlib-Int: {uri-stdlib-baseModule}/Int
:uri-stdlib-Float: {uri-stdlib-baseModule}/Float
:uri-stdlib-Number: {uri-stdlib-baseModule}/Number

View File

@@ -9,8 +9,8 @@ The first element of the array is a code that designates the message's type, enc
The second element of the array is the message body, encoded as a map.
Messages are passed between the _client_ and the _server_.
The _client_ is the host language (for example, the Swift application when using pkl-swift).
The _server_ is the entity that provides controls for interacting with Pkl.
When hosting Pkl (for example, the Swift application when using pkl-swift), the _client_ is the host program and the _server_ is the entity that provides controls for interacting with Pkl.
When implementing an xref:language-reference:index.adoc#external-readers[external reader], the _client_ is the external reader process and the _server_ is the Pkl evaluator.
For example, in JSON representation:
@@ -414,6 +414,8 @@ The response to <<read-resource-request>>.
If successful, `contents` is set.
Otherwise, `error` is set.
If neither is set, `contents` defaults to an empty byte array.
[source,pkl]
----
/// A number identifying this request.
@@ -463,6 +465,8 @@ The response to <<read-module-request>>.
If successful, `contents` is set.
Otherwise, `error` is set.
If neither is set, `contents` defaults to an empty string.
[source,pkl]
----
/// A number identifying this request.
@@ -593,3 +597,96 @@ class PathElement {
isDirectory: Boolean
}
----
[[initialize-module-reader-request]]
=== Initialize Module Reader Request
Code: `0x2e` +
Type: <<server-message,Server>> <<request-message,Request>>
Initialize an xref:language-reference:index.adoc#external-readers[External Module Reader].
This message is sent to external reader processes the first time a module scheme it is registered for is read.
[source,pkl]
----
/// A number identifying this request.
requestId: Int
/// The module scheme to initialize.
scheme: String
----
[[initialize-module-reader-response]]
=== Initialize Module Reader Response
Code: `0x2f` +
Type: <<client-message,Client>> <<response-message,Response>>
Return the requested external module reader specification.
The `spec` field should be set to `null` when the external process does not implement the requested module scheme.
[source,pkl]
----
/// A number identifying this request.
requestId: Int
/// Client-side module reader spec.
///
/// Null when the external process does not implement the requested module scheme.
spec: ClientModuleReader?
----
`ClientModuleReader` is defined above by <<create-evaluator-request,Create Evaluator Request>>.
[[initialize-resource-reader-request]]
=== Initialize Resource Reader Request
Code: `0x30` +
Type: <<server-message,Server>> <<request-message,Request>>
Initialize an xref:language-reference:index.adoc#external-readers[External Resource Reader].
This message is sent to external reader processes the first time a resource scheme it is registered for is read.
[source,pkl]
----
/// A number identifying this request.
requestId: Int
/// The resource scheme to initialize.
scheme: String
----
[[initialize-resource-reader-response]]
=== Initialize Resource Reader Response
Code: `0x31` +
Type: <<client-message,Client>> <<response-message,Response>>
Return the requested external resource reader specification.
The `spec` field should be set to `null` when the external process does not implement the requested resource scheme.
[source,pkl]
----
/// A number identifying this request.
requestId: Int
/// Client-side resource reader spec.
///
/// Null when the external process does not implement the requested resource scheme.
spec: ClientResourceReader?
----
`ClientResourceReader` is defined above by <<create-evaluator-request,Create Evaluator Request>>.
[[close-external-process]]
=== Close External Process
Code: `0x32` +
Type: <<server-message,Server>> <<one-way-message,One Way>>
Initiate graceful shutdown of the external reader process.
[source,pkl]
----
/// This message has no properties.
----

View File

@@ -915,6 +915,7 @@ pigeon = new Dynamic { // <1>
==== Hidden Properties
A property with the modifier `hidden` is omitted from the rendered output and object conversions.
Hidden properties are also ignored when evaluating equality or hashing (e.g. for `Mapping` or `Map` keys).
[source,{pkl}]
----
@@ -933,12 +934,19 @@ pigeon = new Bird { // <3>
pigeonInIndex = pigeon.nameAndLifespanInIndex // <4>
pigeonDynamic = pigeon.toDynamic() // <5>
favoritePigeon = (pigeon) {
nameAndLifespanInIndex = "Bettie, \(lifespan)"
}
samePigeon = pigeon == favoritePigeon // <6>
----
<1> Properties defined as `hidden` are accessible on any `Bird` instance, but not output by default.
<2> Non-hidden properties can refer to hidden properties as usual.
<3> `pigeon` is an object with _four_ properties, but is rendered with _three_ properties.
<4> Accessing a `hidden` property from outside the class and object is like any other property.
<5> Object conversions omit hidden properties, so the resulting `Dynamic` has three properties.
<6> Objects that differ only in `hidden` property values are considered equal
Invoking Pkl on this file produces the following result.
@@ -955,6 +963,12 @@ pigeonDynamic {
lifespan = 8
nameSignWidth = 9
}
favoritePigeon {
name = "Pigeon"
lifespan = 8
nameSignWidth = 9
}
samePigeon = true
----
==== Local properties
@@ -1992,7 +2006,8 @@ pigeon: ParentBird = new {
[[methods]]
== Methods
Modules and classes can define methods.
Pkl methods can be defined on classes and modules using the `function` keyword.
Methods may access properties of their containing type.
Submodules and subclasses can override them.
Like Java and most other object-oriented languages, Pkl uses _single dispatch_ -- methods are dynamically dispatched based on the receiver's runtime type.
@@ -2021,6 +2036,12 @@ greeting2 = greetPigeon(parrot) // <4>
<3> Call instance method on `pigeon`.
<4> Call module method (on `this`).
NOTE: Methods do not support named parameters or default parameter values.
The xref:blog:ROOT:class-as-a-function.adoc[Class-as-a-function] pattern may be a suitable replacement.
TIP: In most cases, methods without parameters should not be defined.
Instead, use <<fixed-properties,`fixed` properties>> on the module or class.
[[modules]]
== Modules
@@ -3156,6 +3177,7 @@ pkl: TRACE: num1 * num2 = 672 (at file:///some/module.pkl, line 42)
This section discusses language features that are generally more relevant to template and library authors than template consumers.
<<meaning-of-new,Meaning of `new`>> +
<<let-expressions,Let Expressions>> +
<<type-tests,Type Tests>> +
<<type-casts,Type Casts>> +
@@ -3177,7 +3199,164 @@ This section discusses language features that are generally more relevant to tem
<<grammar-definition,Grammar Definition>> +
<<reserved-keywords,Reserved Keywords>> +
<<blank-identifiers,Blank Identifiers>> +
<<projects,Projects>>
<<projects,Projects>> +
<<external-readers,External Readers>>
[[meaning-of-new]]
=== Meaning of `new`
Objects in Pkl always <<amending-objects, amends>> _some_ value.
The `new` keyword is a special case of amending where a contextual value is amended.
In Pkl, there are two forms of `new` objects:
* `new` with explicit type information, for example, `new Foo {}`.
* `new` without type information, for example, `new {}`.
==== Type defaults
To understand instantiation cases without explicit parent or type information, it's important to first understand implicit default values.
When a property is declared in a module or class but is not provided an explicit default value, the property's default value becomes the type's default value.
Similarly, when `Listing` and `Mapping` types are declared with explicit type arguments for their element or value, their `default` property amends that declared type.
When `Listing` and `Mapping` types are declared without type arguments, their `default` property amends an empty `Dynamic` object.
Some types, including `Pair` and primitives like `String`, `Number`, and `Boolean` have no default value; attempting to render such a property results in the error "Tried to read property `<name>` but its value is undefined".
[source,{pkl}]
----
class Bird {
name: String = "polly"
}
bird: Bird // <1>
birdListing: Listing<Bird> // <2>
birdMapping: Mapping<String, Bird> // <3>
----
<1> Without an explicit default value, this property has default value `new Bird { name = "polly" }`
<2> With an explicit element type argument, this property's default value is equivalent to `new Listing<Bird> { default = (_) -> new Bird { name = "polly" } }`
<3> With an explicit value type argument, this property's default value is equivalent to `new Mapping<String, Bird> { default = (_) -> new Bird { name = "polly" } }`
==== Explicitly Typed `new`
Instantiating an object with `new <type>` results in a value that amends the specified type's default value.
Notably, creating a `Listing` element or assigning a `Mapping` entry value with an explicitly typed `new` ignores the object's `default` value.
[source,{pkl}]
----
class Bird {
/// The name of the bird
name: String
/// Whether this is a bird of prey or not.
isPredatory: Boolean?
}
newProperty = new Bird { // <1>
name = "Warbler"
}
someListing = new Listing<Bird> {
default {
isPredatory = true
}
new Bird { // <2>
name = "Sand Piper"
}
}
someMapping = new Mapping<String, Bird> {
default {
isPredatory = true
}
["Penguin"] = new Bird { // <3>
name = "Penguin"
}
}
----
<1> Assigning a `new` explicitly-typed value to a property.
<2> Adding an `new` explicitly-typed `Listing` element.
The value will not have property `isPredatory = true` as the `default` property of the `Listing` is not used.
<3> Assigning a `new` explicitly-typed value to a `Mapping` entry.
The value will not have property `isPredatory = true` as the `default` property of the `Mapping` is not used.
==== Implicitly Typed `new`
When using the implicitly typed `new` invocation, there is no explicit parent value to amend.
In these cases, Pkl infers the amend operation's parent value based on context:
* When assigning to a declared property, the property's default value is amended (<<amend-null, including `null`>>).
If there is no type associated with the property, an empty `Dynamic` object is amended.
* When assigning to an entry (e.g. a `Mapping` member) or element (e.g. a `Listing` member), the enclosing object's `default` property is applied to the corresponding index or key, respectively, to produce the value to be amended.
* In other cases, evaluation fails with the error message "Cannot tell which parent to amend".
The type annotation of a <<methods,method>> parameter is not used for inference.
In this case, the argument's type should be specified explicitly.
[source,{pkl}]
----
class Bird {
name: String
function listHatchlings(items: Listing<String>): Listing<String> = new {
for (item in items) {
"\(name):\(item)"
}
}
}
typedProperty: Bird = new { // <1>
name = "Swift"
}
untypedProperty = new { // <2>
hello = "world"
}
typedListing: Listing<Bird> = new {
new { // <3>
name = "Kite"
}
}
untypedListing: Listing = new {
new { // <4>
hello = "there"
}
}
typedMapping: Mapping<String, Bird> = new {
default { entryKey ->
name = entryKey
}
["Saltmarsh Sparrow"] = new { // <5>
name = "Sharp-tailed Sparrow"
}
}
amendedMapping = (typedMapping) {
["Saltmarsh Sparrow"] = new {} // <6>
}
class Aviary {
birds: Listing<Bird> = new {
new { name = "Osprey" }
}
}
aviary: Aviary = new {
birds = new { // <7>
new { name = "Kiwi" }
}
}
swiftHatchlings = typedProperty.listHatchlings(new { "Poppy"; "Chirpy" }) // <8>
----
<1> Assignment to a property with an explicitly declared type, amending `new Bird {}`.
<2> Assignment to an undeclared property in module context, amending `new Dynamic {}`.
<3> `Listing` element creation, amending implicit `default`, `new Bird {}`.
<4> `Listing` element creation, amending implicit `default`, `new Dynamic {}`.
<5> `Mapping` value assignment, amdending the result of applying `default` to `"Saltmarsh Sparrow"`, `new Bird { name = "Saltmarsh Sparrow" }`.
<6> `Mapping` value assignment _replacing_ the parent's entry, amending the result of applying `default` to `"Saltmarsh Sparrow"`, `new Bird { name = "Saltmarsh Sparrow" }`.
<7> Admending the property default value `new Listing { new Bird { name = "Osprey" } }`; the result contains both birds.
<8> Error: Cannot tell which parent to amend.
[[let-expressions]]
=== Let Expressions
@@ -3200,10 +3379,11 @@ Here is an example:
[source%tested,{pkl}]
----
birdDiets = let (diets = List("Seeds", "Berries", "Mice"))
List(diets[2], diets[0]) // <1>
birdDiets =
let (diets = List("Seeds", "Berries", "Mice"))
List(diets[2], diets[0]) // <1>
----
<1> result: `List("Mice", "Seeds")`
<1> result: `birdDiets = List("Mice", "Seeds")`
`let` expressions serve two purposes:
@@ -3214,20 +3394,22 @@ List(diets[2], diets[0]) // <1>
[source%tested,{pkl}]
----
birdDiets = let (diets: List<String> = List("Seeds", "Berries", "Mice"))
diets[2] + diets[0] // <1>
birdDiets =
let (diets: List<String> = List("Seeds", "Berries", "Mice"))
diets[2] + diets[0] // <1>
----
<1> result: `List("Mice", "Seeds")`
<1> result: `birdDiets = List("Mice", "Seeds")`
`let` expressions can be stacked:
[source%tested,{pkl}]
----
birdDiets = let (birds = List("Pigeon", "Barn owl", "Parrot"))
let (diet = List("Seeds", "Mice", "Berries"))
birds.zip(diet) // <1>
birdDiets =
let (birds = List("Pigeon", "Barn owl", "Parrot"))
let (diet = List("Seeds", "Mice", "Berries"))
birds.zip(diet) // <1>
----
<1> result: `List(Pair("Pigeon", "Seeds"), Pair("Barn owl", "Mice"), Pair("Parrot", "Berries"))`
<1> result: `birdDiets = List(Pair("Pigeon", "Seeds"), Pair("Barn owl", "Mice"), Pair("Parrot", "Berries"))`
[[type-tests]]
=== Type Tests
@@ -3721,6 +3903,7 @@ bird2: Bird? = null // <2>
The only class types that admit `null` values despite not ending in `?` are `Any` and `Null`.
(`Null` is not very useful as a type because it _only_ admits `null` values.)
`Any?` and `Null?` are equivalent to `Any` and `Null`, respectively.
In some languages, nullable types are also known as _optional types_.
[[generic-types]]
==== Generic Types
@@ -4560,7 +4743,7 @@ oldPets {
}
newPets {
...cast
...oldPets
["Pigeon"] = "Toby the Pigeon" // <1>
}
----
@@ -5146,8 +5329,8 @@ It is defined by the presence of a `PklProject` file that amends the standard li
Defining a project serves the following purposes:
1. It allows defining common evaluator settings for Pkl modules within a logical project.
2. It helps with managing <<packages,package>> dependencies for Pkl modules within a logical project.
3. It enables packaging and sharing the contents of the project as a <<packages,package>>.
2. It helps with managing <<package-asset-uri,package>> dependencies for Pkl modules within a logical project.
3. It enables packaging and sharing the contents of the project as a <<package-asset-uri,package>>.
4. It allows importing packages via dependency notation.
[[project-dependencies]]
@@ -5225,7 +5408,7 @@ package {
packageZipUrl = "https://example.com/\(name)/\(name)@\(version).zip" // <4>
}
----
<1> The display name of the package. For display purposes only.
<1> The display name of the package.For display purposes only.
<2> The package URI, without the version part.
<3> The version of the package.
<4> The URL to download the package's ZIP file.
@@ -5233,8 +5416,9 @@ package {
The package itself is created by the command xref:pkl-cli:index.adoc#command-project-package[`pkl project package`].
This command only prepares artifacts to be published.
Once the artifacts are prepared, they are expected to be uploaded to an HTTPS server such that the ZIP asset can be downloaded at path `packageZipUrl`, and the metadata can be downloaded at `+https://<package uri>+`.
Once the artifacts are prepared, they are expected to be uploaded to an HTTPS server such that the ZIP asset can be downloaded at path `packageZipUrl`, and the metadata can be downloaded at `+https://<package uri>+`.
[[local-dependencies]]
==== Local dependencies
A project can depend on a local project as a dependency.
@@ -5282,3 +5466,68 @@ It can be imported using dependency notation, i.e. `import "@fruit/Pear.pkl"`.
At runtime, it will resolve to relative path `../fruit/Pear.pkl`.
When packaging projects with local dependencies, both the project and its dependent project must be passed to the xref:pkl-cli:index.adoc#command-project-package[`pkl project package`] command.
[[external-readers]]
=== External Readers
External readers are a mechanism to extend the <<modules,module>> and <<resources,resource>> URI schemes that Pkl supports.
Readers are implemented as ordinary executables and use Pkl's xref:bindings-specification:message-passing-api.adoc[message passing API] to communicate with the hosting Pkl evaluator.
The xref:swift:ROOT:index.adoc[Swift] and xref:go:ROOT:index.adoc[Go] language binding libraries provide an `ExternalReaderRuntime` type to facilitate implementing external readers.
External readers are configured separately for modules and resources.
They are registered by mapping their URI scheme to the executable to run and additonal arguments to pass.
This is done on the command line by passing `--external-resource-reader` and `--external-module-reader` flags, which may both be passed multiple times.
[source,text]
----
$ pkl eval <module> --external-resource-reader <scheme>=<executable> --external-module-reader <scheme>='<executable> <argument> <argument>'
----
External readers may also be configured in a <<projects, Project's>> `PklProject` file.
[source,{pkl}]
----
evaluatorSettings {
externalResourceReaders {
["<scheme>"] {
executable = "<executable>"
}
}
externalModuleReaders {
["<scheme>"] {
executable = "<executable>"
arguments { "<arg>"; "<arg>" }
}
}
}
----
Registering an external reader for a scheme automatically adds that scheme to the default allowed modules/resources.
As with Pkl's built-in module and resource schemes, setting explicit allowed modules or resources overrides this behavior and appropriate patterns must be specified to allow use of external readers.
==== Example
Consider this module:
[source,{pkl}]
----
username = "pigeon"
email = read("ldap://ds.example.com:389/dc=example,dc=com?mail?sub?(uid=\(username))").text
----
Pkl doesn't implement the `ldap:` resource URI scheme natively, but an external reader can provide it.
Assuming a hypothetical `pkl-ldap` executable implementing the external reader protocol and the `ldap:` scheme is in the `$PATH`, this module can be evaluated as:
[source,text]
----
$ pkl eval <module> --external-resource-reader ldap=pkl-ldap
username = "pigeon"
email = "pigeon@example.com"
----
In this example, the external reader may provide both `ldap:` and `ldaps:` schemes.
To support both schemes during evaluation, both would need to be registered explicitly:
[source,text]
----
$ pkl eval <module> --external-resource-reader ldap=pkl-ldap --external-resource-reader ldaps=pkl-ldap
----

View File

@@ -409,6 +409,10 @@ Evaluate the given `<modules>` as _tests_, producing a test report and appropria
Renderers defined in test files will be ignored by the `test` command.
Tests that result in writing `pkl-expected.pcf` files are considered failing tests.
If these are the only failures, the command exits with exit code 10.
Otherwise, failures result in exit code 1.
<modules>::
The absolute or relative URIs of the modules to test. Relative URIs are resolved against the working directory.
@@ -558,14 +562,64 @@ package already exists in the cache directory, this command is a no-op.
This command accepts <<common-options,common options>>.
[[command-analyze-imports]]
=== `pkl analyze imports`
*Synopsis*: `pkl analyze imports [<modules>]`
This command builds a graph of imports declared in the provided modules.
This is a lower level command that is meant to be useful for Pkl-related tooling.
For example, this command feeds into the xref:pkl-gradle:index.adoc[] to determine if tasks are considered up-to-date or not.
This command produces an object with two properties, `imports` and `resolvedImports`.
The `imports` property is a mapping of a module's absolute URI, to the set of imports declared within that module.
The `resolvedImports` property is a mapping of a module's absolute URI (as stated in `imports`), to the resolved absolute URI that might be useful for fetching the module's contents.
For example, a xref:language-reference:index.adoc#local-dependencies[local dependency] import will have an in-language URI with scheme `projectpackage:`, and may have resolved URI with scheme `file:` (assuming that the project is file-based).
Examples:
[source,shell]
----
# Analyze the imports of a single module
pkl analyze imports myModule.pkl
# Same as the previous command, but output in JSON.
pkl analyze imports -f json myModule.pkl
# Analyze imports of all modules declared within src/
pkl analyze imports src/*.pkl
----
<modules>::
The absolute or relative URIs of the modules to analyze. Relative URIs are resolved against the working directory.
==== Options
.-f, --format
[%collapsible]
====
Same meaning as <<format>> in <<command-eval>>.
====
.-o, --output-path
[%collapsible]
====
Same meaning as <<output-path>> in <<command-eval>>.
====
This command also takes <<common-options,common options>>.
[[common-options]]
=== Common options
The <<command-eval>>, <<command-test>>, <<command-repl>>, <<command-project-resolve>>, <<command-project-package>>, and <<command-download-package>> commands support the following common options:
The <<command-eval>>, <<command-test>>, <<command-repl>>, <<command-project-resolve>>, <<command-project-package>>, <<command-download-package>>, and <<command-analyze-imports>> commands support the following common options:
include::../../pkl-cli/partials/cli-common-options.adoc[]
The <<command-eval>>, <<command-test>>, <<command-repl>>, and <<command-download-package>> commands also take the following options:
The <<command-eval>>, <<command-test>>, <<command-repl>>, <<command-download-package>>, and <<command-analyze-imports>> commands also take the following options:
include::../../pkl-cli/partials/cli-project-options.adoc[]

View File

@@ -7,7 +7,6 @@ Comma-separated list of URI patterns that determine which modules can be loaded
Patterns are matched against the beginning of module URIs.
(File paths have been converted to `file:` URLs at this stage.)
At least one pattern needs to match for a module to be loadable.
Both source modules and transitive modules are subject to this check.
====
[[allowed-resources]]
@@ -20,6 +19,19 @@ Patterns are matched against the beginning of resource URIs.
At least one pattern needs to match for a resource to be readable.
====
[[color]]
.--color
[%collapsible]
====
Default: `auto` +
When to format messages with ANSI color codes.
Possible values:
- `"never"`: Never format
- `"auto"`: Format if `stdin`, `stdout`, or `stderr` are connected to a console.
- `"always"`: Always format
====
[[cache-dir]]
.--cache-dir
[%collapsible]

View File

@@ -162,7 +162,7 @@ We recommend to provision it with a Maven compatible build tool as shown in <<in
The Pkldoc tool is offered as Gradle plugin, Java library, and CLI.
It can generate documentation either for modules directly, or generate documentation for _package uris_.
The tool requires an argument of a module named `_docsite-info.pkl`, that amends link:{uri-DocsiteInfo}[pkl.DocsiteInfo].
The tool requires an argument of a module named _docsite-info.pkl_, that amends link:{uri-DocsiteInfo}[pkl.DocsiteInfo].
[discrete]
==== Generating documentation for modules directly

View File

@@ -102,7 +102,6 @@ pkl {
evaluators {
evalPkl {
sourceModules.add(file("module1.pkl"))
transitiveModules.from file("module2.pkl")
outputFile = layout.buildDirectory.file("module1.yaml")
outputFormat = "yaml"
}
@@ -118,7 +117,6 @@ pkl {
evaluators {
register("evalPkl") {
sourceModules.add(file("module1.pkl"))
transitiveModules.from(file("module2.pkl"))
outputFile.set(layout.buildDirectory.file("module1.yaml"))
outputFormat.set("yaml")
}
@@ -127,9 +125,6 @@ pkl {
----
====
To guarantee correct Gradle up-to-date behavior,
`transitiveModules` needs to contain all module files transitively referenced by `sourceModules`.
For each declared evaluator, the Pkl plugin creates an equally named task.
Hence the above evaluator can be run with:
@@ -691,3 +686,61 @@ The project directories to create packages for.
Common properties:
include::../partials/gradle-common-properties.adoc[]
[[analyze-imports]]
== Analyze Imports
This feature is the Gradle analogy for the xref:pkl-cli:index.adoc#command-analyze-imports[analyze imports] command in the CLI. It builds a graph of imports of the provided source modules.
=== Usage
[tabs]
====
build.gradle::
+
[source,groovy]
----
pkl {
analyzers {
imports {
appConfig {
sourceModules.add(file("src/main/resources/appConfig.pkl"))
}
}
}
}
----
build.gradle.kts::
+
[source,kotlin]
----
pkl {
analyzers {
imports {
register("appConfig") {
sourceModules.add(file("src/main/resources/appConfig.pkl"))
}
}
}
}
----
====
=== Configuration Options
.outputFormat: Property<String>
[%collapsible]
====
Same meaning as <<output-format,outputFormat>> in <<module-evaluation>>.
====
.outputFile: RegularFileProperty<String>
[%collapsible]
====
Same meaning as <<output-file,outputFile>> in <<module-evaluation>>.
====
Common properties:
include::../partials/gradle-modules-properties.adoc[]

View File

@@ -7,7 +7,6 @@ URI patterns that determine which modules can be loaded and evaluated.
Patterns are matched against the beginning of module URIs.
(File paths have been converted to `file:` URLs at this stage.)
At least one pattern needs to match for a module to be loadable.
Both source modules and transitive modules are subject to this check.
====
.allowedResources: ListProperty<String>
@@ -68,6 +67,13 @@ The cache directory for storing packages.
If `null`, defaults to `~/.pkl/cache`.
====
.color: Property<Boolean>
[%collapsible]
====
Default: `false` +
Format messages using ANSI color.
====
.noCache: Property<Boolean>
[%collapsible]
====

View File

@@ -20,11 +20,17 @@ This property accepts the following types to represent a module:
.transitiveModules: ConfigurableFileCollection
[%collapsible]
====
Default: `files()` (empty collection) +
Default: [computed by pkl-gradle] +
Example 1: `transitiveModules.from files("module1.pkl", "module2.pkl")` +
Example 2: `+transitiveModules.from fileTree("config").include("**/*.pkl")+` +
File paths of modules that are directly or indirectly used by source modules.
Setting this option enables correct Gradle up-to-date checks, which ensures that your Pkl tasks are executed if any of the transitive files are modified; it does not affect evaluation otherwise.
This property, along with `sourceModules`, is the set of input files used to determine whether this task is up-to-date or not.
By default, Pkl computes this property by analyzing the imports of the source modules.
Setting this property explicitly causes Pkl to skip the analyze imports step.
Including source modules in `transitiveModules` is permitted but not required.
Relative paths are resolved against the project directory.
====

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View File

@@ -1,6 +1,6 @@
= Pkl 0.26 Release Notes
:version: 0.26
:version-minor: 0.26.0
:version-minor: 0.26.3
:release-date: June 17th, 2024
include::ROOT:partial$component-attributes.adoc[]
@@ -508,6 +508,7 @@ We would like to thank the contributors to this release (in alphabetical order):
* https://github.com/MarkSRobinson[@MarkSRobinson]
* https://github.com/mitchcapper[@mitchcapper]
* https://github.com/mrs1669[@mrs1669]
* https://github.com/netvl[@netvl]
* https://github.com/nirinchev[@nirinchev]
* https://github.com/raj-j-shah[@raj-j-shah]
* https://github.com/sgammon[@sgammon]

View File

@@ -0,0 +1,542 @@
= Pkl 0.27 Release Notes
:version: 0.27
:version-minor: 0.27.2
:release-date: November 5th, 2024
include::ROOT:partial$component-attributes.adoc[]
Pkl {version} was released on {release-date}. +
[.small]#The latest bugfix release is {version-minor}. (xref:changelog.adoc[All Versions])#
This release brings improvements in typechecking of `Listing` and `Mapping`, the ability to use readers from external processes, as well as a new import graph analyzer API.
The next release (0.28) is scheduled for February 2025.
Please send feedback and questions to https://github.com/apple/pkl/discussions[GitHub Discussions], or submit an issue on https://github.com/apple/pkl/issues/new[Github]. +
[small]#Pkl is hosted on https://github.com/apple/pkl[GitHub].
To get started, follow xref:pkl-cli:index.adoc#installation[Installation].#
== Highlights [small]#💖#
News you don't want to miss.
[#typecheck-improvements]
=== Improved typechecking of `Listing` and `Mapping` types
Typechecking of `Listing` and `Mapping` types has been improved (https://github.com/apple/pkl/pull/628[#628], https://github.com/apple/pkl/pull/725[#725], https://github.com/apple/pkl/pull/740[#740], https://github.com/apple/pkl/pull/752[#752], https://github.com/apple/pkl/pull/778[#778], https://github.com/apple/pkl/pull/781[#781]).
Today, the typecheck `listing: Listing<E>` immediately evaluates all listing elements to check that they have type `E`.
Likewise, the typecheck `mapping: Mapping<K, V>` immediately evaluates all mapping values to check that they have type `V`.
For example, the typecheck `listing: Listing<Bird>` proceeds as follows:
1. Check that `listing` has type `Listing`
2. Evaluate each listing element and check that it has type `Bird`
This behavior is different from how the rest of Pkl works.
Generally, Pkl only evaluates code that affects program output.
For example, consider the following program:
[source,pkl]
----
class Bird {
name: String
canFly: Boolean
}
local bird: Bird = new {
name = "Pidgy"
canFly = throw("uh oh")
}
birdName = bird.name
----
Even though `bird.canFly` throws an error, the above program succeeds because `bird.canFly` is not part of the program's output and hence is never accessed (Note that `bird` is a _local_ property).
Typechecks of `Mapping` and `Listing` types have been changed to match this behavior.
Mapping and listing values are now only typechecked if and when they are accessed.
NOTE: Mapping _keys_ are still eagerly checked.
This change causes some previously failing programs to evaluate successfully:
[source,pkl]
----
local myNumbers: Listing<Int> = new { 1; 2; "uh oh" }
result = myNumbers[0]
----
In Pkl 0.26 and below, the above program fails with a type mismatch error because element `"uh oh"` is typechecked when `myNumbers` is accessed.
In Pkl 0.27, the same program succeeds, because only element `myNumbers[0]` is part of the program's output and its typecheck succeeds.
As another consequence of this change, some Pkl programs now complete more quickly:
[source,pkl]
----
local allBirds: Mapping<String, Bird> = import*("**/bird.pkl")
environment: "prod"|"qa"
cluster: String
myBird = allBirds["\(environment)/\(cluster)/bird.pkl"] // <1>
----
In Pkl 0.26 and below, all modules matching `**/bird.pkl` are imported when `allBirds` is accessed and typechecked.
This can take a long time.
In Pkl 0.27, only module `"\(environment)/\(cluster)/bird.pkl"` is imported because only this module is part of the program's output.
To learn more about this change, consult https://github.com/apple/pkl-evolution/blob/main/spices/SPICE-0010-overhauled-mapping-listing-typechecks.adoc[SPICE-0010].
=== External readers
A new feature has been added to allow Pkl to spawn external processes to read resources and modules (https://github.com/apple/pkl/pull/660[#660], https://github.com/apple/pkl/pull/762[#762], https://github.com/apple/pkl/pull/766[#766], https://github.com/apple/pkl/pull/770[#770]).
Today, users who use Pkl as a library can define custom module and resource readers.
This allows authors to extend how Pkl performs I/O.
For example, users can implement a reader that reads the `secret:` scheme, where they define exactly how the bytes are fetched in the host runtime.
[source,pkl]
----
result = read("secret:mypassword") // <1>
----
<1> `secret:` is a custom scheme defined by the host runtime.
However, CLI users have been left out.
In Pkl 0.27, a new extension point is added to allow users to implement module and resource readers as external processes.
When run, Pkl will spawn the external process, and talk to the process via xref:bindings-specification:message-passing-api.adoc[message passing].
To learn more about this feature, consult https://github.com/apple/pkl-evolution/blob/main/spices/SPICE-0009-external-readers.adoc[SPICE-0009].
Thanks to https://github.com/HT154[@HT154] for contributing the feature!
[[import-analysis]]
=== Import analysis API
A new API has been added to analyze the import graph of Pkl modules (https://github.com/apple/pkl/pull/695[#695]).
This API comes in four forms:
1. A standard library module: `pkl:analyze`
2. A CLI command: `pkl anaylze imports`
3. A Java API: `org.pkl.core.Analyzer`
4. A Gradle API: `org.pkl.gradle.task.AnalyzeImportsTask`
Some use-cases for this API are:
* For build tools to perform out-of-date checks. Build tools can invalidate a cached result if any of the transitive modules have changed.
* Static code analysis, to determine how Pkl modules depend on each other.
With this API, xref:pkl-gradle:index.adoc[] now by default <<transitive-modules-computed-by-default,computes the transitive modules>> for many of its tasks.
Here is an example of the CLI in use:
[source,shell]
----
pkl analyze imports -f json myModule.pkl # <1>
----
<1> `-f` means: produce output in JSON.
Produces:
[source,json]
----
{
"imports": {
"file:///my/proj/myModule.pkl": [
{
"uri": "projectpackage://example.com/birds@1.0.0#/Bird.pkl"
}
],
"projectpackage://example.com/birds@1.0.0#/Bird.pkl": []
},
"resolvedImports": {
"file:///my/proj/myModule.pkl": "file:///my/proj/myModule.pkl",
"projectpackage://example.com/birds@1.0.0#/Bird.pkl": "file:///my/birds/Bird.pkl"
}
}
----
From this output, we can see that `myModule.pkl` imports `Bird.pkl` from the `birds` package.
We can also see that the module `projectpackage://example.com/birds@1.0.0#/Bird.pkl` resolves to disk location `\file:///my/birds/Bird.pkl` (we can deduce that `birds` is a xref:language-reference:index.adoc#local-dependencies[local dependency]).
To learn more about this feature, consult https://github.com/apple/pkl-evolution/blob/main/spices/SPICE-0001-import-graph-analyzer-api.adoc[SPICE-0001].
== Noteworthy [small]#🎶#
Ready when you need them.
=== Colored output
The Pkl CLI will now emit some messages in color (https://github.com/apple/pkl/pull/552[#552], https://github.com/apple/pkl/pull/746[#746], https://github.com/apple/pkl/pull/771[#771], https://github.com/apple/pkl/pull/779[#779]).
Here is a sneak peek of colored error messages in action.
image::error_sample.png[syntax highlighted output]
Thanks to https://github.com/thomaspurchas[@thomaspurchas] for contributing to this feature!
=== `const local` object members
The `const` modifier can be applied to object members, provided that they are also `local` (https://github.com/apple/pkl/pull/678[#678]).
Currently, regular object members are not allowed to have the `const` modifier.
This introduces an artificial pain point.
For example, given the following module:
[source,pkl]
----
amends "Bird.pkl"
import "Bird.pkl"
local northAmerica = "North America"
local typealias NorthAmericanBird = Bird(this.origin == northAmerica) // <1>
----
<1> Error: cannot reference `northAmerica` from here because it is not `const`.
This is invalid code, because this typealias is referencing a non-const value on the enclosing module.
However, is not possible fix this by adding the `const` modifier to `northAmerica`.
This is because this module `amends "Bird.pkl"`, which means that this module is considered a regular object and not a class.
This means that any members declared here are _object members_, and not _class members_.
In Pkl 0.27, a new rule is introduced to allow the `const` modifier to be applied to object members, provided that they are also `local`.
This change affects object properties, as well as object methods.
To read more about this design, consult https://github.com/apple/pkl-evolution/blob/main/spices/SPICE-0011-const-object-members.adoc[SPICE-0011].
=== Pkl CLI changes
==== New CLI Flags
Some new common flags have been added to the CLI (https://github.com/apple/pkl/pull/660[#660], https://github.com/apple/pkl/pull/746[#746]).
|===
|Flag |Description
|`--color`
|Format messages with ANSI color codes
|`--external-module-reader`
|Shell out to a process to read certain modules.
|`--external-resource-reader`
|Shell out to a process to read certain resources.
|===
==== New command: `pkl analyze imports`
As part of the set of APIs added for <<import-analysis,import analysis>>, a new subcommand has been added called `analyze imports` (https://github.com/apple/pkl/pull/695[#695]).
For details, consult the xref:pkl-cli:index.adoc#command-analyze-imports[CLI documentation].
=== Kotlin/Java code generator improvements
Various improvements have been made to the Kotlin and Java code generators (https://github.com/apple/pkl/pull/705[#705], https://github.com/apple/pkl/pull/710[#710], https://github.com/apple/pkl/pull/714[#714], https://github.com/apple/pkl/pull/721[#721], https://github.com/apple/pkl/pull/729[#729]).
==== Java codegen improvements
* Only generate `hashCode()`, `equals()`, and `toString()` methods for Java classes that are instantiable.
* Add support for Spring Boot 3.
* Make module classes also implement serializable.
* Make empty Java classes instantiable.
==== Kotlin codegen improvements
* Skip generation of `copy()`, `equals()`, `hashCode()`, `toString()` methods for abstract Kotlin classes.
* Don't implement `Serializable` for abstract classes
* Add support for Spring Boot 3.
Thanks to https://github.com/translatenix[@translatenix] for contributing these improvements!
=== Gradle Plugin changes
==== New `AnalyzeImportsTask`
A new task called `org.pkl.gradle.task.AnalyzeImportsTask` is introduced (https://github.com/apple/pkl/pull/695[#695]).
This task is the Gradle analogy to `pkl analyze imports`.
Example:
[tabs]
====
build.gradle::
+
[source,groovy]
----
pkl {
analyzers {
imports {
appConfig {
sourceModules.add(file("src/main/resources/appConfig.pkl"))
}
}
}
}
----
build.gradle.kts::
+
[source,kotlin]
----
pkl {
analyzers {
imports {
register("appConfig") {
sourceModules.add(file("src/main/resources/appConfig.pkl"))
}
}
}
}
----
====
For more details, consult the xref:pkl-gradle:index.adoc#analyze-imports[documentation].
==== Tracked file outputs
Tasks created by the Pkl plugin now declare tracked output files (https://github.com/apple/pkl/pull/403[#403]).
This means that downstream tasks do not need to declare an explicit dependency on the Pkl task.
For example, assuming that `evalPkl` is an `EvalTask`:
.build.gradle.kts
[source,diff]
----
val myGradleTask by tasks.registering {
inputs.files(evalPkl)
- dependsOn(evalPkl) // <1>
}
----
<1> No longer necessary to declare this dependency.
[[transitive-modules-computed-by-default]]
==== `transitiveModules` computed by default
The `transitiveModules` property of a task is now computed by building the import graph of the source modules (https://github.com/apple/pkl/pull/695[#695]).
This means that Pkl-related tasks no longer need to declare their set of transitive modules, because the pkl-gradle plugin will compute this automatically.
NOTE: This adds latency to each task. To opt out of this behavior, set `transitiveModules` explicitly.
=== Standard library changes
==== Additions to `pkl:base`
New properties and methods have been added to the classes of `pkl:base` (https://github.com/apple/pkl/pull/666[#666], https://github.com/apple/pkl/pull/683[#683]).
New properties and methods have been added to {uri-stdlib-Listing}[`Listing`] and {uri-stdlib-Mapping}[`Mapping`].
One of the goals of this change is to improve the experience of authoring constraints.
This eliminates the need to convert to collection types as often.
The added properties and methods are:
* {uri-stdlib-Listing}#first[`Listing.first`]
* {uri-stdlib-Listing}#firstOrNull[`Listing.firstOrNull`]
* {uri-stdlib-Listing}#last[`Listing.last`]
* {uri-stdlib-Listing}#lastOrNull[`Listing.lastOrNull`]
* {uri-stdlib-Listing}#single[`Listing.single`]
* {uri-stdlib-Listing}#singleOrNull[`Listing.singleOrNull`]
* {uri-stdlib-Listing}#every()[`Listing.every()`]
* {uri-stdlib-Listing}#any()[`Listing.any()`]
* {uri-stdlib-Listing}#contains()[`Listing.contains()`]
* {uri-stdlib-Mapping}#containsValue()[`Mapping.containsValue()`]
* {uri-stdlib-Mapping}#every()[`Mapping.every()`]
* {uri-stdlib-Mapping}#any()[`Mapping.any()`]
With this, the following change can be made to existing constraints:
[source,diff]
----
-ipAddresses: Listing<String>(toList().contains("127.0.0.1"))
+ipAddresses: Listing<String>(contains("127.0.0.1"))
----
Additionally, a new method is added to `String`, called {uri-stdlib-String}#splitLimit()[`String.splitLimit()`].
==== Additions to `pkl:EvaluatorSettings`
New properties have been added to `pkl:EvaluatorSettings` (https://github.com/apple/pkl/pull/660[#660], https://github.com/apple/pkl/pull/746[#746]).
These are:
* {uri-stdlib-evaluatorSettingsModule}/#color[`color`]
* {uri-stdlib-evaluatorSettingsModule}/#externalModuleReaders[`externalModuleReaders`]
* {uri-stdlib-evaluatorSettingsModule}/#externalResourceReaders[`externalResourceReaders`]
==== `String` to `Number` conversion improvements.
The `String` to `Number` converter methods, for example, {uri-stdlib-StringToInt}[`String.toInt()`], can now handle underscore separators (https://github.com/apple/pkl/pull/578[#578], https://github.com/apple/pkl/pull/580[#580]).
This better aligns with the source code representation of xref:language-reference:index.adoc#integers[number literals].
[source,pkl]
----
myNum = "1_000".toInt() // <1>
----
<1> Result: `1000`
==== New module: `pkl:analyze`
As part of <<import-analysis>>, a new standard library module is added called `pkl:analyze` (https://github.com/apple/pkl/pull/695[#695]).
This module provides an API for computing the total import graph given a set of input modules.
This API treats the inputs as entrypoints, and produces a graph representing the entire dependency tree, including transitive imports.
Example:
[source,pkl]
----
import "pkl:analyze"
importGraph: analyze.ImportGraph = analyze.importGraph(Set("file:///path/to/my/module.pkl"))
----
For details, see the {uri-stdlib-analyzeModule}[documentation].
=== Annotations on `PklProject` added to packages
When creating packages, some annotations on a `PklProject` will affect how pkldoc generates documentation.
* `@Unlisted`: Omit the package from publishing documentation.
* `@Deprecated`: Add information on the package to show that it is deprecated.
Example:
.PklProject
[source,pkl]
----
@Deprecated
amends "pkl:Project"
----
=== Test report improvements
The report generated from `pkl test` has been overhauled and improved (https://github.com/apple/pkl/pull/498[#498], https://github.com/apple/pkl/pull/628[#682], https://github.com/apple/pkl/pull/738[#738], https://github.com/apple/pkl/pull/771[#771]).
* Tests are grouped into either the `facts` or `examples` section.
* A summary line is added, describing how many tests have passed and failed, and how many assertions have passed and failed.
* Test results are colored.
* The ✅ and ❌ emojis are replaced with ✔ and ✘.
* Thrown errors are reported within the test.
Here is a sneak peek of the new test result output.
image::test_sample.png[]
Thanks to https://github.com/jjmaestro[@jjmaestro] for contributing to this improvement!
=== Java API additions
==== New API: `org.pkl.core.Analyzer`
As part of <<import-analysis>>, a new Java API called `org.pkl.core.Analyzer` is introduced (https://github.com/apple/pkl/pull/695[#695]).
==== New methods
The following methods are added:
**pkl-executor**
* `org.pkl.executor.ExecutorException.getPklVersion`
* `org.pkl.executor.ExecutorException.ExecutorException(java.lang.String, java.lang.Throwable, java.lang.String)`
**pkl-core**
* `org.pkl.core.module.ModuleKeyFactories.externalProcess(java.lang.String, org.pkl.core.externalreader.ExternalReaderProcess)`
* `org.pkl.core.module.ModuleKeyFactories.externalProcess(java.lang.String, org.pkl.core.externalreader.ExternalReaderProcess, long)`
== Breaking Changes [small]#💔#
Things to watch out for when upgrading.
=== Java API breaking changes
The following Java APIs have breaking changes:
|===
|Class/method | Breaking change
|`org.pkl.core.runtime.TestResults`
|Moved to `org.pkl.core.TestResults`, turned into a record, and largely restructured.
|`org.pkl.core.module.ModuleKeyFactories.closeQuietly`
|Deprecated for removal in favor of `org.pkl.core.Closeables.closeQuietly`.
|===
=== Spring Boot 2 support dropped
The Java code generator no longer supports Spring Boot 2.x (https://github.com/apple/pkl/pull/729[#729]).
Spring Boot 2 users can continue to use the Pkl 0.26 code generator.
=== `pkl test` considered failing when writing examples
If running `pkl test` results in `pkl-expected.pcf` files being written, the test now exits with exit code `10` (https://github.com/apple/pkl/pull/738[#738]).
Additionally, the junit reports will consider the test as failing.
=== `Listing` and `Mapping` typecheck changes
Due to changes to <<typecheck-improvements,Listing and Mapping typechecking>>, some previously failing programs now succeed.
This can happen when erroneous code is never evaluated because it does not affect program output:
[source,pkl]
----
local myNumbers: Listing<Int> = new { 1; 2; "uh oh" }
result = myNumbers[0] // <1>
----
<1> In Pkl 0.26 and below, throws a type mismatch error.
+
In Pkl 0.27, yields `1`.
== Miscellaneous [small]#🐸#
* Make pkl-doc top box include a preview of the rest of module-level documentation (https://github.com/apple/pkl/pull/570[#570]).
* Module `pkl-core` now has a dependency on `org.msgpack:msgpack-core` (https://github.com/apple/pkl/pull/660[#660]). Users concerned about potential version conflicts can use one of Pkl's shaded fat JARs (`pkl-config-java-all`, `pkl-tools`).
* Make PklProject.deps.json files end in a newline (https://github.com/apple/pkl/pull/664[#644]).
* Fix invalid syntax of code examples in stdlib doc comments (https://github.com/apple/pkl/pull/703[#703]).
* Update Java dependencies (https://github.com/apple/pkl/pull/689[#689], https://github.com/apple/pkl/pull/767[#767]).
* Add jbang catalog support (https://github.com/apple/pkl/pull/655[#655]).
* Documentation improvements (https://github.com/apple/pkl/pull/623[#623], https://github.com/apple/pkl/pull/680[#680], https://github.com/apple/pkl/pull/682[#682], https://github.com/apple/pkl/pull/685[#685], https://github.com/apple/pkl/pull/687[#687], https://github.com/apple/pkl/pull/703[#703], https://github.com/apple/pkl/pull/704[#704], https://github.com/apple/pkl/pull/715[#715], https://github.com/apple/pkl/pull/730[#730], https://github.com/apple/pkl/pull/753[#753]).
== Bug Fixes [small]#🐜#
The following bugs have been fixed.
* CLI `--property` flags containing `=` in property values are not parsed correctly (https://github.com/apple/pkl/issues/630[#630]).
* Thrown `PklBugException` when reading assets from a local project dependency (https://github.com/apple/pkl/issues/641[#641]).
* Thrown `PklBugException` when PklProjects have a cyclical local dependency (https://github.com/apple/pkl/pull/731[#731]).
* Thrown exception when sending `ReadResourceResponse` or `ReadModuleResponse` where both `contents` and `error` are `null` (https://github.com/apple/pkl/pull/657[#657]).
* Double unary minus is evaluated as single unary minus (https://github.com/apple/pkl/pull/697[#697]).
* Kotlin compiler fails to compiler generated classes with "copy overrides nothing" for subclasses of abstract classes (https://github.com/apple/pkl/issues/569[#569]).
* "Unexpected error" thrown when `Module.output` has its type overridden (https://github.com/apple/pkl/issues/709[#709]).
* "Unexpected error" thrown when loading files with non-ASCII characters (https://github.com/apple/pkl/issues/653[#653]).
* Type parameters in `new Mapping<TypeA, TypeB>`/`new Listing <Type>` are not checked (https://github.com/apple/pkl/issues/405[#405]).
* Comparison methods of `pkl:semver` are incorrect (https://github.com/apple/pkl/issues/772[#772]).
== Contributors [small]#🙏#
We would like to thank the contributors to this release (in alphabetical order):
* https://github.com/djarnis73[@djarnis73]
* https://github.com/kasugamirai[@kasugamirai]
* https://github.com/KushalP[@KushalP]
* https://github.com/jjmaestro[@jjmaestro]
* https://github.com/HT154[@HT154]
* https://github.com/lamtrinhdev[@lamtrinhdev]
* https://github.com/ManuW[@ManuW]
* https://github.com/maxandersen[@maxandersen]
* https://github.com/netvl[@netvl]
* https://github.com/StefMa[@StefMa]
* https://github.com/taichi-ishitani[@taichi-ishitani]
* https://github.com/thomaspurchas[@thomaspurchas]
* https://github.com/translatenix[@translatenix]

View File

@@ -1,6 +1,86 @@
= Changelog
include::ROOT:partial$component-attributes.adoc[]
[[release-0.27.2]]
== 0.27.2 (2025-01-22)
=== Fixes
* Fixes issues where server mode message decoding might result in null pointer exceptions (https://github.com/apple/pkl/pull/853[#853], https://github.com/apple/pkl/pull/882[#882]).
* Fixes an issue where the test report outputs decimal numbers using local-specific decimals (https://github.com/apple/pkl/pull/868[#868]).
* Fixes an issue where the native executables might not run on some environments, resulting in an error like "Fatal error: Failed to create the main Isolate" (https://github.com/apple/pkl/pull/875[#875]).
=== Contributors ❤️
Thank you to all the contributors for this release!
* link:https://github.com/HT154[@HT154]
* link:https://github.com/StefMa[@StefMa]
[[release-0.27.1]]
== 0.27.1 (2024-12-06)
=== Fixes
- Fixes a broken "number literals" link in the 0.27 release notes (https://github.com/apple/pkl/pull/784[#784]).
- Fixes a possible deadlock during external reader process close (https://github.com/apple/pkl/pull/786[#786]).
- Fixes counting elements with computed indices multiple times in length computation of listings (https://github.com/apple/pkl/pull/797[#797]).
- Fixes non Pkl modules being reported in GatherImports task, leading to plugin failures (https://github.com/apple/pkl/pull/821[#821]).
- Fixes a problem where the delegate chain of type casts for Listing/Mapping get unreasonably big, even though the type nodes are the same, which may lead to a stack overflow or performance degradation (https://github.com/apple/pkl/pull/826[#826]).
- Fixes incorrect scoping of type variables in lazy Listing/Mapping type checking in cross-module typealiases (https://github.com/apple/pkl/pull/789[#789]).
- Fixes regression in type checking logic for Listing/Mapping (https://github.com/apple/pkl/pull/789[#789]).
=== Contributors ❤️
Thank you to all the contributors for this release!
* link:https://github.com/GUI[@GUI]
* link:https://github.com/HT154[@HT154]
* link:https://github.com/odenix[@odenix] (formerly @translatenix)
[[release-0.27.0]]
== 0.27.0 (2024-11-05)
xref:0.27.adoc[Release notes]
[[release-0.26.3]]
== 0.26.3 (2024-08-06)
=== Fixes
* Fixes an issue where CLI argument `--property foo=""` is effectively parsed as `--property foo="true"`. This is now parsed as an empty string (https://github.com/apple/pkl/pull/596[#596]).
* Fixes a regression where amending a globbed import or globbed read results in a PklBugException (https://github.com/apple/pkl/pull/607[#607]).
* Fixes an issue around using `file()` notation when using the pkl-gradle plugin on Windows (https://github.com/apple/pkl/pull/611[#611]).
[[release-0.26.2]]
== 0.26.2 (2024-07-18)
=== Fixes
* Fixes a possible race condition where multiple concurrent Pkl evaluations results in a thrown exception when downloading packages (https://github.com/apple/pkl/pull/584[#584]).
[[release-0.26.1]]
== 0.26.1 (2024-06-28)
=== Fixes
* Fixes a regression where native executables fail to run on some environments that don't support newer CPU features (https://github.com/apple/pkl/pull/551[#551]).
* Fixes a `PklBugException` when passing `.` as a project directory to `pkl project resolve` and `pkl project package` (https://github.com/apple/pkl/pull/544[#544]).
=== Changes
* Disable revocation checking of TLS certificates (https://github.com/apple/pkl/pull/553[#553]).
+
As part of HTTP improvements in 0.26, we unwittingly fixed a bug where Pkl does not actually perform cert revocation checks when making HTTPS requests.
This fix, unfortunately, caused a regression in some cases.
For example, this happens when connecting to a server that bears a public trust certificate, while in an environment with no internet access.
This is because the HTTP client needs to check the revocation status of all certificates in the chain.
+
Revocation checks are a nuanced topic with some benefits, and also with its own problem areas.
For this reason, revocation checking is disabled for Pkl's native CLIs.
Users of Pkl's Java APIs will respect the revocation settings set in the JVM.
[[release-0.26.0]]
== 0.26.0 (2024-06-17)

View File

@@ -1,5 +1,6 @@
= Release Notes
* xref:0.27.adoc[0.27 Release Notes]
* xref:0.26.adoc[0.26 Release Notes]
* xref:0.25.adoc[0.25 Release Notes]
* xref:changelog.adoc[Changelog]

View File

@@ -39,6 +39,7 @@
* xref:ROOT:examples.adoc[Examples]
* xref:release-notes:index.adoc[Release Notes]
** xref:release-notes:0.27.adoc[0.27 Release Notes]
** xref:release-notes:0.26.adoc[0.26 Release Notes]
** xref:release-notes:0.25.adoc[0.25 Release Notes]
** xref:release-notes:changelog.adoc[Changelog]

View File

@@ -22,10 +22,10 @@ import org.pkl.core.parser.antlr.PklParser
import org.pkl.core.repl.ReplRequest
import org.pkl.core.repl.ReplResponse
import org.pkl.core.repl.ReplServer
import org.pkl.core.resource.ResourceReaders
import org.pkl.core.util.IoUtils
import org.antlr.v4.runtime.ParserRuleContext
import org.pkl.core.http.HttpClient
import org.pkl.core.resource.ResourceReaders
import java.nio.file.Files
import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile
@@ -41,7 +41,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
companion object {
val headingRegex = Regex("""(?u)^\s*(=++)\s*(.+)""")
val collapsibleBlockRegex = Regex("""(?u)^\s*\[%collapsible""")
val codeBlockRegex = Regex("""(?u)^\s*\[source(?:%(tested|parsed)(%error)?)?(?:,(?:\{)?([a-zA-Z-_]+)}?)?""")
val codeBlockRegex = Regex("""(?u)^\s*\[source(?:%(tested|parsed)(%error)?)?(?:,\{?([a-zA-Z-_]+)}?)?""")
val codeBlockNameRegex = Regex("""(?u)^\s*\.(.+)""")
val codeBlockDelimiterRegex = Regex("""(?u)^\s*----""")
val graphicsRegex = Regex("\\[small]#.+#")
@@ -96,7 +96,8 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
null,
null,
IoUtils.getCurrentWorkingDir(),
StackFrameTransformers.defaultTransformer
StackFrameTransformers.defaultTransformer,
false,
)
return ExecutionContext(replServer)
}

View File

@@ -1,7 +1,7 @@
# suppress inspection "UnusedProperty" for whole file
group=org.pkl-lang
version=0.26.0
version=0.27.2
# google-java-format requires jdk.compiler exports
org.gradle.jvmargs= \

View File

@@ -1,30 +1,32 @@
[versions] # ordered alphabetically
antlr = "4.+"
assertj = "3.+"
checksumPlugin = "1.2.0"
clikt = "3.5.1"
checksumPlugin = "1.4.0"
clikt = "3.+"
commonMark = "0.+"
downloadTaskPlugin = "5.6.0"
geantyref = "1.+"
googleJavaFormat = "1.21.0"
# must not use `+` because used in download URL
graalVm = "23.0.2"
graalVmJdkVersion = "17.0.10"
# 23.1.x requires JDK 20+
graalVm = "23.0.6"
graalVmJdkVersion = "17.0.12"
# slightly hacky but convenient place so we remember to update the checksum
graalVmSha256-macos-x64 = "14f4bd6417809905f86e786c779d0fc2feb840d7dac35ae3503eb25af0530da0"
graalVmSha256-macos-aarch64 = "e944c5ce5da56e683fc8f1a57191b46d9cb702930b1688bda064fcf467d876b8"
graalVmSha256-linux-x64 = "112dc9b92d81a946f1b5b334646151b790785c813e76fcf13527a319003d7e2c"
graalVmSha256-linux-aarch64 = "c95ac550d070f06666cf8c1023a098380dd565be00866473caf6ff1b7cdf680c"
graalVmSha256-windows-x64 = "1ab2291e71f54d73e3e57b7fccbf184cabcba37e16ca9d1cf42d08474a7c02f0"
ideaExtPlugin = "1.1"
graalVmSha256-macos-x64 = "3ecac1471f3fa95a56c5b75c65db9e60ac4551f56eda09eb9da95e6049ea77d7"
graalVmSha256-macos-aarch64 = "4cdfdc6c9395f6773efcd191b6605f1b7c8e1b78ab900ab5cff34720a3feffc5"
graalVmSha256-linux-x64 = "b6f3dace24cf1960ec790216f4c86f00d4f43df64e4e8b548f6382f04894713f"
graalVmSha256-linux-aarch64 = "bd991d486b92deb74337b881e0f13a764c9c1e90fc358819080f7321fa5175e8"
graalVmSha256-windows-x64 = "8b978e56dddc0edc60db99794b56975740d9c52293b31549cfc3f7516fc18b43"
ideaExtPlugin = "1.1.9"
javaPoet = "1.+"
javaxInject = "1"
jansi = "2.+"
jimfs = "1.+"
# 3.25.1 doesn't work with native image
# later versions don't work with native image
# (at least not without additional configuration; tested with 3.25.1 and 3.27.1)
jline = "3.23.0"
jmh = "1.+"
jmhPlugin = "0.6.6"
jmhPlugin = "0.7.2"
jsr305 = "3.+"
junit = "5.+"
kotlin = "1.7.10"
@@ -38,15 +40,16 @@ ktfmt = "0.44"
# replaces nuValidator's log4j dependency
# something related to log4j-1.2-api is apparently broken in 2.17.2
log4j = "2.17.1"
msgpack = "0.9.0"
nexusPublishPlugin = "1.3.0"
msgpack = "0.9.8"
nexusPublishPlugin = "2.0.0"
nuValidator = "20.+"
paguro = "3.+"
shadowPlugin = "8.1.1"
slf4j = "1.+"
# Breaking change in snakeYaml 2.6 (removing DumpSettingsBuilder::setScalarResolver), so pin to 2.5
# snakeYaml 2.6 removed DumpSettingsBuilder::setScalarResolver,
# which is used by the external YAML renderer (org.pkl.core.YamlRenderer)
snakeYaml = "2.5"
spotlessPlugin = "6.11.0"
spotlessPlugin = "6.25.0"
wiremock = "3.+"
[libraries] # ordered alphabetically

Binary file not shown.

View File

@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

7
gradlew vendored
View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

2
gradlew.bat vendored
View File

@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################

18
jbang-catalog.json Normal file
View File

@@ -0,0 +1,18 @@
{
"catalogs": {},
"aliases": {
"pkl": {
"script-ref": "org.pkl-lang:pkl-cli-java:0.27.2",
"java-agents": []
},
"pkl-codegen-java": {
"script-ref": "org.pkl-lang:pkl-codegen-java:0.27.2",
"java-agents": []
},
"pkl-codegen-kotlin": {
"script-ref": "org.pkl-lang:pkl-codegen-kotlin:0.27.2",
"java-agents": []
}
},
"templates": {}
}

View File

@@ -1,30 +1,30 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.ethlo.time:itu:1.8.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.github.ajalt.clikt:clikt-jvm:3.5.1=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.github.ajalt.clikt:clikt:3.5.1=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.ethlo.time:itu:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.github.ajalt.clikt:clikt-jvm:3.5.4=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.github.ajalt.clikt:clikt:3.5.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.github.jknack:handlebars-helpers:4.3.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.github.jknack:handlebars:4.3.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.errorprone:error_prone_annotations:2.26.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.errorprone:error_prone_annotations:2.28.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.guava:failureaccess:1.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.guava:guava:33.2.0-jre=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.guava:guava:33.3.1-jre=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.google.j2objc:j2objc-annotations:3.0.0=testCompileClasspath,testImplementationDependenciesMetadata
com.google.j2objc:j2objc-annotations:3.0.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.9.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.networknt:json-schema-validator:1.4.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.tunnelvisionlabs:antlr4-runtime:4.9.0=default,runtimeClasspath,testRuntimeClasspath
com.networknt:json-schema-validator:1.5.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
com.tunnelvisionlabs:antlr4-runtime:4.9.0=runtimeClasspath,testRuntimeClasspath
commons-fileupload:commons-fileupload:1.5=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
commons-io:commons-io:2.11.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.18=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
net.javacrumbs.json-unit:json-unit-core:2.38.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.javacrumbs.json-unit:json-unit-core:2.40.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.minidev:accessors-smart:2.5.1=testRuntimeClasspath
net.minidev:json-smart:2.5.1=testRuntimeClasspath
net.sf.jopt-simple:jopt-simple:5.0.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
@@ -32,37 +32,36 @@ org.apache.httpcomponents.client5:httpclient5:5.3.1=testCompileClasspath,testImp
org.apache.httpcomponents.core5:httpcore5-h2:5.2.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apache.httpcomponents.core5:httpcore5:5.2.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.checkerframework:checker-qual:3.42.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-common:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-hpack:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.26.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.checkerframework:checker-qual:3.43.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-common:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-hpack:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-server:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-java-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-java-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-bom:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-http:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-io:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-proxy:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-security:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-servlet:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-servlets:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-util:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-webapp:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-xml:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.fusesource.jansi:jansi:2.4.0=default
org.eclipse.jetty:jetty-alpn-client:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-java-client:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-java-server:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-server:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-bom:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-client:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-http:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-io:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-proxy:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-security:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-server:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-servlet:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-servlets:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-util:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-webapp:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-xml:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.fusesource.jansi:jansi:2.4.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.compiler:compiler:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:native-image-base:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:objectfile:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:pointsto:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:svm:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.sdk:graal-sdk:23.0.2=compileClasspath,compileOnlyDependenciesMetadata,default,runtimeClasspath,testRuntimeClasspath
org.graalvm.truffle:truffle-api:23.0.2=compileClasspath,compileOnlyDependenciesMetadata,default,runtimeClasspath,testRuntimeClasspath
org.graalvm.compiler:compiler:23.0.6=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:native-image-base:23.0.6=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:objectfile:23.0.6=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:pointsto:23.0.6=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.nativeimage:svm:23.0.6=compileClasspath,compileOnlyDependenciesMetadata
org.graalvm.sdk:graal-sdk:23.0.6=compileClasspath,compileOnlyDependenciesMetadata,runtimeClasspath,testRuntimeClasspath
org.graalvm.truffle:truffle-api:23.0.6=compileClasspath,compileOnlyDependenciesMetadata,runtimeClasspath,testRuntimeClasspath
org.hamcrest:hamcrest-core:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.hamcrest:hamcrest:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
@@ -75,30 +74,29 @@ org.jetbrains.kotlin:kotlin-scripting-common:1.7.10=kotlinCompilerPluginClasspat
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-scripting-jvm:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains:annotations:13.0=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-native:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-reader:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-terminal-jansi:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-terminal:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.msgpack:msgpack-core:0.9.0=default,runtimeClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains:annotations:13.0=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-native:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-reader:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-terminal-jansi:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-terminal:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-engine:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.jupiter:junit-jupiter-params:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit.platform:junit-platform-engine:1.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.junit:junit-bom:5.11.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
org.organicdesign:Paguro:3.10.3=default,runtimeClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:2.0.11=testRuntimeClasspath
org.slf4j:slf4j-api:2.0.9=testCompileClasspath,testImplementationDependenciesMetadata
org.snakeyaml:snakeyaml-engine:2.5=default,runtimeClasspath,testRuntimeClasspath
org.wiremock:wiremock:3.6.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:2.0.13=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.snakeyaml:snakeyaml-engine:2.5=runtimeClasspath,testRuntimeClasspath
org.wiremock:wiremock:3.9.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.xmlunit:xmlunit-core:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.xmlunit:xmlunit-legacy:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.xmlunit:xmlunit-placeholders:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.yaml:snakeyaml:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,archives,compile,intransitiveDependenciesMetadata,javaExecutable,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeOnlyDependenciesMetadata,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64Executable,stagedLinuxAarch64Executable,stagedLinuxAmd64Executable,stagedMacAarch64Executable,stagedMacAmd64Executable,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
empty=annotationProcessor,archives,compile,intransitiveDependenciesMetadata,javaExecutable,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeOnlyDependenciesMetadata,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64Executable,stagedLinuxAarch64Executable,stagedLinuxAmd64Executable,stagedMacAarch64Executable,stagedMacAmd64Executable,stagedWindowsAmd64Executable,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime

View File

@@ -1,6 +1,18 @@
import java.security.KeyStore
import java.security.cert.CertificateFactory
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
pklAllProjects
pklKotlinLibrary
@@ -10,11 +22,9 @@ plugins {
// already on build script class path (see buildSrc/build.gradle.kts),
// hence must only specify plugin ID here
@Suppress("DSL_SCOPE_VIOLATION")
id(libs.plugins.shadow.get().pluginId)
@Suppress("DSL_SCOPE_VIOLATION") id(libs.plugins.shadow.get().pluginId)
@Suppress("DSL_SCOPE_VIOLATION")
alias(libs.plugins.checksum)
@Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.checksum)
}
// make Java executable available to other subprojects
@@ -38,8 +48,6 @@ val stagedLinuxAarch64Executable: Configuration by configurations.creating
val stagedAlpineLinuxAmd64Executable: Configuration by configurations.creating
val stagedWindowsAmd64Executable: Configuration by configurations.creating
val certs: SourceSet by sourceSets.creating
dependencies {
compileOnly(libs.svm)
@@ -74,17 +82,13 @@ dependencies {
}
tasks.jar {
manifest {
attributes += mapOf("Main-Class" to "org.pkl.cli.Main")
}
manifest { attributes += mapOf("Main-Class" to "org.pkl.cli.Main") }
// not required at runtime
exclude("org/pkl/cli/svm/**")
}
tasks.javadoc {
enabled = false
}
tasks.javadoc { enabled = false }
tasks.shadowJar {
archiveFileName.set("jpkl")
@@ -98,99 +102,74 @@ tasks.shadowJar {
exclude("module-info.*")
}
val javaExecutable by tasks.registering(ExecutableJar::class) {
inJar.set(tasks.shadowJar.flatMap { it.archiveFile })
outJar.set(layout.buildDirectory.file("executable/jpkl"))
val javaExecutable by
tasks.registering(ExecutableJar::class) {
inJar.set(tasks.shadowJar.flatMap { it.archiveFile })
outJar.set(layout.buildDirectory.file("executable/jpkl"))
// uncomment for debugging
//jvmArgs.addAll("-ea", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
}
// uncomment for debugging
// jvmArgs.addAll("-ea", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
}
val testJavaExecutable by tasks.registering(Test::class) {
testClassesDirs = tasks.test.get().testClassesDirs
classpath =
// compiled test classes
sourceSets.test.get().output +
// java executable
javaExecutable.get().outputs.files +
// test-only dependencies
// (test dependencies that are also main dependencies must already be contained in java executable;
// to verify that, we don't want to include them here)
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
}
val testJavaExecutable by
tasks.registering(Test::class) {
testClassesDirs = tasks.test.get().testClassesDirs
classpath =
// compiled test classes
sourceSets.test.get().output +
// java executable
javaExecutable.get().outputs.files +
// test-only dependencies
// (test dependencies that are also main dependencies must already be contained in java
// executable;
// to verify that, we don't want to include them here)
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
}
tasks.check {
dependsOn(testJavaExecutable)
}
tasks.check { dependsOn(testJavaExecutable) }
// 0.14 Java executable was broken because javaExecutable.jvmArgs wasn't commented out.
// To catch this and similar problems, test that Java executable starts successfully.
val testStartJavaExecutable by tasks.registering(Exec::class) {
dependsOn(javaExecutable)
val outputFile =
layout.buildDirectory.file("testStartJavaExecutable") // dummy output to satisfy up-to-date check
outputs.file(outputFile)
val testStartJavaExecutable by
tasks.registering(Exec::class) {
dependsOn(javaExecutable)
val outputFile =
layout.buildDirectory.file(
"testStartJavaExecutable"
) // dummy output to satisfy up-to-date check
outputs.file(outputFile)
if (buildInfo.os.isWindows) {
executable = "java"
args("-jar", javaExecutable.get().outputs.files.singleFile.toString(), "--version")
} else {
executable = javaExecutable.get().outputs.files.singleFile.toString()
args("--version")
if (buildInfo.os.isWindows) {
executable = "java"
args("-jar", javaExecutable.get().outputs.files.singleFile.toString(), "--version")
} else {
executable = javaExecutable.get().outputs.files.singleFile.toString()
args("--version")
}
doFirst { outputFile.get().asFile.delete() }
doLast { outputFile.get().asFile.writeText("OK") }
}
doFirst { outputFile.get().asFile.delete() }
doLast { outputFile.get().asFile.writeText("OK") }
}
tasks.check {
dependsOn(testStartJavaExecutable)
}
val trustStore = layout.buildDirectory.dir("generateTrustStore/PklCARoots.p12")
val trustStorePassword = "password" // no sensitive data to protect
// generate a trust store for Pkl's built-in CA certificates
val generateTrustStore by tasks.registering {
inputs.file(certs.resources.singleFile)
outputs.file(trustStore)
doLast {
val certificates = certs.resources.singleFile.inputStream().use { stream ->
CertificateFactory.getInstance("X.509").generateCertificates(stream)
}
KeyStore.getInstance("PKCS12").apply {
load(null, trustStorePassword.toCharArray()) // initialize empty trust store
for ((index, certificate) in certificates.withIndex()) {
setCertificateEntry("cert-$index", certificate)
}
val trustStoreFile = trustStore.get().asFile
trustStoreFile.parentFile.mkdirs()
trustStoreFile.outputStream().use { stream ->
store(stream, trustStorePassword.toCharArray())
}
}
}
}
tasks.check { dependsOn(testStartJavaExecutable) }
fun Exec.configureExecutable(
graalVm: BuildInfo.GraalVm,
outputFile: Provider<RegularFile>,
extraArgs: List<String> = listOf()
) {
dependsOn(generateTrustStore)
inputs.files(sourceSets.main.map { it.output })
inputs
.files(sourceSets.main.map { it.output })
.withPropertyName("mainSourceSets")
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.files(configurations.runtimeClasspath)
inputs
.files(configurations.runtimeClasspath)
.withPropertyName("runtimeClasspath")
.withNormalizer(ClasspathNormalizer::class)
val nativeImageCommandName = if (buildInfo.os.isWindows) "native-image.cmd" else "native-image"
inputs.files(
file(graalVm.baseDir)
.resolve("bin/$nativeImageCommandName")
)
inputs
.files(file(graalVm.baseDir).resolve("bin/$nativeImageCommandName"))
.withPropertyName("graalVmNativeImage")
.withPathSensitivity(PathSensitivity.ABSOLUTE)
outputs.file(outputFile)
@@ -202,99 +181,109 @@ fun Exec.configureExecutable(
// JARs to exclude from the class path for the native-image build.
val exclusions = listOf(libs.truffleApi, libs.graalSdk).map { it.get().module.name }
// https://www.graalvm.org/22.0/reference-manual/native-image/Options/
argumentProviders.add(CommandLineArgumentProvider {
buildList {
// currently gives a deprecation warning, but we've been told
// that the "initialize everything at build time" *CLI* option is likely here to stay
add("--initialize-at-build-time=")
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
add("--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess")
add("--no-fallback")
add("-Djavax.net.ssl.trustStore=${trustStore.get().asFile}")
add("-Djavax.net.ssl.trustStorePassword=$trustStorePassword")
add("-Djavax.net.ssl.trustStoreType=PKCS12")
// security property "ocsp.enable=true" is set in Main.kt
add("-Dcom.sun.net.ssl.checkRevocation=true")
add("-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl")
add("-H:IncludeResources=org/jline/utils/.*")
add("-H:IncludeResourceBundles=org.pkl.core.errorMessages")
add("--macro:truffle")
add("-H:Class=org.pkl.cli.Main")
add("-H:Name=${outputFile.get().asFile.name}")
// the actual limit (currently) used by native-image is this number + 1400 (idea is to compensate for Truffle's own nodes)
add("-H:MaxRuntimeCompileMethods=1800")
add("-H:+EnforceMaxRuntimeCompileMethods")
add("--enable-url-protocols=http,https")
add("-H:+ReportExceptionStackTraces")
// disable automatic support for JVM CLI options (puts our main class in full control of argument parsing)
add("-H:-ParseRuntimeOptions")
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower) executable
if (!buildInfo.isReleaseBuild) {
add("-Ob")
argumentProviders.add(
CommandLineArgumentProvider {
buildList {
// currently gives a deprecation warning, but we've been told
// that the "initialize everything at build time" *CLI* option is likely here to stay
add("--initialize-at-build-time=")
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
add("--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess")
add("--no-fallback")
add("-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl")
add("-H:IncludeResources=org/jline/utils/.*")
add("-H:IncludeResourceBundles=org.pkl.core.errorMessages")
add("-H:IncludeResources=org/pkl/commons/cli/PklCARoots.pem")
add("--macro:truffle")
add("-H:Class=org.pkl.cli.Main")
add("-H:Name=${outputFile.get().asFile.name}")
// the actual limit (currently) used by native-image is this number + 1400 (idea is to
// compensate for Truffle's own nodes)
add("-H:MaxRuntimeCompileMethods=1800")
add("-H:+EnforceMaxRuntimeCompileMethods")
add("--enable-url-protocols=http,https")
add("-H:+ReportExceptionStackTraces")
// disable automatic support for JVM CLI options (puts our main class in full control of
// argument parsing)
add("-H:-ParseRuntimeOptions")
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower)
// executable
if (!buildInfo.isReleaseBuild) {
add("-Ob")
}
add("-march=compatibility")
// native-image rejects non-existing class path entries -> filter
add("--class-path")
val pathInput =
sourceSets.main.get().output +
configurations.runtimeClasspath.get().filter {
it.exists() && !exclusions.any { exclude -> it.name.contains(exclude) }
}
add(pathInput.asPath)
// make sure dev machine stays responsive (15% slowdown on my laptop)
val processors =
Runtime.getRuntime().availableProcessors() /
if (buildInfo.os.isMacOsX && !buildInfo.isCiBuild) 4 else 1
add("-J-XX:ActiveProcessorCount=${processors}")
// Pass through all `HOMEBREW_` prefixed environment variables to allow build with shimmed
// tools.
addAll(environment.keys.filter { it.startsWith("HOMEBREW_") }.map { "-E$it" })
addAll(extraArgs)
}
// native-image rejects non-existing class path entries -> filter
add("--class-path")
val pathInput = sourceSets.main.get().output + configurations.runtimeClasspath.get()
.filter { it.exists() && !exclusions.any { exclude -> it.name.contains(exclude) } }
add(pathInput.asPath)
// make sure dev machine stays responsive (15% slowdown on my laptop)
val processors = Runtime.getRuntime().availableProcessors() /
if (buildInfo.os.isMacOsX && !buildInfo.isCiBuild) 4 else 1
add("-J-XX:ActiveProcessorCount=${processors}")
addAll(extraArgs)
}
})
}
/**
* Builds the pkl CLI for macOS/amd64.
*/
val macExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-macos-amd64")
)
}
/**
* Builds the pkl CLI for macOS/aarch64.
*/
val macExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAarch64")
configureExecutable(
buildInfo.graalVmAarch64,
layout.buildDirectory.file("executable/pkl-macos-aarch64"),
listOf(
"-H:+AllowDeprecatedBuilderClassesOnImageClasspath"
/** Builds the pkl CLI for macOS/amd64. */
val macExecutableAmd64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-macos-amd64")
)
)
}
}
/**
* Builds the pkl CLI for linux/amd64.
*/
val linuxExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-linux-amd64")
)
}
/** Builds the pkl CLI for macOS/aarch64. */
val macExecutableAarch64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAarch64")
configureExecutable(
buildInfo.graalVmAarch64,
layout.buildDirectory.file("executable/pkl-macos-aarch64"),
listOf("-H:+AllowDeprecatedBuilderClassesOnImageClasspath")
)
}
/** Builds the pkl CLI for linux/amd64. */
val linuxExecutableAmd64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-linux-amd64")
)
}
/**
* Builds the pkl CLI for linux/aarch64.
*
* Right now, this is built within a container on Mac using emulation because CI does not have
* ARM instances.
* Right now, this is built within a container on Mac using emulation because CI does not have ARM
* instances.
*/
val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAarch64")
configureExecutable(
buildInfo.graalVmAarch64,
layout.buildDirectory.file("executable/pkl-linux-aarch64")
)
}
val linuxExecutableAarch64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAarch64")
configureExecutable(
buildInfo.graalVmAarch64,
layout.buildDirectory.file("executable/pkl-linux-aarch64"),
listOf(
// Ensure compatibility for kernels with page size set to 4k, 16k and 64k
// (e.g. Raspberry Pi 5, Asahi Linux)
"-H:PageSize=65536"
)
)
}
/**
* Builds a statically linked CLI for linux/amd64.
@@ -302,23 +291,25 @@ val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class)
* Note: we don't publish the same for linux/aarch64 because native-image doesn't support this.
* Details: https://www.graalvm.org/22.0/reference-manual/native-image/ARM64/
*/
val alpineExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
listOf("--static", "--libc=musl")
)
}
val alpineExecutableAmd64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
listOf("--static", "--libc=musl")
)
}
val windowsExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-windows-amd64"),
listOf("-Dfile.encoding=UTF-8", "-march=compatibility")
)
}
val windowsExecutableAmd64: TaskProvider<Exec> by
tasks.registering(Exec::class) {
dependsOn(":installGraalVmAmd64")
configureExecutable(
buildInfo.graalVmAmd64,
layout.buildDirectory.file("executable/pkl-windows-amd64"),
listOf("-Dfile.encoding=UTF-8")
)
}
tasks.assembleNative {
when {
@@ -328,15 +319,12 @@ tasks.assembleNative {
dependsOn(macExecutableAarch64)
}
}
buildInfo.os.isWindows -> {
dependsOn(windowsExecutableAmd64)
}
buildInfo.os.isLinux && buildInfo.arch == "aarch64" -> {
dependsOn(linuxExecutableAarch64)
}
buildInfo.os.isLinux && buildInfo.arch == "amd64" -> {
dependsOn(linuxExecutableAmd64)
if (buildInfo.hasMuslToolchain) {
@@ -347,7 +335,8 @@ tasks.assembleNative {
}
// make Java executable available to other subprojects
// (we don't do the same for native executables because we don't want tasks assemble/build to build them)
// (we don't do the same for native executables because we don't want tasks assemble/build to build
// them)
artifacts {
add("javaExecutable", javaExecutable.map { it.outputs.files.singleFile }) {
name = "pkl-cli-java"
@@ -357,7 +346,7 @@ artifacts {
}
}
//region Maven Publishing
// region Maven Publishing
publishing {
publications {
register<MavenPublication>("javaExecutable") {
@@ -376,7 +365,8 @@ publishing {
Pkl CLI executable for Java.
Can be executed directly on *nix (if the `java` command is found on the PATH) and with `java -jar` otherwise.
Requires Java 17 or higher.
""".trimIndent()
"""
.trimIndent()
)
}
}
@@ -470,5 +460,4 @@ signing {
sign(publishing.publications["macExecutableAmd64"])
sign(publishing.publications["alpineLinuxExecutableAmd64"])
sign(publishing.publications["windowsExecutableAmd64"])
}
//endregion
} // endregion

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,10 +28,10 @@ import org.pkl.commons.cli.CliException
import org.pkl.commons.createParentDirectories
import org.pkl.commons.currentWorkingDir
import org.pkl.commons.writeString
import org.pkl.core.Closeables
import org.pkl.core.EvaluatorBuilder
import org.pkl.core.ModuleSource
import org.pkl.core.PklException
import org.pkl.core.module.ModuleKeyFactories
import org.pkl.core.module.ModulePathResolver
import org.pkl.core.runtime.ModuleResolver
import org.pkl.core.runtime.VmException
@@ -51,9 +51,10 @@ constructor(
private val consoleWriter: Writer = System.out.writer(),
) : CliCommand(options.base) {
/**
* Output files for the modules to be evaluated. Returns `null` if `options.outputPath` is `null`.
* Multiple modules may be mapped to the same output file, in which case their outputs are
* concatenated with [CliEvaluatorOptions.moduleOutputSeparator].
* Output files for the modules to be evaluated. Returns `null` if `options.outputPath` is `null`
* or if `options.multipleFileOutputPath` is not `null`. Multiple modules may be mapped to the
* same output file, in which case their outputs are concatenated with
* [CliEvaluatorOptions.moduleOutputSeparator].
*/
@Suppress("MemberVisibilityCanBePrivate")
val outputFiles: Set<File>? by lazy {
@@ -99,7 +100,8 @@ constructor(
writeOutput(builder)
}
} finally {
ModuleKeyFactories.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
}
}
@@ -118,7 +120,7 @@ constructor(
try {
moduleResolver.resolve(uri)
} catch (e: VmException) {
throw e.toPklException(stackFrameTransformer)
throw e.toPklException(stackFrameTransformer, options.base.color?.hasColor() ?: false)
}
val substituted =
pathStr

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -0,0 +1,80 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.cli
import java.io.Writer
import org.pkl.commons.cli.CliCommand
import org.pkl.commons.createParentDirectories
import org.pkl.commons.writeString
import org.pkl.core.Closeables
import org.pkl.core.ModuleSource
class CliImportAnalyzer
@JvmOverloads
constructor(
private val options: CliImportAnalyzerOptions,
private val consoleWriter: Writer = System.out.writer()
) : CliCommand(options.base) {
override fun doRun() {
val rendered = render()
if (options.outputPath != null) {
options.outputPath.createParentDirectories()
options.outputPath.writeString(rendered)
} else {
consoleWriter.write(rendered)
consoleWriter.flush()
}
}
// language=pkl
private val sourceModule =
ModuleSource.text(
"""
import "pkl:analyze"
local importStrings = read*("prop:pkl.analyzeImports.**").toMap().values.toSet()
output {
value = analyze.importGraph(importStrings)
renderer {
converters {
[Map] = (it) -> it.toMapping()
[Set] = (it) -> it.toListing()
}
}
}
"""
.trimIndent()
)
private fun render(): String {
val builder = evaluatorBuilder().setOutputFormat(options.outputFormat)
try {
return builder
.apply {
for ((idx, sourceModule) in options.base.normalizedSourceModules.withIndex()) {
addExternalProperty("pkl.analyzeImports.$idx", sourceModule.toString())
}
}
.build()
.use { it.evaluateOutputText(sourceModule) }
} finally {
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.cli
import java.nio.file.Path
import org.pkl.commons.cli.CliBaseOptions
data class CliImportAnalyzerOptions(
/** Base options shared between CLI commands. */
val base: CliBaseOptions,
/** The file path where the output file is placed. */
val outputPath: Path? = null,
/**
* The output format to generate.
*
* These accept the same options as [CliEvaluatorOptions.outputFormat].
*/
val outputFormat: String? = null,
)

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,7 +35,7 @@ abstract class CliProjectCommand(cliOptions: CliBaseOptions, private val project
)
return@lazy listOf(projectFile.normalize())
}
projectDirs.map { dir ->
projectDirs.map(cliOptions.normalizedWorkingDir::resolve).map { dir ->
val projectFile = dir.resolve(PKL_PROJECT_FILENAME)
if (!Files.exists(projectFile)) {
throw CliException("Directory $dir does not contain a PklProject file.")

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,6 +81,7 @@ class CliProjectPackager(
cliOptions.normalizedWorkingDir,
outputPath,
stackFrameTransformer,
cliOptions.color?.hasColor() ?: false,
securityManager,
httpClient,
skipPublishCheck,

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -66,7 +66,8 @@ internal class CliRepl(private val options: CliEvaluatorOptions) : CliCommand(op
project?.dependencies,
options.outputFormat,
options.base.normalizedWorkingDir,
stackFrameTransformer
stackFrameTransformer,
options.base.color?.hasColor() ?: false,
)
Repl(options.base.normalizedWorkingDir, server).run()
}

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,14 +18,13 @@ package org.pkl.cli
import org.pkl.commons.cli.CliBaseOptions
import org.pkl.commons.cli.CliCommand
import org.pkl.commons.cli.CliException
import org.pkl.server.MessageTransports
import org.pkl.server.ProtocolException
import org.pkl.core.messaging.ProtocolException
import org.pkl.server.Server
class CliServer(options: CliBaseOptions) : CliCommand(options) {
override fun doRun() =
try {
val server = Server(MessageTransports.stream(System.`in`, System.out))
val server = Server.stream(System.`in`, System.out)
server.use { it.start() }
} catch (e: ProtocolException) {
throw CliException(e.message!!)

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,9 +17,10 @@ package org.pkl.cli
import java.io.Writer
import org.pkl.commons.cli.*
import org.pkl.core.Closeables
import org.pkl.core.EvaluatorBuilder
import org.pkl.core.ModuleSource.uri
import org.pkl.core.module.ModuleKeyFactories
import org.pkl.core.TestResults
import org.pkl.core.stdlib.test.report.JUnitReport
import org.pkl.core.stdlib.test.report.SimpleReport
import org.pkl.core.util.ErrorMessages
@@ -38,7 +39,8 @@ constructor(
try {
evalTest(builder)
} finally {
ModuleKeyFactories.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
}
}
@@ -59,14 +61,22 @@ constructor(
val evaluator = builder.build()
evaluator.use {
var failed = false
var isExampleWrittenFailure = true
val moduleNames = mutableSetOf<String>()
for (moduleUri in sources) {
val reporter = SimpleReport(useColor)
val allTestResults = mutableListOf<TestResults>()
for ((idx, moduleUri) in sources.withIndex()) {
try {
val results = evaluator.evaluateTest(uri(moduleUri), testOptions.overwrite)
allTestResults.add(results)
if (!failed) {
failed = results.failed()
isExampleWrittenFailure = results.isExampleWrittenFailure.and(isExampleWrittenFailure)
}
reporter.report(results, consoleWriter)
if (sources.size > 1 && idx != sources.size - 1) {
consoleWriter.append('\n')
}
SimpleReport().report(results, consoleWriter)
consoleWriter.flush()
val junitDir = testOptions.junitDir
if (junitDir != null) {
@@ -96,8 +106,12 @@ constructor(
failed = true
}
}
consoleWriter.append('\n')
reporter.summarize(allTestResults, consoleWriter)
consoleWriter.flush()
if (failed) {
throw CliTestException(ErrorMessages.create("testsFailed"))
val exitCode = if (isExampleWrittenFailure) 10 else 1
throw CliTestException(ErrorMessages.create("testsFailed"), exitCode)
}
}
}

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,8 @@ internal fun main(args: Array<String>) {
ServerCommand(helpLink),
TestCommand(helpLink),
ProjectCommand(helpLink),
DownloadPackageCommand(helpLink)
DownloadPackageCommand(helpLink),
AnalyzeCommand(helpLink),
)
.main(args)
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.cli.commands
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.path
import java.nio.file.Path
import org.pkl.cli.CliImportAnalyzer
import org.pkl.cli.CliImportAnalyzerOptions
import org.pkl.commons.cli.commands.ModulesCommand
import org.pkl.commons.cli.commands.single
class AnalyzeCommand(helpLink: String) :
NoOpCliktCommand(
name = "analyze",
help = "Commands related to static analysis",
epilog = "For more information, visit $helpLink"
) {
init {
subcommands(AnalyzeImportsCommand(helpLink))
}
companion object {
class AnalyzeImportsCommand(helpLink: String) :
ModulesCommand(
name = "imports",
helpLink = helpLink,
help = "Prints the the graph of modules imported by the input module(s)."
) {
private val outputPath: Path? by
option(
names = arrayOf("-o", "--output-path"),
metavar = "<path>",
help = "File path where the output file is placed."
)
.path()
.single()
override fun run() {
val options =
CliImportAnalyzerOptions(
base = baseOptions.baseOptions(modules, projectOptions),
outputFormat = baseOptions.format,
outputPath = outputPath
)
CliImportAnalyzer(options).run()
}
}
}
}

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1457,6 +1457,62 @@ result = someLib.x
assertThat(output).isEqualTo("result = 1\n")
}
@Test
fun `eval file with non-ASCII name`() {
val tempDirUri = tempDir.toUri()
val dir = tempDir.resolve("🤬").createDirectory()
val file =
writePklFile(
dir.resolve("日本語.pkl").toString(),
"""
日本語 = "Japanese language"
readDir = read(".").text
readDirFile = read("$tempDirUri🤬").text
readOne = read("日本語.pkl").text.split("\n").first
readOneFile = read("$tempDirUri🤬/日本語.pkl").text.split("\n").first
readGlob = read*("./日*.pkl").keys
readGlobFile = read*("$tempDirUri**/*.pkl").keys.map((it) -> it.replaceAll("$tempDirUri".replaceAll("///", "/"), ""))
importOne = import("日本語.pkl").readOne
importOneFile = import("$tempDirUri🤬/日本語.pkl").日本語
importGlob = import*("./日*.pkl").keys
importGlobFile = import*("$tempDirUri**/*.pkl").keys.map((it) -> it.replaceAll("$tempDirUri".replaceAll("///", "/"), ""))
"""
.trimIndent()
)
val output =
evalToConsole(
CliEvaluatorOptions(
CliBaseOptions(sourceModules = listOf(file)),
)
)
val tripleQuote = "\"\"\""
assertThat(output)
.isEqualTo(
"""
日本語 = "Japanese language"
readDir = $tripleQuote
日本語.pkl
$tripleQuote
readDirFile = $tripleQuote
日本語.pkl
$tripleQuote
readOne = "日本語 = \"Japanese language\""
readOneFile = "日本語 = \"Japanese language\""
readGlob = Set("./日本語.pkl")
readGlobFile = Set("🤬/日本語.pkl")
importOne = "日本語 = \"Japanese language\""
importOneFile = "Japanese language"
importGlob = Set("./日本語.pkl")
importGlobFile = Set("🤬/日本語.pkl")
"""
.trimIndent()
)
}
private fun evalModuleThatImportsPackage(certsFile: Path?, testPort: Int = -1) {
val moduleUri =
writePklFile(

View File

@@ -0,0 +1,142 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.cli
import java.net.URI
import java.nio.file.Path
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatCode
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.pkl.commons.cli.CliBaseOptions
import org.pkl.commons.writeString
import org.pkl.core.OutputFormat
import org.pkl.core.util.StringBuilderWriter
class CliImportAnalyzerTest {
@Test
fun `write to console writer`(@TempDir tempDir: Path) {
val file = tempDir.resolve("test.pkl").writeString("import \"bar.pkl\"")
val otherFile = tempDir.resolve("bar.pkl").writeString("")
val baseOptions = CliBaseOptions(sourceModules = listOf(file.toUri()))
val sb = StringBuilder()
val analyzer = CliImportAnalyzer(CliImportAnalyzerOptions(baseOptions), StringBuilderWriter(sb))
analyzer.run()
assertThat(sb.toString())
.isEqualTo(
"""
imports {
["${otherFile.toUri()}"] {}
["${file.toUri()}"] {
new {
uri = "${otherFile.toUri()}"
}
}
}
resolvedImports {
["${otherFile.toUri()}"] = "${otherFile.toRealPath().toUri()}"
["${file.toUri()}"] = "${file.toRealPath().toUri()}"
}
"""
.trimIndent()
)
}
@Test
fun `different output format`(@TempDir tempDir: Path) {
val file = tempDir.resolve("test.pkl").writeString("import \"bar.pkl\"")
val otherFile = tempDir.resolve("bar.pkl").writeString("")
val baseOptions = CliBaseOptions(sourceModules = listOf(file.toUri()))
val sb = StringBuilder()
val analyzer =
CliImportAnalyzer(
CliImportAnalyzerOptions(baseOptions, outputFormat = OutputFormat.JSON.toString()),
StringBuilderWriter(sb)
)
analyzer.run()
assertThat(sb.toString())
.isEqualTo(
"""
{
"imports": {
"${otherFile.toUri()}": [],
"${file.toUri()}": [
{
"uri": "${otherFile.toUri()}"
}
]
},
"resolvedImports": {
"${otherFile.toUri()}": "${otherFile.toRealPath().toUri()}",
"${file.toUri()}": "${file.toRealPath().toUri()}"
}
}
"""
.trimIndent()
)
}
@Test
fun `write to output file`(@TempDir tempDir: Path) {
val file = tempDir.resolve("test.pkl").writeString("import \"bar.pkl\"")
val otherFile = tempDir.resolve("bar.pkl").writeString("")
val outputPath = tempDir.resolve("imports.pcf")
val baseOptions = CliBaseOptions(sourceModules = listOf(file.toUri()))
val analyzer = CliImportAnalyzer(CliImportAnalyzerOptions(baseOptions, outputPath = outputPath))
analyzer.run()
assertThat(outputPath)
.hasContent(
"""
imports {
["${otherFile.toUri()}"] {}
["${file.toUri()}"] {
new {
uri = "${otherFile.toUri()}"
}
}
}
resolvedImports {
["${otherFile.toUri()}"] = "${otherFile.toRealPath().toUri()}"
["${file.toUri()}"] = "${file.toRealPath().toUri()}"
}
"""
.trimIndent()
)
}
@Test
fun `invalid syntax in module`(@TempDir tempDir: Path) {
val file = tempDir.resolve("test.pkl").writeString("foo = bar(]")
assertThatCode {
CliImportAnalyzer(
CliImportAnalyzerOptions(
CliBaseOptions(sourceModules = listOf(file.toUri()), settings = URI("pkl:settings"))
)
)
.run()
}
.hasMessageContaining(
"""
Pkl Error
Found a syntax error when parsing module `${file.toUri()}`.
"""
.trimIndent()
)
}
}

Some files were not shown because too many files have changed in this diff Show More