Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: Move construction of test DAR files into the Makefile #94

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ jobs:
chmod 755 jq-linux64 && \
mv jq-linux64 /usr/bin/jq
- checkout
- restore_cache:
key: daml-sdk-0.13.32
- run:
command: curl -sSL https://get.daml.com/ | sh
- run:
command: PATH=$PATH:~/.daml/bin daml install 0.13.32
- save_cache:
key: daml-sdk-0.13.32
paths:
- "~/.daml"
- restore_cache:
key: deps9-{{ .Branch }}-{{ checksum "python/poetry.lock" }}
- run:
command: |
export PATH=$PATH:~/.daml/bin; \
source $HOME/.poetry/env && \
make -C python deps
- save_cache:
Expand All @@ -30,16 +41,19 @@ jobs:
- run:
name: Python unit tests
command: |
export PATH=$PATH:~/.daml/bin; \
source $HOME/.poetry/env && \
make -C python test
- run:
name: Python integration tests
command: |
export PATH=$PATH:~/.daml/bin; \
source $HOME/.poetry/env && \
make -C python integration-test
- run:
name: Python packaging
command: |
export PATH=$PATH:~/.daml/bin; \
source $HOME/.poetry/env && \
make -C python package
- run:
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cache_dir=.cache
daml_proto_version=0.13.56-snapshot.20200408.3877.0.1ddcd3c0

Expand All @@ -7,7 +10,6 @@ proto_dir := $(cache_dir)/protos
proto_manifest := $(proto_dir)/manifest.json
python := $(shell cd python && poetry env info -p)/bin/python3


$(download_protos_zip):
@mkdir -p $(@D)
curl -sSL https://github.com/digital-asset/daml/releases/download/v$(daml_proto_version)/protobufs-$(daml_proto_version).zip -o $@
Expand Down Expand Up @@ -48,7 +50,7 @@ build: ## Build everything.
make -C python build

.PHONY: test
test: ## Run all tests.
test: dars ## Run all tests.
make -C python test
make -C tests test

Expand All @@ -69,9 +71,15 @@ gen-python: .cache/make/python.mk ## Rebuild Python code-generated files.
fetch-protos: .cache/protos/protobufs-$(daml_proto_version).zip


.cache/make/dars.mk: _build/dar-mk
mkdir -p $(@D)
$^ > $@


.cache/make/python.mk: _build/make-template.py $(proto_manifest)
mkdir -p $(@D)
$^ > $@


include .cache/make/dars.mk
include .cache/make/python.mk
17 changes: 17 additions & 0 deletions _build/dar-mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Output a Make fragment that builds the dars in the _fixtures/src directory.

root_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null 2>&1 && pwd )"
cd $root_dir

dar_dirs=$(find _fixtures/src -mindepth 1 -maxdepth 1 | sort)
dars=$(for dar_dir in $dar_dirs; do echo -n " $dar_dir/.daml/dist/$(basename $dar_dir)-1.0.0.dar"; done)

echo ".PHONY: dars"
echo "dars:$dars"
for dar_dir in $dar_dirs; do
echo
echo $dar_dir/.daml/dist/$(basename $dar_dir)-1.0.0.dar: $dar_dir/daml.yaml $(find $dar_dir -name *.daml -type f)
echo -e "\tcd \$(<D) && daml build"
done
10 changes: 10 additions & 0 deletions _fixtures/src/all-kinds-of/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: all-kinds-of
version: 1.0.0
source: AllKindsOf.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
10 changes: 10 additions & 0 deletions _fixtures/src/all-party/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: all-party
version: 1.0.0
source: AllParty.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
10 changes: 10 additions & 0 deletions _fixtures/src/complicated/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: complicated
version: 1.0.0
source: Complicated.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
10 changes: 10 additions & 0 deletions _fixtures/src/dotted-fields/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: dotted-fields
version: 1.0.0
source: DottedFields.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
10 changes: 10 additions & 0 deletions _fixtures/src/map-support/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: map-support
version: 1.0.0
source: MapSupport.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
File renamed without changes.
10 changes: 10 additions & 0 deletions _fixtures/src/pending/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: pending
version: 1.0.0
source: Pending.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
File renamed without changes.
10 changes: 10 additions & 0 deletions _fixtures/src/simple/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: simple
version: 1.0.0
source: Simple.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
10 changes: 10 additions & 0 deletions _fixtures/src/test-server/daml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sdk-version: 0.13.32
name: test-server
version: 1.0.0
source: TestServer.daml
parties:
- Alice
- Bob
dependencies:
- daml-prim
- daml-stdlib
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

