aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/init.py47
-rw-r--r--src/ee/tools/ninja.py41
-rw-r--r--src/ee/tools/templates/build.ninja.j26
3 files changed, 73 insertions, 21 deletions
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py
index a3e0472..81bdda3 100644
--- a/src/ee/tools/init.py
+++ b/src/ee/tools/init.py
@@ -1,10 +1,53 @@
import argparse
from pathlib import Path
+from typing import List
+
+from ee.project import Project
+import configparser
+
+
+def init_kicad_project(basedir: Path, cfg):
+ print("basedir={}".format(basedir))
+ pro_files: List[Path] = [f for f in basedir.iterdir() if f.name.endswith(".pro")]
+
+ if len(pro_files) == 0:
+ return
+
+ if len(pro_files) == 1:
+ pro_file = pro_files[0]
+ sch_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".sch")
+ pcb_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".kicad_pcb")
+
+ cfg.add_section("kicad-project")
+
+ if sch_file.is_file():
+ print("Found KiCAD project and schematic")
+ cfg["kicad-project"]["sch"] = str(sch_file)
+
+ if pcb_file.is_file():
+ cfg["kicad-project"]["pcb"] = str(pcb_file)
+ else:
+ print("Found more than one kicad project file.")
+
+
+def init(project_dir: Path, basedir: Path):
+ cfg = configparser.ConfigParser()
+ project = Project(project_dir, cfg)
+
+ init_kicad_project(basedir, cfg)
+
+ print("Saving project. Now run 'ee ninja' to generate Ninja build file")
+ project.save()
-from ee.project import init
parser = argparse.ArgumentParser()
+parser.add_argument("--basedir",
+ metavar="DIR")
+
args = parser.parse_args()
-init(Path("."))
+if not args.basedir:
+ args.basedir = "."
+
+init(Path("."), Path(args.basedir))
diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py
index f04b174..a5bbe5b 100644
--- a/src/ee/tools/ninja.py
+++ b/src/ee/tools/ninja.py
@@ -40,7 +40,7 @@ def noext_filter(s: Union[str, Path]) -> str:
return os.path.splitext(os.path.basename(str(s)))[0]
-def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]):
+def generate(project: Project, kicad_bom_strategy: Optional[str]):
def _create_env():
e = Environment(
loader=PackageLoader(__name__, "templates"),
@@ -53,22 +53,31 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
e.filters["noext"] = noext_filter
return e
- gerber_zip = "prod/gerber.zip"
-
- sch = read_schematics(str(sch_path))
-
- sch_files = sorted([s.path for s in sch.schematics])
-
part_dbs = []
params = {
"ee": "{} -m ee".format(os.path.relpath(sys.executable, Path("."))),
"project": project,
- "sch": sch_path,
- "sch_files": sch_files, "kicad_bom_strategy": kicad_bom_strategy,
- "pcb": str(sch_path).replace(".sch", ".kicad_pcb"),
"part_dbs": part_dbs,
}
+ gerber_zip = None
+
+ if project.cfg.has_section("kicad-project"):
+ kp = project.cfg["kicad-project"]
+ if "sch" in kp:
+ sch_path = Path(project.cfg["kicad-project"]["sch"])
+ sch = read_schematics(str(sch_path))
+
+ sch_files = sorted([s.path for s in sch.schematics])
+
+ params["sch"] = sch_path
+ params["sch_files"] = sch_files
+ params["kicad_bom_strategy"] = kicad_bom_strategy
+
+ if "pcb" in kp:
+ params["pcb"] = Path(project.cfg["kicad-project"]["pcb"])
+ gerber_zip = "prod/gerber.zip"
+
# TODO: read from config
distributors = ["digikey"]
params["distributors"] = distributors
@@ -77,10 +86,9 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
params["gerber_zip"] = gerber_zip
# ee_dir = sch_path.parent / "ee"
- ee_dir = Path(".")
- build_ninja = ee_dir / "build.ninja"
+ build_ninja = project.project_dir / "build.ninja"
- parts_yaml_files = [path for path in ee_dir.iterdir() if str(path).endswith("-parts.yaml")]
+ 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
@@ -95,15 +103,10 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
parser = argparse.ArgumentParser()
-parser.add_argument("--sch",
- required=True,
- metavar="FILE")
-
parser.add_argument("--kicad-bom-strategy",
required=False,
metavar="PY CALLABLE")
args = parser.parse_args()
-project = Project.load()
-generate(project, Path(args.sch), args.kicad_bom_strategy)
+generate(Project.load(), args.kicad_bom_strategy)
diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2
index 514e177..080ac65 100644
--- a/src/ee/tools/templates/build.ninja.j2
+++ b/src/ee/tools/templates/build.ninja.j2
@@ -1,8 +1,12 @@
ee = {{ ee }}
report_dir = {{ project.report_dir }}
+{%- if sch is defined %}
sch = {{ sch | ninja_path }}
sch_files = {{ sch_files | ninja_path }}
+{%- endif %}
+{%- if pcb is defined %}
pcb = {{ pcb | ninja_path }}
+{%- endif %}
rule kicad-gerber
description = kicad-gerber
@@ -51,8 +55,10 @@ build {{ gerber_zip }}: kicad-gerber $pcb
gerber_dir = {{ gerber_zip | parent_dir }}
{%- endif %}
+{% if sch is defined -%}
build ee/sch.xml: kicad-make-bom $sch
strategy ={{ " --strategy " + kicad_bom_strategy if kicad_bom_strategy else "" }}
+{% endif -%}
{% for d in distributors %}
# Distributor {{ d }}
build ee/{{ d }}/search-list.xml: part-create-distributor-search-list ee/sch.xml