Beispiel #1
0
    def cmd(self, dcmd, cmd, interactive, vols=None):
        if Helper.is_cygwin():
            prefix = "winpty "
        else:
            prefix = ''

        privileged = True
        make_opts = os.getenv("MAKE_OPTS")
        if make_opts:
            env = "MAKE_OPTS=" + make_opts
        else:
            env = None
        fmtdata = {
            "prefix": prefix if interactive else "",
            "dcmd": dcmd,
            "privileged": " --privileged" if privileged else "",
            "interactive": " -it" if interactive else "",
            "rm": " --rm" if dcmd == "run" else "",
            "hostname": " -h dev" if dcmd == "run" else "",
            "name": " --name " + self.name if dcmd == "run" else "",
            "vols": " " + vols if vols else "",
            "img": " " + self.img,
            "cmd": " " + cmd if cmd else "",
            "env": " -e " + env if env and dcmd == "run" else "",
        }

        shell((
            "{prefix}docker {dcmd}" +
            "{privileged}{interactive}{rm}{hostname}{name}{vols}{env}{img}{cmd}"
        ).format(**fmtdata))
Beispiel #2
0
 def create(self):
     # create volume if needed
     try:
         shell("docker volume ls | grep " + self.vol_name + " >/dev/null",
               quiet=True)
     except:
         shell("docker volume create " + self.vol_name)
Beispiel #3
0
    def build(self, force):
        dir = path(DOCKER_DIR, self.name)
        done = path(dir, "done")
        # skip if done
        if not force and os.path.exists(done):
            return

        # docker build
        with cd(DOCKER_DIR):
            shell("docker build -t {} {}".format(self.img, self.name))
            self._build()
            shell("touch " + done)
Beispiel #4
0
    def get_current(self):
        commits = []

        with cd(self.topdir):
            # get submodules
            out = shell("git submodule", save_out=True)
            lines = out.split("\n")
            patt = re.compile("[ -]*([^ ]+) +submodules/([^ ]+) *")
            for l in lines:
                if l.find("lowrisc-llvm") >= 0:
                    continue
                r = re.match(patt, l)
                if r:
                    commit = r.group(1)
                    module = r.group(2)
                    commits.append(Commit(module, commit))

            # add sbt
            commits.append(
                Commit(
                    "riscv-sbt",
                    shell("git rev-parse HEAD",
                          save_out=True).format(self.topdir).strip()))
            return commits
Beispiel #5
0
 def clean_imgs():
     # remove all container instances
     containers = shell("docker ps -a | awk '{print$1}' | sed 1d",
                        save_out=True).split()
     if len(containers) > 0:
         shell("docker rm " + " ".join(containers))
     # remove all '<none>' and 'sbt' images
     images = shell(
         "docker images | grep -e sbt -e '<none>' | awk '{print$3}'",
         save_out=True).split()
     if len(images) > 0:
         shell("docker rmi " + " ".join(images))
Beispiel #6
0
    def get(self):
        if not os.path.exists(self.dstdir):
            mkdir_if_needed(self.parent_dir)
            with cd(self.parent_dir):
                cmd = cat("git clone", self.clone_flags, self.url)
                shell(cmd)
        elif self.update:
            with cd(self.dstdir):
                shell("git fetch")

        with cd(self.dstdir):
            shell(("if [ `git rev-parse HEAD` != {0} ]; then " +
                   "git checkout {0}; fi").format(self.commit.strip()))
Beispiel #7
0
 def cygpath(path):
     if Helper.is_cygwin():
         return shell("cygpath -m " + path, save_out=True).strip()
     else:
         return path
Beispiel #8
0
 def is_cygwin():
     try:
         shell("uname | grep -i cygwin >/dev/null", quiet=True)
         return True
     except:
         return False
Beispiel #9
0
        name = img.replace("sbt-", "")
        docker = Docker(name, img)
        docker.exec("/bin/bash", interactive=True)

    # --save-current-commits
    if args.save_current_commits:
        commits = Commits(TOPDIR, DOCKER_DIR)
        commits.save(commits.get_current())
    # --get-srcs
    elif args.get_srcs:
        srcs = Sources()
        srcs.get()
    # --clean
    elif args.clean:
        with cd(DOCKER_DIR):
            shell("rm -f {}".format(" ".join(
                [name + "/done" for name in names])))
    # --clean-imgs
    elif args.clean_imgs:
        Helper.clean_imgs()
    # --build
    elif args.build:
        imgs.build(args.build, args.force)
    # --run
    elif args.run:
        run(args.run)
    # --exec
    elif args.exec:
        exec(args.exec)
    # --rdev
    elif args.rdev:
        run("sbt-dev")