aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/ninja.py25
-rw-r--r--src/ee/tools/templates/build.ninja.j290
2 files changed, 58 insertions, 57 deletions
diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py
index a26a474..aa6952b 100644
--- a/src/ee/tools/ninja.py
+++ b/src/ee/tools/ninja.py
@@ -8,7 +8,18 @@ from jinja2 import Environment, PackageLoader, select_autoescape
import ee.tools
from ee.kicad import read_schematics
-from ee.project import Project
+from ee.project import Project, SupplierDescriptor
+
+
+class NinjaSupplier(object):
+ def __init__(self, project: Project, supplier: SupplierDescriptor):
+ self.project = project
+ self.supplier = supplier
+ self.key = supplier.key
+
+ @property
+ def part_db(self):
+ return "$public_dir/{}/parts.xml".format(self.key)
def ninja_path_filter(s: Union[Path, str, List[str]]) -> str:
@@ -54,16 +65,14 @@ def generate(project: Project):
e.filters["noext"] = noext_filter
return e
- part_dbs = []
params = {
"ee": "{} -m ee".format(os.path.relpath(sys.executable, Path("."))),
"project": project,
- "part_dbs": part_dbs,
"souffle_ee_src": str(Path(__file__).parent.parent / "souffle"),
"is_file": lambda p: os.path.isfile(str(p)),
}
- kicad_souffle_dl = project.project_dir / "ee" / "custom" / "kicad-souffle.dl"
+ kicad_souffle_dl = project.public_dir / "custom" / "kicad-souffle.dl"
if kicad_souffle_dl.is_file():
params["kicad_souffle_dl"] = str(kicad_souffle_dl)
@@ -84,9 +93,7 @@ def generate(project: Project):
params["pcb"] = Path(project.cfg["kicad-project"]["pcb"])
gerber_zip = "prod/gerber.zip"
- # TODO: read from config
- distributors = ["digikey"]
- params["distributors"] = distributors
+ params["suppliers"] = [NinjaSupplier(project, s) for s in project.suppliers]
if gerber_zip is not None:
params["gerber_zip"] = gerber_zip
@@ -98,10 +105,6 @@ def generate(project: Project):
parts_yaml_files = [path for path in project.project_dir.iterdir() if str(path).endswith("-parts.yaml")]
params["parts_yaml_files"] = parts_yaml_files
- # Local part databases first
- part_dbs.extend([parent_dir_filter(p) / noext_filter(p) for p in parts_yaml_files])
- part_dbs.extend([Path("ee") / d / "parts" for d in distributors])
-
if not build_ninja.exists():
with build_ninja.open("w") as f:
f.writelines(["# This file was generated by eetools. Add your own rules and build commands\n",
diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2
index d742791..9fff519 100644
--- a/src/ee/tools/templates/build.ninja.j2
+++ b/src/ee/tools/templates/build.ninja.j2
@@ -1,6 +1,7 @@
{% set reports=[] -%}
ee = {{ ee }}
uuid = {{ project.uuid }}
+public_dir = {{ project.public_dir }}
report_dir = {{ project.report_dir }}
{%- if sch is defined %}
sch = {{ sch | ninja_path }}
@@ -56,7 +57,7 @@ rule create-bom
command = $ee create-bom {{ log }} --schematic $schematic --part-db $part_dbs --out $out $strategy
rule split-parts-by-supplier
- command = $ee split-parts-by-supplier {{ log }} --parts $order $part_dbs --out-dir $out_dir
+ command = $ee split-parts-by-supplier {{ log }} --parts $in --out $out $part_dbs
rule import-parts-yaml
description = import-parts-yaml $in
@@ -84,9 +85,9 @@ default gerbers
{% if sch is defined -%}
{%- set cfg = project.cfg["kicad-project"] %}
-build ee/kicad/sch.xml: kicad-make-bom $sch
+build $public_dir/kicad/sch.xml: kicad-make-bom $sch
{#
-build ee/sch.xml: part-apply-function ee/kicad/sch.xml
+build $public_dir/sch.xml: part-apply-function $public_dir/kicad/sch.xml
execution = kicad
{%- if cfg and "functions" in cfg and cfg["functions"] %}
functions = --function {{ cfg["functions"] }}
@@ -96,42 +97,42 @@ build ee/sch.xml: part-apply-function ee/kicad/sch.xml
{%- endif %}
#}
-build ee/kicad/souffle/facts.dl: part-apply-souffle-pre ee/kicad/sch.xml
- work = ee/kicad/souffle
+build $public_dir/kicad/souffle/facts.dl: part-apply-souffle-pre $public_dir/kicad/sch.xml
+ work = $public_dir/kicad/souffle
-build ee/kicad/souffle/out/fact.csv: souffle {{ kicad_souffle_dl if kicad_souffle_dl else souffle_ee_src + "/kicad.dl" }} | ee/kicad/souffle/facts.dl
- work = ee/kicad/souffle
+build $public_dir/kicad/souffle/out/fact.csv: souffle {{ kicad_souffle_dl if kicad_souffle_dl else souffle_ee_src + "/kicad.dl" }} | $public_dir/kicad/souffle/facts.dl
+ work = $public_dir/kicad/souffle
{#- includes = {{ (souffle_ee_src + "/kicad.dl") if kicad_souffle_dl else "" }}#}
-build ee/sch.xml: part-apply-souffle-post ee/kicad/souffle/out/fact.csv
- in_sch = ee/kicad/sch.xml
- work = ee/kicad/souffle
+build $public_dir/sch.xml: part-apply-souffle-post $public_dir/kicad/souffle/out/fact.csv
+ in_sch = $public_dir/kicad/sch.xml
+ work = $public_dir/kicad/souffle
{%- endif %}
-build $report_dir/part-validate-parts.rst: part-validate-parts ee/bom.xml ee/sch.xml
- sch = ee/sch.xml
- bom = ee/bom.xml
- part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %}
+build $report_dir/part-validate-parts.rst: part-validate-parts $public_dir/bom.xml $public_dir/sch.xml
+ sch = $public_dir/sch.xml
+ bom = $public_dir/bom.xml
+ part_dbs ={%- for s in suppliers %} {{ s.part_db }}{% endfor %}
{%- set reports=reports+["$report_dir/part-validate-parts.rst"] %}
{#- TODO: complete
-build ee/requirements.xml | $report_dir/requirements.rst: part-find-requirements ee/sch.xml
+build $public_dir/requirements.xml | $report_dir/requirements.rst: part-find-requirements $public_dir/sch.xml
report = --report $report_dir/requirements.rst
{%- set reports=reports+["$report_dir/requirements.rst"] %}
#}
-{% for s in distributors %}
-{%- set cfg = project.cfg["supplier:" + s] if "supplier:" + s in project.cfg else None %}
-# Supplier {{ s }}
-build ee/{{ s }}/pn-part-search-list.xml: pn-part-search-list ee/sch.xml
- supplier = {{ s }}
+{% for s in suppliers %}
+{%- set cfg = project.cfg["supplier:" + s.key] if "supplier:" + s.key in project.cfg else None %}
+# Supplier {{ s.key }}
+build $public_dir/{{ s.key }}/pn-part-search-list.xml: pn-part-search-list $public_dir/sch.xml
+ supplier = {{ s.key }}
-build ee/{{ s }}/downloaded.xml | ee/{{ s }}/downloaded.rst: {{ s }}-search-parts ee/{{ s }}/pn-part-search-list.xml
-{%- set reports=reports+["$report_dir/" + s + "/downloaded.rst"] %}
+build $public_dir/{{ s.key }}/downloaded.xml | $public_dir/{{ s.key }}/downloaded.rst: {{ s.key }}-search-parts $public_dir/{{ s.key }}/pn-part-search-list.xml
+{%- set reports=reports+["$report_dir/" + s.key + "/downloaded.rst"] %}
{#
-build ee/{{ s }}/parts.xml: part-apply-function ee/{{ s }}/downloaded.xml
- execution = {{ s }}
+build $public_dir/{{ s.key }}/parts.xml: part-apply-function $public_dir/{{ s.key }}/downloaded.xml
+ execution = {{ s.key }}
{%- if cfg and "functions" in cfg and cfg["functions"] %}
functions = --function {{ cfg["functions"] }}
{%- endif %}
@@ -139,17 +140,17 @@ build ee/{{ s }}/parts.xml: part-apply-function ee/{{ s }}/downloaded.xml
arguments = --argument {{ cfg["function-arguments"] }}
{%- endif %}
#}
-build ee/{{ s }}/souffle/facts.dl: part-apply-souffle-pre ee/{{ s }}/downloaded.xml
- work = ee/{{ s }}/souffle
+build $public_dir/{{ s.key }}/souffle/facts.dl: part-apply-souffle-pre $public_dir/{{ s.key }}/downloaded.xml
+ work = $public_dir/{{ s.key }}/souffle
-{%- set main=souffle_ee_src + "/" + s + ".dl" %}
-{%- set alt="ee/custom/" + s + "-souffle.dl" %}
-build ee/{{ s }}/souffle/out/fact.csv: souffle {{ alt if is_file(alt) else main }} | {{ main }} ee/{{ s }}/souffle/facts.dl
- work = ee/{{ s }}/souffle
+{%- set main=souffle_ee_src + "/" + s.key + ".dl" %}
+{%- set alt="$public_dir/custom/" + s.key + "-souffle.dl" %}
+build $public_dir/{{ s.key }}/souffle/out/fact.csv: souffle {{ alt if is_file(alt) else main }} | {{ main }} $public_dir/{{ s.key }}/souffle/facts.dl
+ work = $public_dir/{{ s.key }}/souffle
-build ee/{{ s }}/parts.xml: part-apply-souffle-post ee/{{ s }}/souffle/out/fact.csv
- in_sch = ee/{{ s }}/downloaded.xml
- work = ee/{{ s }}/souffle
+build {{ s.part_db }}: part-apply-souffle-post $public_dir/{{ s.key }}/souffle/out/fact.csv
+ in_sch = $public_dir/{{ s.key }}/downloaded.xml
+ work = $public_dir/{{ s.key }}/souffle
{%- endfor %}
{%- for f in parts_yaml_files %}
@@ -158,21 +159,18 @@ build {{ out }}: import-parts-yaml {{ f }}
# default {{ out }}
{% endfor %}
-build ee/bom.xml | $report_dir/bom.rst: create-bom ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %}
- schematic = ee/sch.xml
- part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %}
+build $public_dir/bom.xml | $report_dir/bom.rst: create-bom $public_dir/sch.xml {%- for s in suppliers %} {{ s.part_db }}{% endfor %}
+ schematic = $public_dir/sch.xml
+ part_dbs = {%- for s in suppliers %} {{ s.part_db }}{% endfor %}
{%- if project.cfg["create-bom"] and project.cfg["create-bom"]["strategy"] %}
strategy = --strategy {{ project.cfg["create-bom"]["strategy"] }}
{%- endif %}
{%- set reports=reports+["$report_dir/bom.rst"] %}
-{#- TODO: complete
-build ee/orders/index.xml: split-parts-by-supplier ee/bom.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %}
- order = ee/bom.xml
- part_dbs ={%- for p in part_dbs %} --part-db {{ p }}.xml{% endfor %}
- out_dir = ee/orders
-
-default ee/orders/index.xml
+{#
+build $public_dir/orders/index.xml: split-parts-by-supplier $public_dir/bom.xml | {%- for s in suppliers %} {{ s.part_db }}{% endfor %}
+ part_dbs ={%- for s in suppliers %} {{ s.part_db }}{% endfor %}
+ suppliers = {% s for s in suppliers %}
#}
rule seeed-download-opl
@@ -181,16 +179,16 @@ rule seeed-download-opl
{%- if project.cfg.has_section("seeed-opl") %}
{%- set opls=project.cfg["seeed-opl"]["opls"].split(",") %}
-build seeed-download-opls: phony{%- for opl in opls %} ee/seeed/opl/{{ opl.strip() }}.xml{% endfor %}
+build seeed-download-opls: phony {%- for opl in opls %} $public_dir/seeed/opl/{{ opl.strip() }}.xml{% endfor %}
{%- for opl in opls %}
{%- set opl=opl.strip() %}
-build ee/seeed/opl/{{ opl }}.xml: seeed-download-opl
+build $public_dir/seeed/opl/{{ opl }}.xml: seeed-download-opl
opl = {{ opl }}
{%- endfor %}
{%- endif %}
# Reports
build ee-reports: phony {{ " ".join(reports) }}
-build part-dbs: phony {%- for p in part_dbs %} {{ p }}.xml{% endfor %}
+build part-dbs: phony {%- for s in suppliers %} {{ s.part_db }}{% endfor %}
build ee-all: phony ee-reports part-dbs