SHELL := /usr/bin/env bash
Expand Down
64 changes: 17 additions & 47 deletions python/tests/unit/dars.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""
Pre-cook the test DARs for this project.
"""

import logging
import time
from pathlib import Path
from typing import Dict, Mapping, Optional, Sequence
from typing import Mapping

from dazl import setup_default_logger
from dazl.damlsdk.fetch import ensure_sdk_component
from dazl.util.dar import build_dar
from dazl.util.io import find_nearest_ancestor

DAZL_ROOT = find_nearest_ancestor('.dazl-root', Path(__file__).resolve()).parent
Expand All @@ -23,55 +16,32 @@
setup_default_logger(logging.DEBUG)


def load_dars(damlc_version: 'Optional[str]' = None) -> 'Mapping[str, Path]':
def load_dars() -> 'Mapping[str, Path]':
"""
Ensure that the DARs in the test project are all pre-cooked.
"""
dars = dict() # type: Dict[str, Path]

if damlc_version is None:
damlc_version = '100.13.19'

ensure_sdk_component('damlc', damlc_version)

start_time = time.time()

# TODO: parallelize DAR building; this step still takes 40 seconds on my machine
daml_files: Sequence[Path] = list(DAML_ROOT.glob('*.daml'))
if not daml_files:
raise Exception(f'Could not find any DAML files under {DAML_ROOT}')

for daml_file in daml_files:
dar_file = CACHE_ROOT / damlc_version / (daml_file.stem + '.dar')
if dar_file.exists() and dar_file.stat().st_mtime >= daml_file.stat().st_mtime:
logging.info('Skipping building %s because it is newer than %s', dar_file, daml_file)
else:
dar_file.parent.mkdir(parents=True, exist_ok=True)
build_dar(daml_file, dar_file)

dars[daml_file.stem] = dar_file

end_time = time.time()
dar_dir = (DAZL_ROOT / '_fixtures/src') # type: Path

logging.info('Finished building %s test DARs in %.2f.', len(dars), end_time - start_time)
for dar_name, dar_file in dars.items():
logging.info(' %s: %s', dar_name, dar_file)
import subprocess
code = subprocess.run(['make', 'dars'], cwd=str(DAZL_ROOT))
if code.returncode != 0:
raise RuntimeError('Could not build test dars!')

return dars
return {d.name: d / f'.daml/dist/{d.name}-1.0.0.dar' for d in dar_dir.iterdir() if d.is_dir()}


DARS = load_dars()

# These are primarily defined so that we get good auto-complete in the IDE; it's also a way of
# enforcing that DARs we expect to exist, actually exist.
AllKindsOf = DARS['AllKindsOf']
AllParty = DARS['AllParty']
Complicated = DARS['Complicated']
DottedFields = DARS['DottedFields']
MapSupport = DARS['MapSupport']
Pending = DARS['Pending']
Simple = DARS['Simple']
TestServer = DARS['TestServer']
AllKindsOf = DARS['all-kinds-of']
AllParty = DARS['all-party']
Complicated = DARS['complicated']
DottedFields = DARS['dotted-fields']
MapSupport = DARS['map-support']
Pending = DARS['pending']
Simple = DARS['simple']
TestServer = DARS['test-server']


if __name__ == '__main__':
Expand Down