Skip to content

Commit 1e84feb

Browse files
committed
Implement packaging of code samples
This patch: * Adjusts code samples to use a different Clang bin path: as if installed from a binary package rather than as if built from source * Implements copying of code samples to the generated binary packages
1 parent 6a0d984 commit 1e84feb

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

samples/Makefile.conf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@
1616
#
1717

1818
ifndef BIN_PATH
19-
ifndef VERSION
20-
VERSION=0.1
19+
BIN_PATH=../../../bin
2120
endif
22-
BIN_PATH=../../../install-${VERSION}/LLVMEmbeddedToolchainForArm-${VERSION}/bin
23-
endif

samples/README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,14 @@ Debugging is only supported on Linux.
5050
## Specifying the location of the installed toolchain
5151

5252
The Makefiles of the code samples need the location of the installed LLVM
53-
Embedded Toolchain for Arm. There are several ways to specify the location,
54-
depending on the environment. The following option works in all environments:
55-
* Set the environment variable ``BIN_PATH`` to point to the ``bin`` directory
56-
of the toolchain.
57-
58-
The following two options work on Linux and MSYS2:
59-
* Set the environment variable ``VERSION`` to the revision of the built
60-
toolchain (e.g. ``13.0.0`` or ``HEAD``). The sample Makefiles will assume that
61-
the toolchain is installed in the default directory used by the
62-
``build.py`` script (i.e.
63-
``install-<revision>/LLVMEmbeddedToolchainForArm-<revision>``
64-
in the root of the ``LLVM-embedded-toolchain-for-Arm`` repository
65-
checkout), or
66-
* Don't set any of the above variables. This will have the same effect as
67-
setting ``VERSION=0.1``.
53+
Embedded Toolchain for Arm.
54+
55+
If you are using Linux or MSYS2 and running the samples directly from the
56+
installation directory the Makefiles will determine the correct location
57+
automatically.
58+
59+
Otherwise you will need to set the environment variable ``BIN_PATH`` to point
60+
to the ``bin`` directory of the toolchain.
6861

6962
## Compiling, running and debugging the samples
7063

@@ -88,12 +81,6 @@ use the following commands to build, run or debug the sample:
8881
```
8982
* ``$ make clean`` to delete the generated ``.elf`` and ``.hex`` files
9083

91-
Note: you can set an environment variable for a command using the following
92-
syntax:
93-
```
94-
$ VERSION=HEAD make run
95-
```
96-
9784
### Windows
9885

9986
If you plan to run the compiled samples, ensure that the path of the directory

scripts/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def main() -> int:
356356

357357
def do_package():
358358
package.write_version_file(cfg, version)
359+
package.copy_samples(cfg)
359360
package.package_toolchain(cfg)
360361
run_or_skip(cfg, Action.PACKAGE, do_package, 'packaging')
361362
except util.ToolchainBuildError:

scripts/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def _fill_inferred(self):
346346
self.newlib_repo_dir = join(self.repos_dir, 'newlib.git')
347347
is_using_mingw = self.host_toolchain.kind == ToolchainKind.MINGW
348348
self.is_cross_compiling = (os.name == 'posix' and is_using_mingw)
349+
self.is_windows = is_using_mingw
349350
self.cmake_generator = 'Ninja' if self.use_ninja else 'Unix Makefiles'
350351
self.release_mode = self.revision != 'HEAD'
351352
if self.release_mode:

scripts/package.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import logging
1717
import os
18+
import shutil
1819
from typing import FrozenSet
1920
import tarfile
2021
import zipfile
@@ -39,6 +40,25 @@ def write_version_file(cfg: config.Config, version: repos.LLVMBMTC) -> None:
3940
util.write_lines(lines, dest)
4041

4142

43+
def copy_samples(cfg: config.Config) -> None:
44+
"""Copy code samples, filter out files that are not usable on the target
45+
platform."""
46+
src = os.path.join(cfg.source_dir, 'samples')
47+
dest = os.path.join(cfg.target_llvm_dir, 'samples')
48+
if os.path.exists(dest):
49+
shutil.rmtree(dest)
50+
51+
if cfg.is_windows:
52+
# We don't filter out Makefile and Makefile.conf because we support
53+
# using Windows+MSYS2
54+
ignore = shutil.ignore_patterns('.gitignore')
55+
else:
56+
# make.bat is useless on Linux/Mac
57+
ignore = shutil.ignore_patterns('.gitignore', 'make.bat')
58+
logging.info('Copying "%s" to "%s"', src, dest)
59+
shutil.copytree(src, dest, ignore=ignore)
60+
61+
4262
def _get_excluded_symlinks(cfg: config.Config) -> FrozenSet[str]:
4363
"""Get a list of symlinks that should be excluded when symlinks are
4464
converted to copies (i.e. when targeting Windows or using zip as archive
@@ -51,7 +71,7 @@ def _get_excluded_symlinks(cfg: config.Config) -> FrozenSet[str]:
5171
'lld-link', # Windows (COFF) linker
5272
'wasm-ld', # WebAssembly linker
5373
]
54-
if cfg.is_cross_compiling:
74+
if cfg.is_windows:
5575
excludes = [name + '.exe' for name in excludes]
5676
return frozenset(excludes)
5777

@@ -64,7 +84,7 @@ def reset_uid(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
6484
return tarinfo
6585
exclude_set: FrozenSet[str] = frozenset()
6686
dereference = False
67-
if cfg.is_cross_compiling:
87+
if cfg.is_windows:
6888
exclude_set = _get_excluded_symlinks(cfg)
6989
dereference = True
7090
with tarfile.open(dest_pkg, 'w:gz') as dest:

0 commit comments

Comments
 (0)